pngunknown.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294
  1. /* pngunknown.c - test the read side unknown chunk handling
  2. *
  3. * Last changed in libpng 1.6.32 [August 24, 2017]
  4. * Copyright (c) 2015,2017 Glenn Randers-Pehrson
  5. * Written by John Cunningham Bowler
  6. *
  7. * This code is released under the libpng license.
  8. * For conditions of distribution and use, see the disclaimer
  9. * and license in png.h
  10. *
  11. * NOTES:
  12. * This is a C program that is intended to be linked against libpng. It
  13. * allows the libpng unknown handling code to be tested by interpreting
  14. * arguments to save or discard combinations of chunks. The program is
  15. * currently just a minimal validation for the built-in libpng facilities.
  16. */
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <setjmp.h>
  21. /* Define the following to use this test against your installed libpng, rather
  22. * than the one being built here:
  23. */
  24. #ifdef PNG_FREESTANDING_TESTS
  25. # include <png.h>
  26. #else
  27. # include "../../png.h"
  28. #endif
  29. /* 1.6.1 added support for the configure test harness, which uses 77 to indicate
  30. * a skipped test, in earlier versions we need to succeed on a skipped test, so:
  31. */
  32. #if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)
  33. # define SKIP 77
  34. #else
  35. # define SKIP 0
  36. #endif
  37. /* Since this program tests the ability to change the unknown chunk handling
  38. * these must be defined:
  39. */
  40. #if defined(PNG_SET_UNKNOWN_CHUNKS_SUPPORTED) &&\
  41. defined(PNG_STDIO_SUPPORTED) &&\
  42. defined(PNG_READ_SUPPORTED)
  43. /* One of these must be defined to allow us to find out what happened. It is
  44. * still useful to set unknown chunk handling without either of these in order
  45. * to cause *known* chunks to be discarded. This can be a significant
  46. * efficiency gain, but it can't really be tested here.
  47. */
  48. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED) ||\
  49. defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
  50. #if PNG_LIBPNG_VER < 10500
  51. /* This deliberately lacks the const. */
  52. typedef png_byte *png_const_bytep;
  53. /* This is copied from 1.5.1 png.h: */
  54. #define PNG_INTERLACE_ADAM7_PASSES 7
  55. #define PNG_PASS_START_ROW(pass) (((1U&~(pass))<<(3-((pass)>>1)))&7)
  56. #define PNG_PASS_START_COL(pass) (((1U& (pass))<<(3-(((pass)+1)>>1)))&7)
  57. #define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3)
  58. #define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3)
  59. #define PNG_PASS_ROWS(height, pass) (((height)+(((1<<PNG_PASS_ROW_SHIFT(pass))\
  60. -1)-PNG_PASS_START_ROW(pass)))>>PNG_PASS_ROW_SHIFT(pass))
  61. #define PNG_PASS_COLS(width, pass) (((width)+(((1<<PNG_PASS_COL_SHIFT(pass))\
  62. -1)-PNG_PASS_START_COL(pass)))>>PNG_PASS_COL_SHIFT(pass))
  63. #define PNG_ROW_FROM_PASS_ROW(yIn, pass) \
  64. (((yIn)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))
  65. #define PNG_COL_FROM_PASS_COL(xIn, pass) \
  66. (((xIn)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))
  67. #define PNG_PASS_MASK(pass,off) ( \
  68. ((0x110145AFU>>(((7-(off))-(pass))<<2)) & 0xFU) | \
  69. ((0x01145AF0U>>(((7-(off))-(pass))<<2)) & 0xF0U))
  70. #define PNG_ROW_IN_INTERLACE_PASS(y, pass) \
  71. ((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1)
  72. #define PNG_COL_IN_INTERLACE_PASS(x, pass) \
  73. ((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1)
  74. /* These are needed too for the default build: */
  75. #define PNG_WRITE_16BIT_SUPPORTED
  76. #define PNG_READ_16BIT_SUPPORTED
  77. /* This comes from pnglibconf.h after 1.5: */
  78. #define PNG_FP_1 100000
  79. #define PNG_GAMMA_THRESHOLD_FIXED\
  80. ((png_fixed_point)(PNG_GAMMA_THRESHOLD * PNG_FP_1))
  81. #endif
  82. #if PNG_LIBPNG_VER < 10600
  83. /* 1.6.0 constifies many APIs. The following exists to allow pngvalid to be
  84. * compiled against earlier versions.
  85. */
  86. # define png_const_structp png_structp
  87. #endif
  88. #if PNG_LIBPNG_VER < 10700
  89. /* Copied from libpng 1.7.0 png.h */
  90. #define PNG_u2(b1, b2) (((unsigned int)(b1) << 8) + (b2))
  91. #define PNG_U16(b1, b2) ((png_uint_16)PNG_u2(b1, b2))
  92. #define PNG_U32(b1, b2, b3, b4)\
  93. (((png_uint_32)PNG_u2(b1, b2) << 16) + PNG_u2(b3, b4))
  94. /* Constants for known chunk types.
  95. */
  96. #define png_IDAT PNG_U32( 73, 68, 65, 84)
  97. #define png_IEND PNG_U32( 73, 69, 78, 68)
  98. #define png_IHDR PNG_U32( 73, 72, 68, 82)
  99. #define png_PLTE PNG_U32( 80, 76, 84, 69)
  100. #define png_bKGD PNG_U32( 98, 75, 71, 68)
  101. #define png_cHRM PNG_U32( 99, 72, 82, 77)
  102. #define png_eXIf PNG_U32(101, 88, 73, 102) /* registered July 2017 */
  103. #define png_fRAc PNG_U32(102, 82, 65, 99) /* registered, not defined */
  104. #define png_gAMA PNG_U32(103, 65, 77, 65)
  105. #define png_gIFg PNG_U32(103, 73, 70, 103)
  106. #define png_gIFt PNG_U32(103, 73, 70, 116) /* deprecated */
  107. #define png_gIFx PNG_U32(103, 73, 70, 120)
  108. #define png_hIST PNG_U32(104, 73, 83, 84)
  109. #define png_iCCP PNG_U32(105, 67, 67, 80)
  110. #define png_iTXt PNG_U32(105, 84, 88, 116)
  111. #define png_oFFs PNG_U32(111, 70, 70, 115)
  112. #define png_pCAL PNG_U32(112, 67, 65, 76)
  113. #define png_pHYs PNG_U32(112, 72, 89, 115)
  114. #define png_sBIT PNG_U32(115, 66, 73, 84)
  115. #define png_sCAL PNG_U32(115, 67, 65, 76)
  116. #define png_sPLT PNG_U32(115, 80, 76, 84)
  117. #define png_sRGB PNG_U32(115, 82, 71, 66)
  118. #define png_sTER PNG_U32(115, 84, 69, 82)
  119. #define png_tEXt PNG_U32(116, 69, 88, 116)
  120. #define png_tIME PNG_U32(116, 73, 77, 69)
  121. #define png_tRNS PNG_U32(116, 82, 78, 83)
  122. #define png_zTXt PNG_U32(122, 84, 88, 116)
  123. /* Test on flag values as defined in the spec (section 5.4): */
  124. #define PNG_CHUNK_ANCILLARY(c) (1 & ((c) >> 29))
  125. #define PNG_CHUNK_CRITICAL(c) (!PNG_CHUNK_ANCILLARY(c))
  126. #define PNG_CHUNK_PRIVATE(c) (1 & ((c) >> 21))
  127. #define PNG_CHUNK_RESERVED(c) (1 & ((c) >> 13))
  128. #define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >> 5))
  129. #endif /* PNG_LIBPNG_VER < 10700 */
  130. #ifdef __cplusplus
  131. # define this not_the_cpp_this
  132. # define new not_the_cpp_new
  133. # define voidcast(type, value) static_cast<type>(value)
  134. #else
  135. # define voidcast(type, value) (value)
  136. #endif /* __cplusplus */
  137. /* Unused formal parameter errors are removed using the following macro which is
  138. * expected to have no bad effects on performance.
  139. */
  140. #ifndef UNUSED
  141. # if defined(__GNUC__) || defined(_MSC_VER)
  142. # define UNUSED(param) (void)param;
  143. # else
  144. # define UNUSED(param)
  145. # endif
  146. #endif
  147. /* Types of chunks not known to libpng */
  148. #define png_vpAg PNG_U32(118, 112, 65, 103)
  149. /* Chunk information */
  150. #define PNG_INFO_tEXt 0x10000000U
  151. #define PNG_INFO_iTXt 0x20000000U
  152. #define PNG_INFO_zTXt 0x40000000U
  153. #define PNG_INFO_sTER 0x01000000U
  154. #define PNG_INFO_vpAg 0x02000000U
  155. #define ABSENT 0
  156. #define START 1
  157. #define END 2
  158. static struct
  159. {
  160. char name[5];
  161. png_uint_32 flag;
  162. png_uint_32 tag;
  163. int unknown; /* Chunk not known to libpng */
  164. int all; /* Chunk set by the '-1' option */
  165. int position; /* position in pngtest.png */
  166. int keep; /* unknown handling setting */
  167. } chunk_info[] = {
  168. /* Critical chunks */
  169. { "IDAT", PNG_INFO_IDAT, png_IDAT, 0, 0, START, 0 }, /* must be [0] */
  170. { "PLTE", PNG_INFO_PLTE, png_PLTE, 0, 0, ABSENT, 0 },
  171. /* Non-critical chunks that libpng handles */
  172. /* This is a mess but it seems to be the only way to do it - there is no way
  173. * to check for a definition outside a #if.
  174. */
  175. { "bKGD", PNG_INFO_bKGD, png_bKGD,
  176. # ifdef PNG_READ_bKGD_SUPPORTED
  177. 0,
  178. # else
  179. 1,
  180. # endif
  181. 1, START, 0 },
  182. { "cHRM", PNG_INFO_cHRM, png_cHRM,
  183. # ifdef PNG_READ_cHRM_SUPPORTED
  184. 0,
  185. # else
  186. 1,
  187. # endif
  188. 1, START, 0 },
  189. { "eXIf", PNG_INFO_eXIf, png_eXIf,
  190. # ifdef PNG_READ_eXIf_SUPPORTED
  191. 0,
  192. # else
  193. 1,
  194. # endif
  195. 1, END, 0 },
  196. { "gAMA", PNG_INFO_gAMA, png_gAMA,
  197. # ifdef PNG_READ_gAMA_SUPPORTED
  198. 0,
  199. # else
  200. 1,
  201. # endif
  202. 1, START, 0 },
  203. { "hIST", PNG_INFO_hIST, png_hIST,
  204. # ifdef PNG_READ_hIST_SUPPORTED
  205. 0,
  206. # else
  207. 1,
  208. # endif
  209. 1, ABSENT, 0 },
  210. { "iCCP", PNG_INFO_iCCP, png_iCCP,
  211. # ifdef PNG_READ_iCCP_SUPPORTED
  212. 0,
  213. # else
  214. 1,
  215. # endif
  216. 1, ABSENT, 0 },
  217. { "iTXt", PNG_INFO_iTXt, png_iTXt,
  218. # ifdef PNG_READ_iTXt_SUPPORTED
  219. 0,
  220. # else
  221. 1,
  222. # endif
  223. 1, ABSENT, 0 },
  224. { "oFFs", PNG_INFO_oFFs, png_oFFs,
  225. # ifdef PNG_READ_oFFs_SUPPORTED
  226. 0,
  227. # else
  228. 1,
  229. # endif
  230. 1, START, 0 },
  231. { "pCAL", PNG_INFO_pCAL, png_pCAL,
  232. # ifdef PNG_READ_pCAL_SUPPORTED
  233. 0,
  234. # else
  235. 1,
  236. # endif
  237. 1, START, 0 },
  238. { "pHYs", PNG_INFO_pHYs, png_pHYs,
  239. # ifdef PNG_READ_pHYs_SUPPORTED
  240. 0,
  241. # else
  242. 1,
  243. # endif
  244. 1, START, 0 },
  245. { "sBIT", PNG_INFO_sBIT, png_sBIT,
  246. # ifdef PNG_READ_sBIT_SUPPORTED
  247. 0,
  248. # else
  249. 1,
  250. # endif
  251. 1, START, 0 },
  252. { "sCAL", PNG_INFO_sCAL, png_sCAL,
  253. # ifdef PNG_READ_sCAL_SUPPORTED
  254. 0,
  255. # else
  256. 1,
  257. # endif
  258. 1, START, 0 },
  259. { "sPLT", PNG_INFO_sPLT, png_sPLT,
  260. # ifdef PNG_READ_sPLT_SUPPORTED
  261. 0,
  262. # else
  263. 1,
  264. # endif
  265. 1, ABSENT, 0 },
  266. { "sRGB", PNG_INFO_sRGB, png_sRGB,
  267. # ifdef PNG_READ_sRGB_SUPPORTED
  268. 0,
  269. # else
  270. 1,
  271. # endif
  272. 1, START, 0 },
  273. { "tEXt", PNG_INFO_tEXt, png_tEXt,
  274. # ifdef PNG_READ_tEXt_SUPPORTED
  275. 0,
  276. # else
  277. 1,
  278. # endif
  279. 1, START, 0 },
  280. { "tIME", PNG_INFO_tIME, png_tIME,
  281. # ifdef PNG_READ_tIME_SUPPORTED
  282. 0,
  283. # else
  284. 1,
  285. # endif
  286. 1, START, 0 },
  287. { "tRNS", PNG_INFO_tRNS, png_tRNS,
  288. # ifdef PNG_READ_tRNS_SUPPORTED
  289. 0,
  290. # else
  291. 1,
  292. # endif
  293. 0, ABSENT, 0 },
  294. { "zTXt", PNG_INFO_zTXt, png_zTXt,
  295. # ifdef PNG_READ_zTXt_SUPPORTED
  296. 0,
  297. # else
  298. 1,
  299. # endif
  300. 1, END, 0 },
  301. /* No libpng handling */
  302. { "sTER", PNG_INFO_sTER, png_sTER, 1, 1, START, 0 },
  303. { "vpAg", PNG_INFO_vpAg, png_vpAg, 1, 0, START, 0 },
  304. };
  305. #define NINFO ((int)((sizeof chunk_info)/(sizeof chunk_info[0])))
  306. static void
  307. clear_keep(void)
  308. {
  309. int i = NINFO;
  310. while (--i >= 0)
  311. chunk_info[i].keep = 0;
  312. }
  313. static int
  314. find(const char *name)
  315. {
  316. int i = NINFO;
  317. while (--i >= 0)
  318. {
  319. if (memcmp(chunk_info[i].name, name, 4) == 0)
  320. break;
  321. }
  322. return i;
  323. }
  324. static int
  325. findb(const png_byte *name)
  326. {
  327. int i = NINFO;
  328. while (--i >= 0)
  329. {
  330. if (memcmp(chunk_info[i].name, name, 4) == 0)
  331. break;
  332. }
  333. return i;
  334. }
  335. static int
  336. find_by_flag(png_uint_32 flag)
  337. {
  338. int i = NINFO;
  339. while (--i >= 0) if (chunk_info[i].flag == flag) return i;
  340. fprintf(stderr, "pngunknown: internal error\n");
  341. exit(4);
  342. }
  343. static int
  344. ancillary(const char *name)
  345. {
  346. return PNG_CHUNK_ANCILLARY(PNG_U32(name[0], name[1], name[2], name[3]));
  347. }
  348. #ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
  349. static int
  350. ancillaryb(const png_byte *name)
  351. {
  352. return PNG_CHUNK_ANCILLARY(PNG_U32(name[0], name[1], name[2], name[3]));
  353. }
  354. #endif
  355. /* Type of an error_ptr */
  356. typedef struct
  357. {
  358. jmp_buf error_return;
  359. png_structp png_ptr;
  360. png_infop info_ptr, end_ptr;
  361. png_uint_32 before_IDAT;
  362. png_uint_32 after_IDAT;
  363. int error_count;
  364. int warning_count;
  365. int keep; /* the default value */
  366. const char *program;
  367. const char *file;
  368. const char *test;
  369. } display;
  370. static const char init[] = "initialization";
  371. static const char cmd[] = "command line";
  372. static void
  373. init_display(display *d, const char *program)
  374. {
  375. memset(d, 0, sizeof *d);
  376. d->png_ptr = NULL;
  377. d->info_ptr = d->end_ptr = NULL;
  378. d->error_count = d->warning_count = 0;
  379. d->program = program;
  380. d->file = program;
  381. d->test = init;
  382. }
  383. static void
  384. clean_display(display *d)
  385. {
  386. png_destroy_read_struct(&d->png_ptr, &d->info_ptr, &d->end_ptr);
  387. /* This must not happen - it might cause an app crash */
  388. if (d->png_ptr != NULL || d->info_ptr != NULL || d->end_ptr != NULL)
  389. {
  390. fprintf(stderr, "%s(%s): png_destroy_read_struct error\n", d->file,
  391. d->test);
  392. exit(1);
  393. }
  394. }
  395. PNG_FUNCTION(void, display_exit, (display *d), static PNG_NORETURN)
  396. {
  397. ++(d->error_count);
  398. if (d->png_ptr != NULL)
  399. clean_display(d);
  400. /* During initialization and if this is a single command line argument set
  401. * exit now - there is only one test, otherwise longjmp to do the next test.
  402. */
  403. if (d->test == init || d->test == cmd)
  404. exit(1);
  405. longjmp(d->error_return, 1);
  406. }
  407. static int
  408. display_rc(const display *d, int strict)
  409. {
  410. return d->error_count + (strict ? d->warning_count : 0);
  411. }
  412. /* libpng error and warning callbacks */
  413. PNG_FUNCTION(void, (PNGCBAPI error), (png_structp png_ptr, const char *message),
  414. static PNG_NORETURN)
  415. {
  416. display *d = (display*)png_get_error_ptr(png_ptr);
  417. fprintf(stderr, "%s(%s): libpng error: %s\n", d->file, d->test, message);
  418. display_exit(d);
  419. }
  420. static void PNGCBAPI
  421. warning(png_structp png_ptr, const char *message)
  422. {
  423. display *d = (display*)png_get_error_ptr(png_ptr);
  424. fprintf(stderr, "%s(%s): libpng warning: %s\n", d->file, d->test, message);
  425. ++(d->warning_count);
  426. }
  427. static png_uint_32
  428. get_valid(display *d, png_infop info_ptr)
  429. {
  430. png_uint_32 flags = png_get_valid(d->png_ptr, info_ptr, (png_uint_32)~0);
  431. /* Map the text chunks back into the flags */
  432. {
  433. png_textp text;
  434. png_uint_32 ntext = png_get_text(d->png_ptr, info_ptr, &text, NULL);
  435. while (ntext > 0) switch (text[--ntext].compression)
  436. {
  437. case -1:
  438. flags |= PNG_INFO_tEXt;
  439. break;
  440. case 0:
  441. flags |= PNG_INFO_zTXt;
  442. break;
  443. case 1:
  444. case 2:
  445. flags |= PNG_INFO_iTXt;
  446. break;
  447. default:
  448. fprintf(stderr, "%s(%s): unknown text compression %d\n", d->file,
  449. d->test, text[ntext].compression);
  450. display_exit(d);
  451. }
  452. }
  453. return flags;
  454. }
  455. #ifdef PNG_READ_USER_CHUNKS_SUPPORTED
  456. static int PNGCBAPI
  457. read_callback(png_structp pp, png_unknown_chunkp pc)
  458. {
  459. /* This function mimics the behavior of png_set_keep_unknown_chunks by
  460. * returning '0' to keep the chunk and '1' to discard it.
  461. */
  462. display *d = voidcast(display*, png_get_user_chunk_ptr(pp));
  463. int chunk = findb(pc->name);
  464. int keep, discard;
  465. if (chunk < 0) /* not one in our list, so not a known chunk */
  466. keep = d->keep;
  467. else
  468. {
  469. keep = chunk_info[chunk].keep;
  470. if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)
  471. {
  472. /* See the comments in png.h - use the default for unknown chunks,
  473. * do not keep known chunks.
  474. */
  475. if (chunk_info[chunk].unknown)
  476. keep = d->keep;
  477. else
  478. keep = PNG_HANDLE_CHUNK_NEVER;
  479. }
  480. }
  481. switch (keep)
  482. {
  483. default:
  484. fprintf(stderr, "%s(%s): %d: unrecognized chunk option\n", d->file,
  485. d->test, chunk_info[chunk].keep);
  486. display_exit(d);
  487. case PNG_HANDLE_CHUNK_AS_DEFAULT:
  488. case PNG_HANDLE_CHUNK_NEVER:
  489. discard = 1/*handled; discard*/;
  490. break;
  491. case PNG_HANDLE_CHUNK_IF_SAFE:
  492. case PNG_HANDLE_CHUNK_ALWAYS:
  493. discard = 0/*not handled; keep*/;
  494. break;
  495. }
  496. /* Also store information about this chunk in the display, the relevant flag
  497. * is set if the chunk is to be kept ('not handled'.)
  498. */
  499. if (chunk >= 0) if (!discard) /* stupidity to stop a GCC warning */
  500. {
  501. png_uint_32 flag = chunk_info[chunk].flag;
  502. if (pc->location & PNG_AFTER_IDAT)
  503. d->after_IDAT |= flag;
  504. else
  505. d->before_IDAT |= flag;
  506. }
  507. /* However if there is no support to store unknown chunks don't ask libpng to
  508. * do it; there will be an png_error.
  509. */
  510. # ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
  511. return discard;
  512. # else
  513. return 1; /*handled; discard*/
  514. # endif
  515. }
  516. #endif /* READ_USER_CHUNKS_SUPPORTED */
  517. #ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
  518. static png_uint_32
  519. get_unknown(display *d, png_infop info_ptr, int after_IDAT)
  520. {
  521. /* Create corresponding 'unknown' flags */
  522. png_uint_32 flags = 0;
  523. UNUSED(after_IDAT)
  524. {
  525. png_unknown_chunkp unknown;
  526. int num_unknown = png_get_unknown_chunks(d->png_ptr, info_ptr, &unknown);
  527. while (--num_unknown >= 0)
  528. {
  529. int chunk = findb(unknown[num_unknown].name);
  530. /* Chunks not known to pngunknown must be validated here; since they
  531. * must also be unknown to libpng the 'display->keep' behavior should
  532. * have been used.
  533. */
  534. if (chunk < 0) switch (d->keep)
  535. {
  536. default: /* impossible */
  537. case PNG_HANDLE_CHUNK_AS_DEFAULT:
  538. case PNG_HANDLE_CHUNK_NEVER:
  539. fprintf(stderr, "%s(%s): %s: %s: unknown chunk saved\n",
  540. d->file, d->test, d->keep ? "discard" : "default",
  541. unknown[num_unknown].name);
  542. ++(d->error_count);
  543. break;
  544. case PNG_HANDLE_CHUNK_IF_SAFE:
  545. if (!ancillaryb(unknown[num_unknown].name))
  546. {
  547. fprintf(stderr,
  548. "%s(%s): if-safe: %s: unknown critical chunk saved\n",
  549. d->file, d->test, unknown[num_unknown].name);
  550. ++(d->error_count);
  551. break;
  552. }
  553. /* FALLTHROUGH */ /* (safe) */
  554. case PNG_HANDLE_CHUNK_ALWAYS:
  555. break;
  556. }
  557. else
  558. flags |= chunk_info[chunk].flag;
  559. }
  560. }
  561. return flags;
  562. }
  563. #else /* SAVE_UNKNOWN_CHUNKS */
  564. static png_uint_32
  565. get_unknown(display *d, png_infop info_ptr, int after_IDAT)
  566. /* Otherwise this will return the cached values set by any user callback */
  567. {
  568. UNUSED(info_ptr);
  569. if (after_IDAT)
  570. return d->after_IDAT;
  571. else
  572. return d->before_IDAT;
  573. }
  574. # ifndef PNG_READ_USER_CHUNKS_SUPPORTED
  575. /* The #defines above should mean this is never reached, it's just here as
  576. * a check to ensure the logic is correct.
  577. */
  578. # error No store support and no user chunk support, this will not work
  579. # endif /* READ_USER_CHUNKS */
  580. #endif /* SAVE_UNKNOWN_CHUNKS */
  581. static int
  582. check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
  583. display *d, int set_callback)
  584. {
  585. int i, npasses, ipass;
  586. png_uint_32 height;
  587. d->keep = PNG_HANDLE_CHUNK_AS_DEFAULT;
  588. d->before_IDAT = 0;
  589. d->after_IDAT = 0;
  590. /* Some of these errors are permanently fatal and cause an exit here, others
  591. * are per-test and cause an error return.
  592. */
  593. d->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, d, error,
  594. warning);
  595. if (d->png_ptr == NULL)
  596. {
  597. fprintf(stderr, "%s(%s): could not allocate png struct\n", d->file,
  598. d->test);
  599. /* Terminate here, this error is not test specific. */
  600. exit(1);
  601. }
  602. d->info_ptr = png_create_info_struct(d->png_ptr);
  603. d->end_ptr = png_create_info_struct(d->png_ptr);
  604. if (d->info_ptr == NULL || d->end_ptr == NULL)
  605. {
  606. fprintf(stderr, "%s(%s): could not allocate png info\n", d->file,
  607. d->test);
  608. clean_display(d);
  609. exit(1);
  610. }
  611. png_init_io(d->png_ptr, fp);
  612. # ifdef PNG_READ_USER_CHUNKS_SUPPORTED
  613. /* This is only done if requested by the caller; it interferes with the
  614. * standard store/save mechanism.
  615. */
  616. if (set_callback)
  617. png_set_read_user_chunk_fn(d->png_ptr, d, read_callback);
  618. # else
  619. UNUSED(set_callback)
  620. # endif
  621. /* Handle each argument in turn; multiple settings are possible for the same
  622. * chunk and multiple calls will occur (the last one should override all
  623. * preceding ones).
  624. */
  625. for (i=0; i<argc; ++i)
  626. {
  627. const char *equals = strchr(argv[i], '=');
  628. if (equals != NULL)
  629. {
  630. int chunk, option;
  631. if (strcmp(equals+1, "default") == 0)
  632. option = PNG_HANDLE_CHUNK_AS_DEFAULT;
  633. else if (strcmp(equals+1, "discard") == 0)
  634. option = PNG_HANDLE_CHUNK_NEVER;
  635. else if (strcmp(equals+1, "if-safe") == 0)
  636. option = PNG_HANDLE_CHUNK_IF_SAFE;
  637. else if (strcmp(equals+1, "save") == 0)
  638. option = PNG_HANDLE_CHUNK_ALWAYS;
  639. else
  640. {
  641. fprintf(stderr, "%s(%s): %s: unrecognized chunk option\n", d->file,
  642. d->test, argv[i]);
  643. display_exit(d);
  644. }
  645. switch (equals - argv[i])
  646. {
  647. case 4: /* chunk name */
  648. chunk = find(argv[i]);
  649. if (chunk >= 0)
  650. {
  651. /* These #if tests have the effect of skipping the arguments
  652. * if SAVE support is unavailable - we can't do a useful test
  653. * in this case, so we just check the arguments! This could
  654. * be improved in the future by using the read callback.
  655. */
  656. # if PNG_LIBPNG_VER >= 10700 &&\
  657. !defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
  658. if (option < PNG_HANDLE_CHUNK_IF_SAFE)
  659. # endif /* 1.7+ SAVE_UNKNOWN_CHUNKS */
  660. {
  661. png_byte name[5];
  662. memcpy(name, chunk_info[chunk].name, 5);
  663. png_set_keep_unknown_chunks(d->png_ptr, option, name, 1);
  664. chunk_info[chunk].keep = option;
  665. }
  666. continue;
  667. }
  668. break;
  669. case 7: /* default */
  670. if (memcmp(argv[i], "default", 7) == 0)
  671. {
  672. # if PNG_LIBPNG_VER >= 10700 &&\
  673. !defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
  674. if (option < PNG_HANDLE_CHUNK_IF_SAFE)
  675. # endif /* 1.7+ SAVE_UNKNOWN_CHUNKS */
  676. png_set_keep_unknown_chunks(d->png_ptr, option, NULL, 0);
  677. d->keep = option;
  678. continue;
  679. }
  680. break;
  681. case 3: /* all */
  682. if (memcmp(argv[i], "all", 3) == 0)
  683. {
  684. # if PNG_LIBPNG_VER >= 10700 &&\
  685. !defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
  686. if (option < PNG_HANDLE_CHUNK_IF_SAFE)
  687. # endif /* 1.7+ SAVE_UNKNOWN_CHUNKS */
  688. png_set_keep_unknown_chunks(d->png_ptr, option, NULL, -1);
  689. d->keep = option;
  690. for (chunk = 0; chunk < NINFO; ++chunk)
  691. if (chunk_info[chunk].all)
  692. chunk_info[chunk].keep = option;
  693. continue;
  694. }
  695. break;
  696. default: /* some misplaced = */
  697. break;
  698. }
  699. }
  700. fprintf(stderr, "%s(%s): %s: unrecognized chunk argument\n", d->file,
  701. d->test, argv[i]);
  702. display_exit(d);
  703. }
  704. png_read_info(d->png_ptr, d->info_ptr);
  705. switch (png_get_interlace_type(d->png_ptr, d->info_ptr))
  706. {
  707. case PNG_INTERLACE_NONE:
  708. npasses = 1;
  709. break;
  710. case PNG_INTERLACE_ADAM7:
  711. npasses = PNG_INTERLACE_ADAM7_PASSES;
  712. break;
  713. default:
  714. /* Hard error because it is not test specific */
  715. fprintf(stderr, "%s(%s): invalid interlace type\n", d->file, d->test);
  716. clean_display(d);
  717. exit(1);
  718. }
  719. /* Skip the image data, if IDAT is not being handled then don't do this
  720. * because it will cause a CRC error.
  721. */
  722. if (chunk_info[0/*IDAT*/].keep == PNG_HANDLE_CHUNK_AS_DEFAULT)
  723. {
  724. png_start_read_image(d->png_ptr);
  725. height = png_get_image_height(d->png_ptr, d->info_ptr);
  726. if (npasses > 1)
  727. {
  728. png_uint_32 width = png_get_image_width(d->png_ptr, d->info_ptr);
  729. for (ipass=0; ipass<npasses; ++ipass)
  730. {
  731. png_uint_32 wPass = PNG_PASS_COLS(width, ipass);
  732. if (wPass > 0)
  733. {
  734. png_uint_32 y;
  735. for (y=0; y<height; ++y) if (PNG_ROW_IN_INTERLACE_PASS(y, ipass))
  736. png_read_row(d->png_ptr, NULL, NULL);
  737. }
  738. }
  739. } /* interlaced */
  740. else /* not interlaced */
  741. {
  742. png_uint_32 y;
  743. for (y=0; y<height; ++y)
  744. png_read_row(d->png_ptr, NULL, NULL);
  745. }
  746. }
  747. png_read_end(d->png_ptr, d->end_ptr);
  748. flags[0] = get_valid(d, d->info_ptr);
  749. flags[1] = get_unknown(d, d->info_ptr, 0/*before IDAT*/);
  750. /* Only png_read_png sets PNG_INFO_IDAT! */
  751. flags[chunk_info[0/*IDAT*/].keep != PNG_HANDLE_CHUNK_AS_DEFAULT] |=
  752. PNG_INFO_IDAT;
  753. flags[2] = get_valid(d, d->end_ptr);
  754. flags[3] = get_unknown(d, d->end_ptr, 1/*after IDAT*/);
  755. clean_display(d);
  756. return d->keep;
  757. }
  758. static void
  759. check_error(display *d, png_uint_32 flags, const char *message)
  760. {
  761. while (flags)
  762. {
  763. png_uint_32 flag = flags & -(png_int_32)flags;
  764. int i = find_by_flag(flag);
  765. fprintf(stderr, "%s(%s): chunk %s: %s\n", d->file, d->test,
  766. chunk_info[i].name, message);
  767. ++(d->error_count);
  768. flags &= ~flag;
  769. }
  770. }
  771. static void
  772. check_handling(display *d, int def, png_uint_32 chunks, png_uint_32 known,
  773. png_uint_32 unknown, const char *position, int set_callback)
  774. {
  775. while (chunks)
  776. {
  777. png_uint_32 flag = chunks & -(png_int_32)chunks;
  778. int i = find_by_flag(flag);
  779. int keep = chunk_info[i].keep;
  780. const char *type;
  781. const char *errorx = NULL;
  782. if (chunk_info[i].unknown)
  783. {
  784. if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)
  785. {
  786. type = "UNKNOWN (default)";
  787. keep = def;
  788. }
  789. else
  790. type = "UNKNOWN (specified)";
  791. if (flag & known)
  792. errorx = "chunk processed";
  793. else switch (keep)
  794. {
  795. case PNG_HANDLE_CHUNK_AS_DEFAULT:
  796. if (flag & unknown)
  797. errorx = "DEFAULT: unknown chunk saved";
  798. break;
  799. case PNG_HANDLE_CHUNK_NEVER:
  800. if (flag & unknown)
  801. errorx = "DISCARD: unknown chunk saved";
  802. break;
  803. case PNG_HANDLE_CHUNK_IF_SAFE:
  804. if (ancillary(chunk_info[i].name))
  805. {
  806. if (!(flag & unknown))
  807. errorx = "IF-SAFE: unknown ancillary chunk lost";
  808. }
  809. else if (flag & unknown)
  810. errorx = "IF-SAFE: unknown critical chunk saved";
  811. break;
  812. case PNG_HANDLE_CHUNK_ALWAYS:
  813. if (!(flag & unknown))
  814. errorx = "SAVE: unknown chunk lost";
  815. break;
  816. default:
  817. errorx = "internal error: bad keep";
  818. break;
  819. }
  820. } /* unknown chunk */
  821. else /* known chunk */
  822. {
  823. type = "KNOWN";
  824. if (flag & known)
  825. {
  826. /* chunk was processed, it won't have been saved because that is
  827. * caught below when checking for inconsistent processing.
  828. */
  829. if (keep != PNG_HANDLE_CHUNK_AS_DEFAULT)
  830. errorx = "!DEFAULT: known chunk processed";
  831. }
  832. else /* not processed */ switch (keep)
  833. {
  834. case PNG_HANDLE_CHUNK_AS_DEFAULT:
  835. errorx = "DEFAULT: known chunk not processed";
  836. break;
  837. case PNG_HANDLE_CHUNK_NEVER:
  838. if (flag & unknown)
  839. errorx = "DISCARD: known chunk saved";
  840. break;
  841. case PNG_HANDLE_CHUNK_IF_SAFE:
  842. if (ancillary(chunk_info[i].name))
  843. {
  844. if (!(flag & unknown))
  845. errorx = "IF-SAFE: known ancillary chunk lost";
  846. }
  847. else if (flag & unknown)
  848. errorx = "IF-SAFE: known critical chunk saved";
  849. break;
  850. case PNG_HANDLE_CHUNK_ALWAYS:
  851. if (!(flag & unknown))
  852. errorx = "SAVE: known chunk lost";
  853. break;
  854. default:
  855. errorx = "internal error: bad keep (2)";
  856. break;
  857. }
  858. }
  859. if (errorx != NULL)
  860. {
  861. ++(d->error_count);
  862. fprintf(stderr, "%s(%s%s): %s %s %s: %s\n", d->file, d->test,
  863. set_callback ? ",callback" : "",
  864. type, chunk_info[i].name, position, errorx);
  865. }
  866. chunks &= ~flag;
  867. }
  868. }
  869. static void
  870. perform_one_test(FILE *fp, int argc, const char **argv,
  871. png_uint_32 *default_flags, display *d, int set_callback)
  872. {
  873. int def;
  874. png_uint_32 flags[2][4];
  875. rewind(fp);
  876. clear_keep();
  877. memcpy(flags[0], default_flags, sizeof flags[0]);
  878. def = check(fp, argc, argv, flags[1], d, set_callback);
  879. /* If IDAT is being handled as unknown the image read is skipped and all the
  880. * IDATs after the first end up in the end info struct, so in this case add
  881. * IDAT to the list of unknowns. (Do this after 'check' above sets the
  882. * chunk_info 'keep' fields.)
  883. *
  884. * Note that the flag setting has to be in the 'known' field to avoid
  885. * triggering the consistency check below and the flag must only be set if
  886. * there are multiple IDATs, so if the check above did find an unknown IDAT
  887. * after IDAT.
  888. */
  889. if (chunk_info[0/*IDAT*/].keep != PNG_HANDLE_CHUNK_AS_DEFAULT &&
  890. (flags[1][3] & PNG_INFO_IDAT) != 0)
  891. flags[0][2] |= PNG_INFO_IDAT;
  892. /* Chunks should either be known or unknown, never both and this should apply
  893. * whether the chunk is before or after the IDAT (actually, the app can
  894. * probably change this by swapping the handling after the image, but this
  895. * test does not do that.)
  896. */
  897. check_error(d, (flags[0][0]|flags[0][2]) & (flags[0][1]|flags[0][3]),
  898. "chunk handled inconsistently in count tests");
  899. check_error(d, (flags[1][0]|flags[1][2]) & (flags[1][1]|flags[1][3]),
  900. "chunk handled inconsistently in option tests");
  901. /* Now find out what happened to each chunk before and after the IDAT and
  902. * determine if the behavior was correct. First some basic sanity checks,
  903. * any known chunk should be known in the original count, any unknown chunk
  904. * should be either known or unknown in the original.
  905. */
  906. {
  907. png_uint_32 test;
  908. test = flags[1][0] & ~flags[0][0];
  909. check_error(d, test, "new known chunk before IDAT");
  910. test = flags[1][1] & ~(flags[0][0] | flags[0][1]);
  911. check_error(d, test, "new unknown chunk before IDAT");
  912. test = flags[1][2] & ~flags[0][2];
  913. check_error(d, test, "new known chunk after IDAT");
  914. test = flags[1][3] & ~(flags[0][2] | flags[0][3]);
  915. check_error(d, test, "new unknown chunk after IDAT");
  916. }
  917. /* Now each chunk in the original list should have been handled according to
  918. * the options set for that chunk, regardless of whether libpng knows about
  919. * it or not.
  920. */
  921. check_handling(d, def, flags[0][0] | flags[0][1], flags[1][0], flags[1][1],
  922. "before IDAT", set_callback);
  923. check_handling(d, def, flags[0][2] | flags[0][3], flags[1][2], flags[1][3],
  924. "after IDAT", set_callback);
  925. }
  926. static void
  927. perform_one_test_safe(FILE *fp, int argc, const char **argv,
  928. png_uint_32 *default_flags, display *d, const char *test)
  929. {
  930. if (setjmp(d->error_return) == 0)
  931. {
  932. d->test = test; /* allow use of d->error_return */
  933. # ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
  934. perform_one_test(fp, argc, argv, default_flags, d, 0);
  935. # endif
  936. # ifdef PNG_READ_USER_CHUNKS_SUPPORTED
  937. perform_one_test(fp, argc, argv, default_flags, d, 1);
  938. # endif
  939. d->test = init; /* prevent use of d->error_return */
  940. }
  941. }
  942. static const char *standard_tests[] =
  943. {
  944. "discard", "default=discard", 0,
  945. "save", "default=save", 0,
  946. "if-safe", "default=if-safe", 0,
  947. "vpAg", "vpAg=if-safe", 0,
  948. "sTER", "sTER=if-safe", 0,
  949. "IDAT", "default=discard", "IDAT=save", 0,
  950. "sAPI", "bKGD=save", "cHRM=save", "gAMA=save", "all=discard", "iCCP=save",
  951. "sBIT=save", "sRGB=save", "eXIf=save", 0,
  952. 0/*end*/
  953. };
  954. static PNG_NORETURN void
  955. usage(const char *program, const char *reason)
  956. {
  957. fprintf(stderr, "pngunknown: %s: usage:\n %s [--strict] "
  958. "--default|{(CHNK|default|all)=(default|discard|if-safe|save)} "
  959. "testfile.png\n", reason, program);
  960. exit(99);
  961. }
  962. int
  963. main(int argc, const char **argv)
  964. {
  965. FILE *fp;
  966. png_uint_32 default_flags[4/*valid,unknown{before,after}*/];
  967. int strict = 0, default_tests = 0;
  968. const char *count_argv = "default=save";
  969. const char *touch_file = NULL;
  970. display d;
  971. init_display(&d, argv[0]);
  972. while (++argv, --argc > 0)
  973. {
  974. if (strcmp(*argv, "--strict") == 0)
  975. strict = 1;
  976. else if (strcmp(*argv, "--default") == 0)
  977. default_tests = 1;
  978. else if (strcmp(*argv, "--touch") == 0)
  979. {
  980. if (argc > 1)
  981. touch_file = *++argv, --argc;
  982. else
  983. usage(d.program, "--touch: missing file name");
  984. }
  985. else
  986. break;
  987. }
  988. /* A file name is required, but there should be no other arguments if
  989. * --default was specified.
  990. */
  991. if (argc <= 0)
  992. usage(d.program, "missing test file");
  993. /* GCC BUG: if (default_tests && argc != 1) triggers some weird GCC argc
  994. * optimization which causes warnings with -Wstrict-overflow!
  995. */
  996. else if (default_tests) if (argc != 1)
  997. usage(d.program, "extra arguments");
  998. /* The name of the test file is the last argument; remove it. */
  999. d.file = argv[--argc];
  1000. fp = fopen(d.file, "rb");
  1001. if (fp == NULL)
  1002. {
  1003. perror(d.file);
  1004. exit(99);
  1005. }
  1006. /* First find all the chunks, known and unknown, in the test file, a failure
  1007. * here aborts the whole test.
  1008. *
  1009. * If 'save' is supported then the normal saving method should happen,
  1010. * otherwise if 'read' is supported then the read callback will do the
  1011. * same thing. If both are supported the 'read' callback won't be
  1012. * instantiated by default. If 'save' is *not* supported then a user
  1013. * callback is required even though we can call png_get_unknown_chunks.
  1014. */
  1015. if (check(fp, 1, &count_argv, default_flags, &d,
  1016. # ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
  1017. 0
  1018. # else
  1019. 1
  1020. # endif
  1021. ) != PNG_HANDLE_CHUNK_ALWAYS)
  1022. {
  1023. fprintf(stderr, "%s: %s: internal error\n", d.program, d.file);
  1024. exit(99);
  1025. }
  1026. /* Now find what the various supplied options cause to change: */
  1027. if (!default_tests)
  1028. {
  1029. d.test = cmd; /* acts as a flag to say exit, do not longjmp */
  1030. # ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
  1031. perform_one_test(fp, argc, argv, default_flags, &d, 0);
  1032. # endif
  1033. # ifdef PNG_READ_USER_CHUNKS_SUPPORTED
  1034. perform_one_test(fp, argc, argv, default_flags, &d, 1);
  1035. # endif
  1036. d.test = init;
  1037. }
  1038. else
  1039. {
  1040. const char **test = standard_tests;
  1041. /* Set the exit_test pointer here so we can continue after a libpng error.
  1042. * NOTE: this leaks memory because the png_struct data from the failing
  1043. * test is never freed.
  1044. */
  1045. while (*test)
  1046. {
  1047. const char *this_test = *test++;
  1048. const char **next = test;
  1049. int count = display_rc(&d, strict), new_count;
  1050. const char *result;
  1051. int arg_count = 0;
  1052. while (*next) ++next, ++arg_count;
  1053. perform_one_test_safe(fp, arg_count, test, default_flags, &d,
  1054. this_test);
  1055. new_count = display_rc(&d, strict);
  1056. if (new_count == count)
  1057. result = "PASS";
  1058. else
  1059. result = "FAIL";
  1060. printf("%s: %s %s\n", result, d.program, this_test);
  1061. test = next+1;
  1062. }
  1063. }
  1064. fclose(fp);
  1065. if (display_rc(&d, strict) == 0)
  1066. {
  1067. /* Success, touch the success file if appropriate */
  1068. if (touch_file != NULL)
  1069. {
  1070. FILE *fsuccess = fopen(touch_file, "wt");
  1071. if (fsuccess != NULL)
  1072. {
  1073. int err = 0;
  1074. fprintf(fsuccess, "PNG unknown tests succeeded\n");
  1075. fflush(fsuccess);
  1076. err = ferror(fsuccess);
  1077. if (fclose(fsuccess) || err)
  1078. {
  1079. fprintf(stderr, "%s: write failed\n", touch_file);
  1080. exit(99);
  1081. }
  1082. }
  1083. else
  1084. {
  1085. fprintf(stderr, "%s: open failed\n", touch_file);
  1086. exit(99);
  1087. }
  1088. }
  1089. return 0;
  1090. }
  1091. return 1;
  1092. }
  1093. #else /* !(READ_USER_CHUNKS || SAVE_UNKNOWN_CHUNKS) */
  1094. int
  1095. main(void)
  1096. {
  1097. fprintf(stderr,
  1098. " test ignored: no support to find out about unknown chunks\n");
  1099. /* So the test is skipped: */
  1100. return SKIP;
  1101. }
  1102. #endif /* READ_USER_CHUNKS || SAVE_UNKNOWN_CHUNKS */
  1103. #else /* !(SET_UNKNOWN_CHUNKS && READ) */
  1104. int
  1105. main(void)
  1106. {
  1107. fprintf(stderr,
  1108. " test ignored: no support to modify unknown chunk handling\n");
  1109. /* So the test is skipped: */
  1110. return SKIP;
  1111. }
  1112. #endif /* SET_UNKNOWN_CHUNKS && READ*/