[libpng17] Catch up with recent libpng16 changes; unknown handling and spelling

corrections
This commit is contained in:
John Bowler
2013-09-30 08:28:05 -05:00
committed by Glenn Randers-Pehrson
parent d9f60caf72
commit 7657ac14f2
15 changed files with 315 additions and 100 deletions

View File

@@ -362,6 +362,8 @@ Version 1.7.0beta19 [September 30, 2013]
builds. builds.
Fixed default behavior of ARM_NEON_API. If the ARM NEON API option is Fixed default behavior of ARM_NEON_API. If the ARM NEON API option is
compiled without the CHECK option it defaulted to on, not off. compiled without the CHECK option it defaulted to on, not off.
Catch up with recent libpng16 changes; unknown handling and spelling
corrections
Send comments/corrections/commendations to png-mng-implement at lists.sf.net Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit (subscription required; visit

View File

@@ -4651,6 +4651,8 @@ Version 1.7.0beta19 [September 30, 2013]
builds. builds.
Fixed default behavior of ARM_NEON_API. If the ARM NEON API option is Fixed default behavior of ARM_NEON_API. If the ARM NEON API option is
compiled without the CHECK option it defaulted to on, not off. compiled without the CHECK option it defaulted to on, not off.
Catch up with recent libpng16 changes; unknown handling and spelling
corrections
Send comments/corrections/commendations to png-mng-implement at lists.sf.net Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit (subscription required; visit

View File

@@ -1,7 +1,7 @@
/* pngunknown.c - test the read side unknown chunk handling /* pngunknown.c - test the read side unknown chunk handling
* *
* Last changed in libpng 1.7.0 [(PENDING RELEASE)] * Last changed in libpng 1.6.0 [February 14, 2013]
* Copyright (c) 2013 Glenn Randers-Pehrson * Copyright (c) 2013 Glenn Randers-Pehrson
* Written by John Cunningham Bowler * Written by John Cunningham Bowler
* *
@@ -30,7 +30,19 @@
# include "../../png.h" # include "../../png.h"
#endif #endif
#ifdef PNG_READ_SUPPORTED /* Since this program tests the ability to change the unknown chunk handling
* these must be defined:
*/
#if defined(PNG_SET_UNKNOWN_CHUNKS_SUPPORTED) &&\
defined(PNG_READ_SUPPORTED)
/* One of these must be defined to allow us to find out what happened. It is
* still useful to set unknown chunk handling without either of these in order
* to cause *known* chunks to be discarded. This can be a significant
* efficiency gain, but it can't really be tested here.
*/
#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) ||\
defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)
#if PNG_LIBPNG_VER < 10500 #if PNG_LIBPNG_VER < 10500
/* This deliberately lacks the PNG_CONST. */ /* This deliberately lacks the PNG_CONST. */
@@ -75,8 +87,60 @@ typedef png_byte *png_const_bytep;
# define png_const_structp png_structp # define png_const_structp png_structp
#endif #endif
/* Types of chunks not known to libpng */ #ifdef __cplusplus
#define png_vpAg PNG_U32(118, 112, 65, 103) # define this not_the_cpp_this
# define new not_the_cpp_new
# define voidcast(type, value) static_cast<type>(value)
#else
# define voidcast(type, value) (value)
#endif /* __cplusplus */
/* Unused formal parameter errors are removed using the following macro which is
* expected to have no bad effects on performance.
*/
#ifndef UNUSED
# if defined(__GNUC__) || defined(_MSC_VER)
# define UNUSED(param) (void)param;
# else
# define UNUSED(param)
# endif
#endif
/* Copied from pngpriv.h */
#define PNG_32b(b,s) ((png_uint_32)(b) << (s))
#define PNG_CHUNK(b1,b2,b3,b4) \
(PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0))
#define png_IHDR PNG_CHUNK( 73, 72, 68, 82)
#define png_IDAT PNG_CHUNK( 73, 68, 65, 84)
#define png_IEND PNG_CHUNK( 73, 69, 78, 68)
#define png_PLTE PNG_CHUNK( 80, 76, 84, 69)
#define png_bKGD PNG_CHUNK( 98, 75, 71, 68)
#define png_cHRM PNG_CHUNK( 99, 72, 82, 77)
#define png_gAMA PNG_CHUNK(103, 65, 77, 65)
#define png_hIST PNG_CHUNK(104, 73, 83, 84)
#define png_iCCP PNG_CHUNK(105, 67, 67, 80)
#define png_iTXt PNG_CHUNK(105, 84, 88, 116)
#define png_oFFs PNG_CHUNK(111, 70, 70, 115)
#define png_pCAL PNG_CHUNK(112, 67, 65, 76)
#define png_sCAL PNG_CHUNK(115, 67, 65, 76)
#define png_pHYs PNG_CHUNK(112, 72, 89, 115)
#define png_sBIT PNG_CHUNK(115, 66, 73, 84)
#define png_sPLT PNG_CHUNK(115, 80, 76, 84)
#define png_sRGB PNG_CHUNK(115, 82, 71, 66)
#define png_sTER PNG_CHUNK(115, 84, 69, 82)
#define png_tEXt PNG_CHUNK(116, 69, 88, 116)
#define png_tIME PNG_CHUNK(116, 73, 77, 69)
#define png_tRNS PNG_CHUNK(116, 82, 78, 83)
#define png_zTXt PNG_CHUNK(122, 84, 88, 116)
#define png_vpAg PNG_CHUNK('v', 'p', 'A', 'g')
/* Test on flag values as defined in the spec (section 5.4): */
#define PNG_CHUNK_ANCILLARY(c ) (1 & ((c) >> 29))
#define PNG_CHUNK_CRITICAL(c) (!PNG_CHUNK_ANCILLARY(c))
#define PNG_CHUNK_PRIVATE(c) (1 & ((c) >> 21))
#define PNG_CHUNK_RESERVED(c) (1 & ((c) >> 13))
#define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >> 5))
/* Chunk information */ /* Chunk information */
#define PNG_INFO_tEXt 0x10000000U #define PNG_INFO_tEXt 0x10000000U
@@ -105,8 +169,8 @@ static struct
{ "PLTE", PNG_INFO_PLTE, png_PLTE, 0, 0, ABSENT, 0 }, { "PLTE", PNG_INFO_PLTE, png_PLTE, 0, 0, ABSENT, 0 },
/* Non-critical chunks that libpng handles */ /* Non-critical chunks that libpng handles */
/* This is a mess but it seems to be the only way to do it - there is no way to /* This is a mess but it seems to be the only way to do it - there is no way
* check for definition outside a #if. * to check for a definition outside a #if.
*/ */
{ "bKGD", PNG_INFO_bKGD, png_bKGD, { "bKGD", PNG_INFO_bKGD, png_bKGD,
# ifdef PNG_READ_bKGD_SUPPORTED # ifdef PNG_READ_bKGD_SUPPORTED
@@ -283,14 +347,16 @@ find_by_flag(png_uint_32 flag)
static int static int
ancillary(const char *name) ancillary(const char *name)
{ {
return PNG_CHUNK_ANCILLARY(PNG_U32(name[0], name[1], name[2], name[3])); return PNG_CHUNK_ANCILLARY(PNG_CHUNK(name[0], name[1], name[2], name[3]));
} }
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
static int static int
ancillaryb(const png_byte *name) ancillaryb(const png_byte *name)
{ {
return PNG_CHUNK_ANCILLARY(PNG_U32(name[0], name[1], name[2], name[3])); return PNG_CHUNK_ANCILLARY(PNG_CHUNK(name[0], name[1], name[2], name[3]));
} }
#endif
/* Type of an error_ptr */ /* Type of an error_ptr */
typedef struct typedef struct
@@ -298,8 +364,11 @@ typedef struct
jmp_buf error_return; jmp_buf error_return;
png_structp png_ptr; png_structp png_ptr;
png_infop info_ptr, end_ptr; png_infop info_ptr, end_ptr;
png_uint_32 before_IDAT;
png_uint_32 after_IDAT;
int error_count; int error_count;
int warning_count; int warning_count;
int keep; /* the default value */
const char *program; const char *program;
const char *file; const char *file;
const char *test; const char *test;
@@ -410,11 +479,88 @@ get_valid(display *d, png_infop info_ptr)
return flags; return flags;
} }
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
static int
read_callback(png_structp pp, png_unknown_chunkp pc)
{
/* This function mimics the behavior of png_set_keep_unknown_chunks by
* returning '0' to keep the chunk and '1' to discard it.
*/
display *d = voidcast(display*, png_get_user_chunk_ptr(pp));
int chunk = findb(pc->name);
int keep, discard;
if (chunk < 0) /* not one in our list, so not a known chunk */
keep = d->keep;
else
{
keep = chunk_info[chunk].keep;
if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)
{
/* See the comments in png.h - use the default for unknown chunks,
* do not keep known chunks.
*/
if (chunk_info[chunk].unknown)
keep = d->keep;
else
keep = PNG_HANDLE_CHUNK_NEVER;
}
}
switch (keep)
{
default:
fprintf(stderr, "%s(%s): %d: unrecognized chunk option\n", d->file,
d->test, chunk_info[chunk].keep);
display_exit(d);
case PNG_HANDLE_CHUNK_AS_DEFAULT:
case PNG_HANDLE_CHUNK_NEVER:
discard = 1/*handled; discard*/;
break;
case PNG_HANDLE_CHUNK_IF_SAFE:
case PNG_HANDLE_CHUNK_ALWAYS:
discard = 0/*not handled; keep*/;
break;
}
/* Also store information about this chunk in the display, the relevant flag
* is set if the chunk is to be kept ('not handled'.)
*/
if (chunk >= 0) if (!discard) /* stupidity to stop a GCC warning */
{
png_uint_32 flag = chunk_info[chunk].flag;
if (pc->location & PNG_AFTER_IDAT)
d->after_IDAT |= flag;
else
d->before_IDAT |= flag;
}
/* However if there is no support to store unknown chunks don't ask libpng to
* do it; there will be an png_error.
*/
# ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
return discard;
# else
return 1; /*handled; discard*/
# endif
}
#endif /* READ_USER_CHUNKS_SUPPORTED */
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
static png_uint_32 static png_uint_32
get_unknown(display *d, int def, png_infop info_ptr) get_unknown(display *d, png_infop info_ptr, int after_IDAT)
{ {
/* Create corresponding 'unknown' flags */ /* Create corresponding 'unknown' flags */
png_uint_32 flags = 0; png_uint_32 flags = 0;
UNUSED(after_IDAT)
{ {
png_unknown_chunkp unknown; png_unknown_chunkp unknown;
int num_unknown = png_get_unknown_chunks(d->png_ptr, info_ptr, &unknown); int num_unknown = png_get_unknown_chunks(d->png_ptr, info_ptr, &unknown);
@@ -424,16 +570,16 @@ get_unknown(display *d, int def, png_infop info_ptr)
int chunk = findb(unknown[num_unknown].name); int chunk = findb(unknown[num_unknown].name);
/* Chunks not known to pngunknown must be validated here; since they /* Chunks not known to pngunknown must be validated here; since they
* must also be unknown to libpng the 'def' behavior should have been * must also be unknown to libpng the 'display->keep' behavior should
* used. * have been used.
*/ */
if (chunk < 0) switch (def) if (chunk < 0) switch (d->keep)
{ {
default: /* impossible */ default: /* impossible */
case PNG_HANDLE_CHUNK_AS_DEFAULT: case PNG_HANDLE_CHUNK_AS_DEFAULT:
case PNG_HANDLE_CHUNK_NEVER: case PNG_HANDLE_CHUNK_NEVER:
fprintf(stderr, "%s(%s): %s: %s: unknown chunk saved\n", fprintf(stderr, "%s(%s): %s: %s: unknown chunk saved\n",
d->file, d->test, def ? "discard" : "default", d->file, d->test, d->keep ? "discard" : "default",
unknown[num_unknown].name); unknown[num_unknown].name);
++(d->error_count); ++(d->error_count);
break; break;
@@ -459,14 +605,39 @@ get_unknown(display *d, int def, png_infop info_ptr)
return flags; return flags;
} }
#else
static png_uint_32
get_unknown(display *d, png_infop info_ptr, int after_IDAT)
/* Otherwise this will return the cached values set by any user callback */
{
UNUSED(info_ptr);
if (after_IDAT)
return d->after_IDAT;
else
return d->before_IDAT;
}
# ifndef PNG_READ_USER_CHUNKS_SUPPORTED
/* The #defines above should mean this is never reached, it's just here as
* a check to ensure the logic is correct.
*/
# error No store support and no user chunk support, this will not work
# endif
#endif
static int static int
check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/, check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
display *d) display *d, int set_callback)
{ {
int i, def = PNG_HANDLE_CHUNK_AS_DEFAULT, npasses, ipass; int i, npasses, ipass;
png_uint_32 height; png_uint_32 height;
d->keep = PNG_HANDLE_CHUNK_AS_DEFAULT;
d->before_IDAT = 0;
d->after_IDAT = 0;
/* Some of these errors are permanently fatal and cause an exit here, others /* Some of these errors are permanently fatal and cause an exit here, others
* are per-test and cause an error return. * are per-test and cause an error return.
*/ */
@@ -492,6 +663,16 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
png_init_io(d->png_ptr, fp); png_init_io(d->png_ptr, fp);
# ifdef PNG_READ_USER_CHUNKS_SUPPORTED
/* This is only done if requested by the caller; it interferes with the
* standard store/save mechanism.
*/
if (set_callback)
png_set_read_user_chunk_fn(d->png_ptr, d, read_callback);
# else
UNUSED(set_callback)
# endif
/* Handle each argument in turn; multiple settings are possible for the same /* Handle each argument in turn; multiple settings are possible for the same
* chunk and multiple calls will occur (the last one should override all * chunk and multiple calls will occur (the last one should override all
* preceding ones). * preceding ones).
@@ -531,13 +712,11 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
* in this case, so we just check the arguments! This could * in this case, so we just check the arguments! This could
* be improved in the future by using the read callback. * be improved in the future by using the read callback.
*/ */
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
png_byte name[5]; png_byte name[5];
memcpy(name, chunk_info[chunk].name, 5); memcpy(name, chunk_info[chunk].name, 5);
png_set_keep_unknown_chunks(d->png_ptr, option, name, 1); png_set_keep_unknown_chunks(d->png_ptr, option, name, 1);
chunk_info[chunk].keep = option; chunk_info[chunk].keep = option;
# endif
continue; continue;
} }
@@ -546,10 +725,8 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
case 7: /* default */ case 7: /* default */
if (memcmp(argv[i], "default", 7) == 0) if (memcmp(argv[i], "default", 7) == 0)
{ {
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, 0); png_set_keep_unknown_chunks(d->png_ptr, option, NULL, 0);
# endif d->keep = option;
def = option;
continue; continue;
} }
@@ -558,14 +735,12 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
case 3: /* all */ case 3: /* all */
if (memcmp(argv[i], "all", 3) == 0) if (memcmp(argv[i], "all", 3) == 0)
{ {
# ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
png_set_keep_unknown_chunks(d->png_ptr, option, NULL, -1); png_set_keep_unknown_chunks(d->png_ptr, option, NULL, -1);
def = option; d->keep = option;
for (chunk = 0; chunk < NINFO; ++chunk) for (chunk = 0; chunk < NINFO; ++chunk)
if (chunk_info[chunk].all) if (chunk_info[chunk].all)
chunk_info[chunk].keep = option; chunk_info[chunk].keep = option;
# endif
continue; continue;
} }
@@ -639,18 +814,18 @@ check(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,
png_read_end(d->png_ptr, d->end_ptr); png_read_end(d->png_ptr, d->end_ptr);
flags[0] = get_valid(d, d->info_ptr); flags[0] = get_valid(d, d->info_ptr);
flags[1] = get_unknown(d, def, d->info_ptr); flags[1] = get_unknown(d, d->info_ptr, 0/*before IDAT*/);
/* Only png_read_png sets PNG_INFO_IDAT! */ /* Only png_read_png sets PNG_INFO_IDAT! */
flags[chunk_info[0/*IDAT*/].keep != PNG_HANDLE_CHUNK_AS_DEFAULT] |= flags[chunk_info[0/*IDAT*/].keep != PNG_HANDLE_CHUNK_AS_DEFAULT] |=
PNG_INFO_IDAT; PNG_INFO_IDAT;
flags[2] = get_valid(d, d->end_ptr); flags[2] = get_valid(d, d->end_ptr);
flags[3] = get_unknown(d, def, d->end_ptr); flags[3] = get_unknown(d, d->end_ptr, 1/*after IDAT*/);
clean_display(d); clean_display(d);
return def; return d->keep;
} }
static void static void
@@ -788,7 +963,7 @@ check_handling(display *d, int def, png_uint_32 chunks, png_uint_32 known,
static void static void
perform_one_test(FILE *fp, int argc, const char **argv, perform_one_test(FILE *fp, int argc, const char **argv,
png_uint_32 *default_flags, display *d) png_uint_32 *default_flags, display *d, int set_callback)
{ {
int def; int def;
png_uint_32 flags[2][4]; png_uint_32 flags[2][4];
@@ -797,7 +972,7 @@ perform_one_test(FILE *fp, int argc, const char **argv,
clear_keep(); clear_keep();
memcpy(flags[0], default_flags, sizeof flags[0]); memcpy(flags[0], default_flags, sizeof flags[0]);
def = check(fp, argc, argv, flags[1], d); def = check(fp, argc, argv, flags[1], d, set_callback);
/* Chunks should either be known or unknown, never both and this should apply /* Chunks should either be known or unknown, never both and this should apply
* whether the chunk is before or after the IDAT (actually, the app can * whether the chunk is before or after the IDAT (actually, the app can
@@ -844,7 +1019,12 @@ perform_one_test_safe(FILE *fp, int argc, const char **argv,
if (setjmp(d->error_return) == 0) if (setjmp(d->error_return) == 0)
{ {
d->test = test; /* allow use of d->error_return */ d->test = test; /* allow use of d->error_return */
perform_one_test(fp, argc, argv, default_flags, d); # ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
perform_one_test(fp, argc, argv, default_flags, d, 0);
# endif
# ifdef PNG_READ_USER_CHUNKS_SUPPORTED
perform_one_test(fp, argc, argv, default_flags, d, 1);
# endif
d->test = init; /* prevent use of d->error_return */ d->test = init; /* prevent use of d->error_return */
} }
} }
@@ -868,7 +1048,7 @@ usage(const char *program, const char *reason)
fprintf(stderr, "pngunknown: %s: usage:\n %s [--strict] " fprintf(stderr, "pngunknown: %s: usage:\n %s [--strict] "
"--default|{(CHNK|default|all)=(default|discard|if-safe|save)} " "--default|{(CHNK|default|all)=(default|discard|if-safe|save)} "
"testfile.png\n", reason, program); "testfile.png\n", reason, program);
exit(2); exit(99);
} }
int int
@@ -916,11 +1096,6 @@ main(int argc, const char **argv)
else if (default_tests) if (argc != 1) else if (default_tests) if (argc != 1)
usage(d.program, "extra arguments"); usage(d.program, "extra arguments");
# ifndef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
fprintf(stderr, "%s: warning: no 'save' support so arguments ignored\n",
d.program);
# endif
/* The name of the test file is the last argument; remove it. */ /* The name of the test file is the last argument; remove it. */
d.file = argv[--argc]; d.file = argv[--argc];
@@ -928,24 +1103,40 @@ main(int argc, const char **argv)
if (fp == NULL) if (fp == NULL)
{ {
perror(d.file); perror(d.file);
exit(2); exit(99);
} }
/* First find all the chunks, known and unknown, in the test file, a failure /* First find all the chunks, known and unknown, in the test file, a failure
* here aborts the whole test. * here aborts the whole test.
*
* If 'save' is supported then the normal saving method should happen,
* otherwise if 'read' is supported then the read callback will do the
* same thing. If both are supported the 'read' callback won't be
* instantiated by default. If 'save' is *not* supported then a user
* callback is required even though we can call png_get_unknown_chunks.
*/ */
if (check(fp, 1, &count_argv, default_flags, &d) != if (check(fp, 1, &count_argv, default_flags, &d,
PNG_HANDLE_CHUNK_ALWAYS) # ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
0
# else
1
# endif
) != PNG_HANDLE_CHUNK_ALWAYS)
{ {
fprintf(stderr, "%s: %s: internal error\n", d.program, d.file); fprintf(stderr, "%s: %s: internal error\n", d.program, d.file);
exit(3); exit(99);
} }
/* Now find what the various supplied options cause to change: */ /* Now find what the various supplied options cause to change: */
if (!default_tests) if (!default_tests)
{ {
d.test = cmd; /* acts as a flag to say exit, do not longjmp */ d.test = cmd; /* acts as a flag to say exit, do not longjmp */
perform_one_test(fp, argc, argv, default_flags, &d); # ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED
perform_one_test(fp, argc, argv, default_flags, &d, 0);
# endif
# ifdef PNG_READ_USER_CHUNKS_SUPPORTED
perform_one_test(fp, argc, argv, default_flags, &d, 1);
# endif
d.test = init; d.test = init;
} }
@@ -1003,14 +1194,14 @@ main(int argc, const char **argv)
if (fclose(fsuccess) || err) if (fclose(fsuccess) || err)
{ {
fprintf(stderr, "%s: write failed\n", touch_file); fprintf(stderr, "%s: write failed\n", touch_file);
exit(1); exit(99);
} }
} }
else else
{ {
fprintf(stderr, "%s: open failed\n", touch_file); fprintf(stderr, "%s: open failed\n", touch_file);
exit(1); exit(99);
} }
} }
@@ -1020,13 +1211,24 @@ main(int argc, const char **argv)
return 1; return 1;
} }
#else #else /* !(READ_USER_CHUNKS || SAVE_UNKNOWN_CHUNKS) */
int int
main(void) main(void)
{ {
fprintf(stderr, fprintf(stderr,
" test ignored because libpng was not built with unknown chunk support\n"); " test ignored: no support to find out about unknown chunks\n");
/* So the test is skipped: */ /* So the test is skipped: */
return 77; return 77;
} }
#endif #endif /* READ_USER_CHUNKS || SAVE_UNKNOWN_CHUNKS */
#else /* !(SET_UNKNOWN_CHUNKS && READ) */
int
main(void)
{
fprintf(stderr,
" test ignored: no support to modify unknown chunk handling\n");
/* So the test is skipped: */
return 77;
}
#endif /* SET_UNKNOWN_CHUNKS && READ*/

View File

@@ -6030,7 +6030,7 @@ transform_test(png_modifier *pmIn, PNG_CONST png_uint_32 idIn,
Catch(fault) Catch(fault)
{ {
modifier_reset((png_modifier*)fault); modifier_reset(voidcast(png_modifier*,(void*)fault));
} }
} }
@@ -8874,7 +8874,7 @@ gamma_test(png_modifier *pmIn, PNG_CONST png_byte colour_typeIn,
} }
Catch(fault) Catch(fault)
modifier_reset((png_modifier*)fault); modifier_reset(voidcast(png_modifier*,(void*)fault));
} }
static void gamma_threshold_test(png_modifier *pm, png_byte colour_type, static void gamma_threshold_test(png_modifier *pm, png_byte colour_type,

View File

@@ -100,12 +100,12 @@ $(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak $(ZH)\
$(PNGSRC)/scripts/pnglibconf.dfa \ $(PNGSRC)/scripts/pnglibconf.dfa \
$(PNGSRC)/scripts/options.awk pngusr.h pngusr.dfa $(PNGSRC)/scripts/options.awk pngusr.h pngusr.dfa
$(RM) pnglibconf.h pnglibconf.dfn $(RM) pnglibconf.h pnglibconf.dfn
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\ $(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG -I."\ srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG -I."\
DFA_XTRA="pngusr.dfa" $@ DFA_XTRA="pngusr.dfa" $@
clean: clean:
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\ $(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
srcdir=$(PNGSRC) clean srcdir=$(PNGSRC) clean
$(RM) pngm2pnm$(O) $(RM) pngm2pnm$(O)
$(RM) pngm2pnm$(E) $(RM) pngm2pnm$(E)

View File

@@ -99,12 +99,12 @@ $(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak $(ZH)\
$(PNGSRC)/scripts/pnglibconf.dfa \ $(PNGSRC)/scripts/pnglibconf.dfa \
$(PNGSRC)/scripts/options.awk pngusr.h pngusr.dfa $(PNGSRC)/scripts/options.awk pngusr.h pngusr.dfa
$(RM) pnglibconf.h pnglibconf.dfn $(RM) pnglibconf.h pnglibconf.dfn
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\ $(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG -I."\ srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG -I."\
DFA_XTRA="pngusr.dfa" $@ DFA_XTRA="pngusr.dfa" $@
clean: clean:
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\ $(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
srcdir=$(PNGSRC) clean srcdir=$(PNGSRC) clean
$(RM) pnm2pngm$(O) $(RM) pnm2pngm$(O)
$(RM) pnm2pngm$(E) $(RM) pnm2pngm$(E)

View File

@@ -115,12 +115,12 @@ $(PNGCONF): $(PNGSRC)/scripts/pnglibconf.mak $(ZH)\
$(PNGSRC)/scripts/pnglibconf.dfa \ $(PNGSRC)/scripts/pnglibconf.dfa \
$(PNGSRC)/scripts/options.awk pngusr.h pngusr.dfa $(PNGSRC)/scripts/options.awk pngusr.h pngusr.dfa
$(RM) pnglibconf.h pnglibconf.dfn $(RM) pnglibconf.h pnglibconf.dfn
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\ $(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG -I."\ srcdir=$(PNGSRC) CPPFLAGS="-DPNG_USER_CONFIG -I."\
DFA_XTRA="pngusr.dfa" $@ DFA_XTRA="pngusr.dfa" $@
clean: clean:
$(MAKE) $(MAKEFLAGS) -f $(PNGSRC)/scripts/pnglibconf.mak\ $(MAKE) -f $(PNGSRC)/scripts/pnglibconf.mak $(MAKEFLAGS)\
srcdir=$(PNGSRC) clean srcdir=$(PNGSRC) clean
$(RM) rpng2-x$(O) $(RM) rpng2-x$(O)
$(RM) rpng2-x$(E) $(RM) rpng2-x$(E)

View File

@@ -3658,7 +3658,7 @@ usage(const char *prog)
" --optimize (-o):", " --optimize (-o):",
" Find the smallest deflate window size for the compressed data.", " Find the smallest deflate window size for the compressed data.",
" --strip=[none|crc|unsafe|unused|transform|color|all]:", " --strip=[none|crc|unsafe|unused|transform|color|all]:",
" none: Retain all chunks.", " none (default): Retain all chunks.",
" crc: Remove chunks with a bad CRC.", " crc: Remove chunks with a bad CRC.",
" unsafe: Remove chunks that may be unsafe to retain if the image data", " unsafe: Remove chunks that may be unsafe to retain if the image data",
" is modified. This is set automatically if --max is given but", " is modified. This is set automatically if --max is given but",
@@ -3682,7 +3682,7 @@ usage(const char *prog)
" --max=<number>:", " --max=<number>:",
" Use IDAT chunks sized <number>. If no number is given the the IDAT", " Use IDAT chunks sized <number>. If no number is given the the IDAT",
" chunks will be the maximum size permitted; 2^31-1 bytes. If the option", " chunks will be the maximum size permitted; 2^31-1 bytes. If the option",
" is ommited the original chunk sizes will not be changed. When the", " is omitted the original chunk sizes will not be changed. When the",
" option is given --strip=unsafe is set automatically, this may be", " option is given --strip=unsafe is set automatically, this may be",
" cancelled if you know that all unknown unsafe-to-copy chunks really are", " cancelled if you know that all unknown unsafe-to-copy chunks really are",
" safe to copy across an IDAT size change. This is true of all chunks", " safe to copy across an IDAT size change. This is true of all chunks",
@@ -3690,7 +3690,7 @@ usage(const char *prog)
" MESSAGES", " MESSAGES",
" By default the program only outputs summaries for each file.", " By default the program only outputs summaries for each file.",
" --quiet (-q):", " --quiet (-q):",
" Do not output the summaries except for files which cannot be read, with", " Do not output the summaries except for files which cannot be read. With",
" two --quiets these are not output either.", " two --quiets these are not output either.",
" --errors (-e):", " --errors (-e):",
" Output errors from libpng and the program (except too-far-back).", " Output errors from libpng and the program (except too-far-back).",

9
png.c
View File

@@ -691,13 +691,13 @@ png_get_copyright(png_const_structrp png_ptr)
#else #else
# ifdef __STDC__ # ifdef __STDC__
return PNG_STRING_NEWLINE \ return PNG_STRING_NEWLINE \
"libpng version 1.7.0beta19 - September 20, 2013" PNG_STRING_NEWLINE \ "libpng version 1.7.0beta19 - September 30, 2013" PNG_STRING_NEWLINE \
"Copyright (c) 1998-2013 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \ "Copyright (c) 1998-2013 Glenn Randers-Pehrson" PNG_STRING_NEWLINE \
"Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \ "Copyright (c) 1996-1997 Andreas Dilger" PNG_STRING_NEWLINE \
"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \ "Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc." \
PNG_STRING_NEWLINE; PNG_STRING_NEWLINE;
# else # else
return "libpng version 1.7.0beta19 - September 20, 2013\ return "libpng version 1.7.0beta19 - September 30, 2013\
Copyright (c) 1998-2013 Glenn Randers-Pehrson\ Copyright (c) 1998-2013 Glenn Randers-Pehrson\
Copyright (c) 1996-1997 Andreas Dilger\ Copyright (c) 1996-1997 Andreas Dilger\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc."; Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.";
@@ -778,7 +778,8 @@ png_handle_as_unknown(png_const_structrp png_ptr, png_const_bytep chunk_name)
return PNG_HANDLE_CHUNK_AS_DEFAULT; return PNG_HANDLE_CHUNK_AS_DEFAULT;
} }
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) ||\
defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
int /* PRIVATE */ int /* PRIVATE */
png_chunk_unknown_handling(png_const_structrp png_ptr, png_uint_32 chunk_name) png_chunk_unknown_handling(png_const_structrp png_ptr, png_uint_32 chunk_name)
{ {
@@ -787,7 +788,7 @@ png_chunk_unknown_handling(png_const_structrp png_ptr, png_uint_32 chunk_name)
PNG_CSTRING_FROM_CHUNK(chunk_string, chunk_name); PNG_CSTRING_FROM_CHUNK(chunk_string, chunk_name);
return png_handle_as_unknown(png_ptr, chunk_string); return png_handle_as_unknown(png_ptr, chunk_string);
} }
#endif /* READ_UNKNOWN_CHUNKS */ #endif /* READ_UNKNOWN_CHUNKS || HANDLE_AS_UNKNOWN */
#endif /* SET_UNKNOWN_CHUNKS */ #endif /* SET_UNKNOWN_CHUNKS */
/* This function was added to libpng-1.0.7 */ /* This function was added to libpng-1.0.7 */

13
png.h
View File

@@ -1,7 +1,7 @@
/* png.h - header file for PNG reference library /* png.h - header file for PNG reference library
* *
* libpng version 1.7.0beta19 - September 16, 2013 * libpng version 1.7.0beta19 - September 30, 2013
* Copyright (c) 1998-2013 Glenn Randers-Pehrson * Copyright (c) 1998-2013 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
@@ -11,7 +11,7 @@
* Authors and maintainers: * Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
* libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
* libpng versions 0.97, January 1998, through 1.7.0beta19 - September 16, 2013: Glenn * libpng versions 0.97, January 1998, through 1.7.0beta19 - September 30, 2013: Glenn
* See also "Contributing Authors", below. * See also "Contributing Authors", below.
* *
* Note about libpng version numbers: * Note about libpng version numbers:
@@ -200,7 +200,7 @@
* *
* This code is released under the libpng license. * This code is released under the libpng license.
* *
* libpng versions 1.2.6, August 15, 2004, through 1.7.0beta19, September 16, 2013, are * libpng versions 1.2.6, August 15, 2004, through 1.7.0beta19, September 30, 2013, are
* Copyright (c) 2004, 2006-2013 Glenn Randers-Pehrson, and are * Copyright (c) 2004, 2006-2013 Glenn Randers-Pehrson, and are
* distributed according to the same disclaimer and license as libpng-1.2.5 * distributed according to the same disclaimer and license as libpng-1.2.5
* with the following individual added to the list of Contributing Authors: * with the following individual added to the list of Contributing Authors:
@@ -312,7 +312,7 @@
* Y2K compliance in libpng: * Y2K compliance in libpng:
* ========================= * =========================
* *
* September 16, 2013 * September 30, 2013
* *
* Since the PNG Development group is an ad-hoc body, we can't make * Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration. * an official declaration.
@@ -380,7 +380,7 @@
/* Version information for png.h - this should match the version in png.c */ /* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.7.0beta19" #define PNG_LIBPNG_VER_STRING "1.7.0beta19"
#define PNG_HEADER_VERSION_STRING \ #define PNG_HEADER_VERSION_STRING \
" libpng version 1.7.0beta19 - September 16, 2013\n" " libpng version 1.7.0beta19 - September 30, 2013\n"
#define PNG_LIBPNG_VER_SONUM 17 #define PNG_LIBPNG_VER_SONUM 17
#define PNG_LIBPNG_VER_DLLNUM 17 #define PNG_LIBPNG_VER_DLLNUM 17
@@ -822,7 +822,8 @@ typedef png_time * png_timep;
typedef const png_time * png_const_timep; typedef const png_time * png_const_timep;
typedef png_time * * png_timepp; typedef png_time * * png_timepp;
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED #if defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) ||\
defined(PNG_USER_CHUNKS_SUPPORTED)
/* png_unknown_chunk is a structure to hold queued chunks for which there is /* png_unknown_chunk is a structure to hold queued chunks for which there is
* no specific support. The idea is that we can use this to queue * no specific support. The idea is that we can use this to queue
* up private chunks for output even though the library doesn't actually * up private chunks for output even though the library doesn't actually

View File

@@ -240,7 +240,7 @@ png_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)
return; return;
if (png_ptr->mode & PNG_AFTER_IDAT) if (png_ptr->mode & PNG_AFTER_IDAT)
png_benign_error(png_ptr, "Too many IDATs found"); png_benign_error(png_ptr, "Too many IDATs found[p]");
} }
if (chunk_name == png_IHDR) if (chunk_name == png_IHDR)

View File

@@ -1334,7 +1334,7 @@ PNG_INTERNAL_FUNCTION(void,png_handle_zTXt,(png_structrp png_ptr,
PNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_structrp png_ptr,
png_uint_32 chunk_name),PNG_EMPTY); png_uint_32 chunk_name),PNG_EMPTY);
#ifdef PNG_READ_SUPPORTED #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr, PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr,
png_inforp info_ptr, png_uint_32 length, int keep),PNG_EMPTY); png_inforp info_ptr, png_uint_32 length, int keep),PNG_EMPTY);
/* This is the function that gets called for unknown chunks. The 'keep' /* This is the function that gets called for unknown chunks. The 'keep'
@@ -1343,16 +1343,15 @@ PNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr,
* just skips the chunk or errors out if it is critical. * just skips the chunk or errors out if it is critical.
*/ */
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) ||\
#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)
PNG_INTERNAL_FUNCTION(int,png_chunk_unknown_handling, PNG_INTERNAL_FUNCTION(int,png_chunk_unknown_handling,
(png_const_structrp png_ptr, png_uint_32 chunk_name),PNG_EMPTY); (png_const_structrp png_ptr, png_uint_32 chunk_name),PNG_EMPTY);
/* Exactly as the API png_handle_as_unknown() except that the argument is a /* Exactly as the API png_handle_as_unknown() except that the argument is a
* 32-bit chunk name, not a string. * 32-bit chunk name, not a string.
*/ */
#endif #endif /* READ_UNKNOWN_CHUNKS || HANDLE_AS_UNKNOWN */
#endif /* PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */ #endif /* PNG_SET_UNKNOWN_CHUNKS_SUPPORTED */
#endif /* PNG_READ_SUPPORTED */
/* Handle the transformations for reading and writing */ /* Handle the transformations for reading and writing */
#ifdef PNG_READ_TRANSFORMS_SUPPORTED #ifdef PNG_READ_TRANSFORMS_SUPPORTED

View File

@@ -121,7 +121,7 @@ png_read_info(png_structrp png_ptr, png_inforp info_ptr)
png_chunk_error(png_ptr, "Missing PLTE before IDAT"); png_chunk_error(png_ptr, "Missing PLTE before IDAT");
else if (png_ptr->mode & PNG_AFTER_IDAT) else if (png_ptr->mode & PNG_AFTER_IDAT)
png_chunk_benign_error(png_ptr, "Too many IDATs found"); png_chunk_benign_error(png_ptr, "Too many IDATs found[s]");
png_ptr->mode |= PNG_HAVE_IDAT; png_ptr->mode |= PNG_HAVE_IDAT;
} }
@@ -728,7 +728,7 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
if (chunk_name == png_IDAT) if (chunk_name == png_IDAT)
{ {
if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
png_benign_error(png_ptr, "Too many IDATs found"); png_benign_error(png_ptr, "Too many IDATs found(a1)");
} }
png_handle_unknown(png_ptr, info_ptr, length, keep); png_handle_unknown(png_ptr, info_ptr, length, keep);
if (chunk_name == png_PLTE) if (chunk_name == png_PLTE)
@@ -742,7 +742,7 @@ png_read_end(png_structrp png_ptr, png_inforp info_ptr)
* read, but not after other chunks have been read. * read, but not after other chunks have been read.
*/ */
if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT)) if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
png_benign_error(png_ptr, "Too many IDATs found"); png_benign_error(png_ptr, "Too many IDATs found(a2)");
png_crc_finish(png_ptr, length); png_crc_finish(png_ptr, length);
} }

View File

@@ -2792,19 +2792,26 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
if (ret < 0) if (ret < 0)
png_chunk_error(png_ptr, "error in user chunk"); png_chunk_error(png_ptr, "error in user chunk");
else if (ret > 0) /* chunk was handled */ else if (ret == 0)
{
/* Use the default handling, note that if there is per-chunk
* handling specified it has already been set into 'keep'.
*
* NOTE: this is an API change in 1.7.0, prior to 1.7.0 libpng
* would force keep to PNG_HANDLE_CHUNK_IF_SAFE at this point,
* and 1.6.0 would issue a warning if this caused a default of
* discarding the chunk to be changed.
*/
if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)
keep = png_ptr->unknown_default;
}
else /* chunk was handled */
{ {
handled = 1; handled = 1;
/* Critical chunks can be safely discarded at this point. */ /* Critical chunks can be safely discarded at this point. */
keep = PNG_HANDLE_CHUNK_NEVER; keep = PNG_HANDLE_CHUNK_NEVER;
} }
/* else: use the default handling.
* NOTE: this is an API change in 1.7.0, prior to 1.7.0 libpng would
* force keep to PNG_HANDLE_CHUNK_IF_SAFE at this point, and 1.6.0
* would issue a warning if this caused a default of discarding the
* chunk to be changed.
*/
} }
else else
@@ -2892,9 +2899,8 @@ png_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,
} }
# endif # endif
} }
# else /* no store support! */ # else /* no store support: the chunk must be handled by the user callback */
PNG_UNUSED(info_ptr) PNG_UNUSED(info_ptr)
# error untested code (reading unknown chunks with no store support)
# endif # endif
/* Regardless of the error handling below the cached data (if any) can be /* Regardless of the error handling below the cached data (if any) can be

View File

@@ -1387,11 +1387,13 @@ test_one_file(PNG_CONST char *inname, PNG_CONST char *outname)
} }
} }
#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED
# ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED # ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1); png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);
# endif # endif
# ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED # ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1); png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);
# endif
#endif #endif
pngtest_debug("Reading and writing end_info data"); pngtest_debug("Reading and writing end_info data");