[libpng16] Moved png_check_keyword() from pngwutil.c to pngset.c
This commit is contained in:
parent
f3da771890
commit
975cbbb029
5
ANNOUNCE
5
ANNOUNCE
@ -1,4 +1,4 @@
|
||||
Libpng 1.6.21beta02 - December 12, 2015
|
||||
Libpng 1.6.21beta02 - December 13, 2015
|
||||
|
||||
This is not intended to be a public release. It will be replaced
|
||||
within a few weeks by a public version or by another test version.
|
||||
@ -25,9 +25,10 @@ Other information:
|
||||
|
||||
Changes since the last public release (1.6.20):
|
||||
|
||||
Version 1.6.21beta01 [December 12, 2015]
|
||||
Version 1.6.21beta01 [December 13, 2015]
|
||||
Fixed syntax "$(command)" in tests/pngstest that some shells other than
|
||||
bash could not parse (Bug report by Nelson Beebe). Use `command` instead.
|
||||
Moved png_check_keyword() from pngwutil.c to pngset.c
|
||||
|
||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||
(subscription required; visit
|
||||
|
3
CHANGES
3
CHANGES
@ -5446,9 +5446,10 @@ Version 1.6.20rc02 [November 29, 2015]
|
||||
Version 1.6.20 [December 3, 2015]
|
||||
No changes.
|
||||
|
||||
Version 1.6.21beta01 [December 12, 2015]
|
||||
Version 1.6.21beta01 [December 13, 2015]
|
||||
Fixed syntax "$(command)" in tests/pngstest that some shells other than
|
||||
bash could not parse (Bug report by Nelson Beebe). Use `command` instead.
|
||||
Moved png_check_keyword() from pngwutil.c to pngset.c
|
||||
|
||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
|
||||
(subscription required; visit
|
||||
|
@ -2,7 +2,7 @@
|
||||
/* pngpriv.h - private declarations for use inside libpng
|
||||
*
|
||||
* Last changed in libpng 1.6.18 [July 23, 2015]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
@ -1917,6 +1917,9 @@ PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon,
|
||||
(png_structp png_ptr, unsigned int bpp), PNG_EMPTY);
|
||||
#endif
|
||||
|
||||
PNG_INTERNAL_FUNCTION(png_uint_32, png_check_keyword, (png_structrp png_ptr,
|
||||
png_const_charp key, png_bytep new_key), PNG_EMPTY);
|
||||
|
||||
/* Maintainer: Put new private prototypes here ^ */
|
||||
|
||||
#include "pngdebug.h"
|
||||
|
84
pngset.c
84
pngset.c
@ -1644,4 +1644,88 @@ png_set_check_for_invalid_index(png_structrp png_ptr, int allowed)
|
||||
png_ptr->num_palette_max = -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) || \
|
||||
defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
|
||||
/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification,
|
||||
* and if invalid, correct the keyword rather than discarding the entire
|
||||
* chunk. The PNG 1.0 specification requires keywords 1-79 characters in
|
||||
* length, forbids leading or trailing whitespace, multiple internal spaces,
|
||||
* and the non-break space (0x80) from ISO 8859-1. Returns keyword length.
|
||||
*
|
||||
* The 'new_key' buffer must be 80 characters in size (for the keyword plus a
|
||||
* trailing '\0'). If this routine returns 0 then there was no keyword, or a
|
||||
* valid one could not be generated, and the caller must png_error.
|
||||
*/
|
||||
png_uint_32 /* PRIVATE */
|
||||
png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)
|
||||
{
|
||||
png_const_charp orig_key = key;
|
||||
png_uint_32 key_len = 0;
|
||||
int bad_character = 0;
|
||||
int space = 1;
|
||||
|
||||
png_debug(1, "in png_check_keyword");
|
||||
|
||||
if (key == NULL)
|
||||
{
|
||||
*new_key = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (*key && key_len < 79)
|
||||
{
|
||||
png_byte ch = (png_byte)*key++;
|
||||
|
||||
if ((ch > 32 && ch <= 126) || (ch >= 161 /*&& ch <= 255*/))
|
||||
*new_key++ = ch, ++key_len, space = 0;
|
||||
|
||||
else if (space == 0)
|
||||
{
|
||||
/* A space or an invalid character when one wasn't seen immediately
|
||||
* before; output just a space.
|
||||
*/
|
||||
*new_key++ = 32, ++key_len, space = 1;
|
||||
|
||||
/* If the character was not a space then it is invalid. */
|
||||
if (ch != 32)
|
||||
bad_character = ch;
|
||||
}
|
||||
|
||||
else if (bad_character == 0)
|
||||
bad_character = ch; /* just skip it, record the first error */
|
||||
}
|
||||
|
||||
if (key_len > 0 && space != 0) /* trailing space */
|
||||
{
|
||||
--key_len, --new_key;
|
||||
if (bad_character == 0)
|
||||
bad_character = 32;
|
||||
}
|
||||
|
||||
/* Terminate the keyword */
|
||||
*new_key = 0;
|
||||
|
||||
if (key_len == 0)
|
||||
return 0;
|
||||
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
/* Try to only output one warning per keyword: */
|
||||
if (*key != 0) /* keyword too long */
|
||||
png_warning(png_ptr, "keyword truncated");
|
||||
|
||||
else if (bad_character != 0)
|
||||
{
|
||||
PNG_WARNING_PARAMETERS(p)
|
||||
|
||||
png_warning_parameter(p, 1, orig_key);
|
||||
png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_02x, bad_character);
|
||||
|
||||
png_formatted_warning(png_ptr, p, "keyword \"@1\": bad character '0x@2'");
|
||||
}
|
||||
#endif /* WARNINGS */
|
||||
|
||||
return key_len;
|
||||
}
|
||||
#endif /* TEXT || pCAL || iCCP || sPLT */
|
||||
#endif /* READ || WRITE */
|
||||
|
86
pngwutil.c
86
pngwutil.c
@ -2,7 +2,7 @@
|
||||
/* pngwutil.c - utilities to write a PNG file
|
||||
*
|
||||
* Last changed in libpng 1.6.19 [November 12, 2015]
|
||||
* Copyright (c) 1998-2015 Glenn Randers-Pehrson
|
||||
* Copyright (c) 1998-2002,2004,2006-2015 Glenn Randers-Pehrson
|
||||
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
||||
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
||||
*
|
||||
@ -665,90 +665,6 @@ png_write_compressed_data_out(png_structrp png_ptr, compression_state *comp)
|
||||
}
|
||||
#endif /* WRITE_COMPRESSED_TEXT */
|
||||
|
||||
#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
|
||||
defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
|
||||
/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification,
|
||||
* and if invalid, correct the keyword rather than discarding the entire
|
||||
* chunk. The PNG 1.0 specification requires keywords 1-79 characters in
|
||||
* length, forbids leading or trailing whitespace, multiple internal spaces,
|
||||
* and the non-break space (0x80) from ISO 8859-1. Returns keyword length.
|
||||
*
|
||||
* The 'new_key' buffer must be 80 characters in size (for the keyword plus a
|
||||
* trailing '\0'). If this routine returns 0 then there was no keyword, or a
|
||||
* valid one could not be generated, and the caller must png_error.
|
||||
*/
|
||||
static png_uint_32
|
||||
png_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)
|
||||
{
|
||||
png_const_charp orig_key = key;
|
||||
png_uint_32 key_len = 0;
|
||||
int bad_character = 0;
|
||||
int space = 1;
|
||||
|
||||
png_debug(1, "in png_check_keyword");
|
||||
|
||||
if (key == NULL)
|
||||
{
|
||||
*new_key = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (*key && key_len < 79)
|
||||
{
|
||||
png_byte ch = (png_byte)*key++;
|
||||
|
||||
if ((ch > 32 && ch <= 126) || (ch >= 161 /*&& ch <= 255*/))
|
||||
*new_key++ = ch, ++key_len, space = 0;
|
||||
|
||||
else if (space == 0)
|
||||
{
|
||||
/* A space or an invalid character when one wasn't seen immediately
|
||||
* before; output just a space.
|
||||
*/
|
||||
*new_key++ = 32, ++key_len, space = 1;
|
||||
|
||||
/* If the character was not a space then it is invalid. */
|
||||
if (ch != 32)
|
||||
bad_character = ch;
|
||||
}
|
||||
|
||||
else if (bad_character == 0)
|
||||
bad_character = ch; /* just skip it, record the first error */
|
||||
}
|
||||
|
||||
if (key_len > 0 && space != 0) /* trailing space */
|
||||
{
|
||||
--key_len, --new_key;
|
||||
if (bad_character == 0)
|
||||
bad_character = 32;
|
||||
}
|
||||
|
||||
/* Terminate the keyword */
|
||||
*new_key = 0;
|
||||
|
||||
if (key_len == 0)
|
||||
return 0;
|
||||
|
||||
#ifdef PNG_WARNINGS_SUPPORTED
|
||||
/* Try to only output one warning per keyword: */
|
||||
if (*key != 0) /* keyword too long */
|
||||
png_warning(png_ptr, "keyword truncated");
|
||||
|
||||
else if (bad_character != 0)
|
||||
{
|
||||
PNG_WARNING_PARAMETERS(p)
|
||||
|
||||
png_warning_parameter(p, 1, orig_key);
|
||||
png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_02x, bad_character);
|
||||
|
||||
png_formatted_warning(png_ptr, p, "keyword \"@1\": bad character '0x@2'");
|
||||
}
|
||||
#endif /* WARNINGS */
|
||||
|
||||
return key_len;
|
||||
}
|
||||
#endif /* WRITE_TEXT || WRITE_pCAL || WRITE_iCCP || WRITE_sPLT */
|
||||
|
||||
/* Write the IHDR chunk, and update the png_struct with the necessary
|
||||
* information. Note that the rest of this code depends upon this
|
||||
* information being correct.
|
||||
|
Loading…
Reference in New Issue
Block a user