mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
Imported from pngcrush-1.3.0.tar
This commit is contained in:
313
pngrutil.c
313
pngrutil.c
@@ -1,7 +1,7 @@
|
||||
|
||||
/* pngrutil.c - utilities to read a PNG file
|
||||
*
|
||||
* libpng 1.0.5f - December 6, 1999
|
||||
* libpng 1.0.5j - December 21, 1999
|
||||
* For conditions of distribution and use, see copyright notice in png.h
|
||||
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
* Copyright (c) 1996, 1997 Andreas Dilger
|
||||
@@ -145,7 +145,7 @@ png_crc_error(png_structp png_ptr)
|
||||
* holding the original prefix part and an uncompressed version of the
|
||||
* trailing part (the malloc area passed in is freed).
|
||||
*/
|
||||
png_charp png_decompress_chunk(png_structp png_ptr, int comp_type,
|
||||
png_charp png_decompress_chunk(png_structp png_ptr, int comp_type,
|
||||
png_charp chunkdata, png_size_t chunklength,
|
||||
png_size_t prefix_size)
|
||||
{
|
||||
@@ -196,7 +196,7 @@ png_charp png_decompress_chunk(png_structp png_ptr, int comp_type,
|
||||
{
|
||||
if (text == NULL)
|
||||
{
|
||||
text_size = prefix_size +
|
||||
text_size = prefix_size +
|
||||
png_ptr->zbuf_size - png_ptr->zstream.avail_out;
|
||||
text = (png_charp)png_malloc(png_ptr, text_size + 1);
|
||||
png_memcpy(text + prefix_size, png_ptr->zbuf,
|
||||
@@ -236,7 +236,6 @@ png_charp png_decompress_chunk(png_structp png_ptr, int comp_type,
|
||||
}
|
||||
else /* if (comp_type >= PNG_TEXT_COMPRESSION_LAST) */
|
||||
{
|
||||
png_size_t text_size;
|
||||
#if !defined(PNG_NO_STDIO)
|
||||
char umsg[50];
|
||||
|
||||
@@ -496,8 +495,10 @@ png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
void
|
||||
png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
png_uint_32 igamma;
|
||||
png_fixed_point igamma;
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
float file_gamma;
|
||||
#endif
|
||||
png_byte buf[4];
|
||||
|
||||
png_debug(1, "in png_handle_gAMA\n");
|
||||
@@ -536,14 +537,14 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
if (png_crc_finish(png_ptr, 0))
|
||||
return;
|
||||
|
||||
igamma = png_get_uint_32(buf);
|
||||
igamma = (png_fixed_point)png_get_uint_32(buf);
|
||||
/* check for zero gamma */
|
||||
if (igamma == 0)
|
||||
return;
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_sRGB)
|
||||
if(fabs((float)igamma - 45455.)>500.)
|
||||
if(igamma < 45000L || igamma > 46000L)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect gAMA value when sRGB is also present");
|
||||
@@ -554,11 +555,16 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
}
|
||||
#endif /* PNG_READ_sRGB_SUPPORTED */
|
||||
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
file_gamma = (float)igamma / (float)100000.0;
|
||||
#ifdef PNG_READ_GAMMA_SUPPORTED
|
||||
png_ptr->gamma = file_gamma;
|
||||
#endif
|
||||
png_set_gAMA(png_ptr, info_ptr, file_gamma);
|
||||
#endif
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -633,8 +639,11 @@ void
|
||||
png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
png_byte buf[4];
|
||||
png_uint_32 val;
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
|
||||
#endif
|
||||
png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
|
||||
int_y_green, int_x_blue, int_y_blue;
|
||||
|
||||
png_debug(1, "in png_handle_cHRM\n");
|
||||
|
||||
@@ -669,15 +678,13 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
}
|
||||
|
||||
png_crc_read(png_ptr, buf, 4);
|
||||
val = png_get_uint_32(buf);
|
||||
white_x = (float)val / (float)100000.0;
|
||||
int_x_white = (png_fixed_point)png_get_uint_32(buf);
|
||||
|
||||
png_crc_read(png_ptr, buf, 4);
|
||||
val = png_get_uint_32(buf);
|
||||
white_y = (float)val / (float)100000.0;
|
||||
int_y_white = (png_fixed_point)png_get_uint_32(buf);
|
||||
|
||||
if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
|
||||
white_x + white_y > 1.0)
|
||||
if (int_x_white > 80000L || int_y_white > 80000L ||
|
||||
int_x_white + int_y_white > 100000L)
|
||||
{
|
||||
png_warning(png_ptr, "Invalid cHRM white point");
|
||||
png_crc_finish(png_ptr, 24);
|
||||
@@ -685,15 +692,13 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
}
|
||||
|
||||
png_crc_read(png_ptr, buf, 4);
|
||||
val = png_get_uint_32(buf);
|
||||
red_x = (float)val / (float)100000.0;
|
||||
int_x_red = (png_fixed_point)png_get_uint_32(buf);
|
||||
|
||||
png_crc_read(png_ptr, buf, 4);
|
||||
val = png_get_uint_32(buf);
|
||||
red_y = (float)val / (float)100000.0;
|
||||
int_y_red = (png_fixed_point)png_get_uint_32(buf);
|
||||
|
||||
if (red_x < 0 || red_x > 0.8 || red_y < 0 || red_y > 0.8 ||
|
||||
red_x + red_y > 1.0)
|
||||
if (int_x_red > 80000L || int_y_red > 80000L ||
|
||||
int_x_red + int_y_red > 100000L)
|
||||
{
|
||||
png_warning(png_ptr, "Invalid cHRM red point");
|
||||
png_crc_finish(png_ptr, 16);
|
||||
@@ -701,15 +706,13 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
}
|
||||
|
||||
png_crc_read(png_ptr, buf, 4);
|
||||
val = png_get_uint_32(buf);
|
||||
green_x = (float)val / (float)100000.0;
|
||||
int_x_green = (png_fixed_point)png_get_uint_32(buf);
|
||||
|
||||
png_crc_read(png_ptr, buf, 4);
|
||||
val = png_get_uint_32(buf);
|
||||
green_y = (float)val / (float)100000.0;
|
||||
int_y_green = (png_fixed_point)png_get_uint_32(buf);
|
||||
|
||||
if (green_x < 0 || green_x > 0.8 || green_y < 0 || green_y > 0.8 ||
|
||||
green_x + green_y > 1.0)
|
||||
if (int_x_green > 80000L || int_y_green > 80000L ||
|
||||
int_x_green + int_y_green > 100000L)
|
||||
{
|
||||
png_warning(png_ptr, "Invalid cHRM green point");
|
||||
png_crc_finish(png_ptr, 8);
|
||||
@@ -717,52 +720,74 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
}
|
||||
|
||||
png_crc_read(png_ptr, buf, 4);
|
||||
val = png_get_uint_32(buf);
|
||||
blue_x = (float)val / (float)100000.0;
|
||||
int_x_blue = (png_fixed_point)png_get_uint_32(buf);
|
||||
|
||||
png_crc_read(png_ptr, buf, 4);
|
||||
val = png_get_uint_32(buf);
|
||||
blue_y = (float)val / (float)100000.0;
|
||||
int_y_blue = (png_fixed_point)png_get_uint_32(buf);
|
||||
|
||||
if (blue_x < (float)0 || blue_x > (float)0.8 || blue_y < (float)0 ||
|
||||
blue_y > (float)0.8 || blue_x + blue_y > (float)1.0)
|
||||
if (int_x_blue > 80000L || int_y_blue > 80000L ||
|
||||
int_x_blue + int_y_blue > 100000L)
|
||||
{
|
||||
png_warning(png_ptr, "Invalid cHRM blue point");
|
||||
png_crc_finish(png_ptr, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (png_crc_finish(png_ptr, 0))
|
||||
return;
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
white_x = (float)int_x_white / (float)100000.0;
|
||||
white_y = (float)int_y_white / (float)100000.0;
|
||||
red_x = (float)int_x_red / (float)100000.0;
|
||||
red_y = (float)int_y_red / (float)100000.0;
|
||||
green_x = (float)int_x_green / (float)100000.0;
|
||||
green_y = (float)int_y_green / (float)100000.0;
|
||||
blue_x = (float)int_x_blue / (float)100000.0;
|
||||
blue_y = (float)int_y_blue / (float)100000.0;
|
||||
#endif
|
||||
|
||||
#if defined(PNG_READ_sRGB_SUPPORTED)
|
||||
if (info_ptr->valid & PNG_INFO_sRGB)
|
||||
{
|
||||
if (fabs(white_x - (float).3127) > (float).001 ||
|
||||
fabs(white_y - (float).3290) > (float).001 ||
|
||||
fabs( red_x - (float).6400) > (float).001 ||
|
||||
fabs( red_y - (float).3300) > (float).001 ||
|
||||
fabs(green_x - (float).3000) > (float).001 ||
|
||||
fabs(green_y - (float).6000) > (float).001 ||
|
||||
fabs( blue_x - (float).1500) > (float).001 ||
|
||||
fabs( blue_y - (float).0600) > (float).001)
|
||||
if (abs(int_x_white - 31270L) > 1000 ||
|
||||
abs(int_y_white - 32900L) > 1000 ||
|
||||
abs( int_x_red - 64000L) > 1000 ||
|
||||
abs( int_y_red - 33000L) > 1000 ||
|
||||
abs(int_x_green - 30000L) > 1000 ||
|
||||
abs(int_y_green - 60000L) > 1000 ||
|
||||
abs( int_x_blue - 15000L) > 1000 ||
|
||||
abs( int_y_blue - 6000L) > 1000)
|
||||
{
|
||||
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect cHRM value when sRGB is also present");
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
|
||||
white_x, white_y, red_x, red_y);
|
||||
fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
|
||||
green_x, green_y, blue_x, blue_y);
|
||||
#else
|
||||
fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
|
||||
int_x_white, int_y_white, int_x_red, int_y_red);
|
||||
fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
|
||||
int_x_green, int_y_green, int_x_blue, int_y_blue);
|
||||
#endif
|
||||
#endif /* PNG_NO_CONSOLE_IO */
|
||||
}
|
||||
png_crc_finish(png_ptr, 0);
|
||||
return;
|
||||
}
|
||||
#endif /* PNG_READ_sRGB_SUPPORTED */
|
||||
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_set_cHRM(png_ptr, info_ptr,
|
||||
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
|
||||
#endif
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_set_cHRM_fixed(png_ptr, info_ptr,
|
||||
int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
|
||||
int_y_green, int_x_blue, int_y_blue);
|
||||
#endif
|
||||
if (png_crc_finish(png_ptr, 0))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -771,6 +796,9 @@ void
|
||||
png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
int intent;
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
int igamma;
|
||||
#endif
|
||||
png_byte buf[1];
|
||||
|
||||
png_debug(1, "in png_handle_sRGB\n");
|
||||
@@ -814,27 +842,38 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
}
|
||||
|
||||
#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
igamma=png_ptr->gamma * 100000.;
|
||||
#else
|
||||
# ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
igamma=(int)png_ptr->int_gamma;
|
||||
# endif
|
||||
#endif
|
||||
if ((info_ptr->valid & PNG_INFO_gAMA))
|
||||
if(fabs((png_ptr->gamma*(float)100000.+.5)-45455.) > 500.)
|
||||
if(igamma < 45000L || igamma > 46000L)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect gAMA value when sRGB is also present");
|
||||
#ifndef PNG_NO_CONSOLE_IO
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
fprintf(stderr,"gamma=%f\n",png_ptr->gamma);
|
||||
#else
|
||||
fprintf(stderr,"gamma=(%lu/100000)\n",png_ptr->int_gamma);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif /* PNG_READ_gAMA_SUPPORTED */
|
||||
|
||||
#ifdef PNG_READ_cHRM_SUPPORTED
|
||||
if (info_ptr->valid & PNG_INFO_cHRM)
|
||||
if (fabs(info_ptr->x_white - (float).3127) > (float).001 ||
|
||||
fabs(info_ptr->y_white - (float).3290) > (float).001 ||
|
||||
fabs( info_ptr->x_red - (float).6400) > (float).001 ||
|
||||
fabs( info_ptr->y_red - (float).3300) > (float).001 ||
|
||||
fabs(info_ptr->x_green - (float).3000) > (float).001 ||
|
||||
fabs(info_ptr->y_green - (float).6000) > (float).001 ||
|
||||
fabs( info_ptr->x_blue - (float).1500) > (float).001 ||
|
||||
fabs( info_ptr->y_blue - (float).0600) > (float).001)
|
||||
if (abs(info_ptr->int_x_white - 31270L) > 1000 ||
|
||||
abs(info_ptr->int_y_white - 32900L) > 1000 ||
|
||||
abs( info_ptr->int_x_red - 64000L) > 1000 ||
|
||||
abs( info_ptr->int_y_red - 33000L) > 1000 ||
|
||||
abs(info_ptr->int_x_green - 30000L) > 1000 ||
|
||||
abs(info_ptr->int_y_green - 60000L) > 1000 ||
|
||||
abs( info_ptr->int_x_blue - 15000L) > 1000 ||
|
||||
abs( info_ptr->int_y_blue - 6000L) > 1000)
|
||||
{
|
||||
png_warning(png_ptr,
|
||||
"Ignoring incorrect cHRM value when sRGB is also present");
|
||||
@@ -851,7 +890,7 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
/* Note: this does not properly handle chunks that are > 64K under DOS */
|
||||
{
|
||||
png_charp chunkdata;
|
||||
png_byte compression_type;
|
||||
png_byte compression_type;
|
||||
png_charp profile;
|
||||
png_uint_32 skip = 0;
|
||||
png_size_t slength, prefix_length;
|
||||
@@ -1480,8 +1519,15 @@ png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
void
|
||||
png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
png_charp unit, ep, vp;
|
||||
double width, height;
|
||||
png_charp buffer, ep;
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
double width=0., height=0.;
|
||||
png_charp vp;
|
||||
#else
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_charp swidth, sheight;
|
||||
#endif
|
||||
#endif
|
||||
png_size_t slength;
|
||||
|
||||
png_debug(1, "in png_handle_sCAL\n");
|
||||
@@ -1503,46 +1549,75 @@ png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
|
||||
png_debug1(2, "Allocating and reading sCAL chunk data (%d bytes)\n",
|
||||
length + 1);
|
||||
unit = (png_charp)png_malloc(png_ptr, length + 1);
|
||||
buffer = (png_charp)png_malloc(png_ptr, length + 1);
|
||||
slength = (png_size_t)length;
|
||||
png_crc_read(png_ptr, (png_bytep)unit, slength);
|
||||
png_crc_read(png_ptr, (png_bytep)buffer, slength);
|
||||
|
||||
if (png_crc_finish(png_ptr, 0))
|
||||
{
|
||||
png_free(png_ptr, unit);
|
||||
png_free(png_ptr, buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
unit[slength] = 0x00; /* null terminate the last string */
|
||||
buffer[slength] = 0x00; /* null terminate the last string */
|
||||
|
||||
png_debug(3, "Finding end of sCAL unit string\n");
|
||||
for (ep = unit; *ep; ep++)
|
||||
/* empty loop */ ;
|
||||
ep++;
|
||||
ep = buffer + 1; /* skip unit byte */
|
||||
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
width = strtod(ep, &vp);
|
||||
if (*vp)
|
||||
png_error(png_ptr, "malformed width string in sCAL chunk");
|
||||
#else
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
swidth = (png_charp)png_malloc(png_ptr, strlen(ep) + 1);
|
||||
png_memcpy(swidth, ep, (png_size_t)strlen(ep));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
for (ep = unit; *ep; ep++)
|
||||
for (ep = buffer; *ep; ep++)
|
||||
/* empty loop */ ;
|
||||
ep++;
|
||||
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
height = strtod(ep, &vp);
|
||||
if (*vp)
|
||||
png_error(png_ptr, "malformed height string in sCAL chunk");
|
||||
#else
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
sheight = (png_charp)png_malloc(png_ptr, strlen(ep) + 1);
|
||||
png_memcpy(sheight, ep, (png_size_t)strlen(ep));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (unit + slength < ep || width <= 0. || height <= 0.)
|
||||
if (buffer + slength < ep
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
|| width <= 0. || height <= 0.
|
||||
#endif
|
||||
)
|
||||
{
|
||||
png_warning(png_ptr, "Invalid sCAL data");
|
||||
png_free(png_ptr, unit);
|
||||
png_free(png_ptr, buffer);
|
||||
#if defined(PNG_FIXED_POINT_SUPPORTED)&& !defined(PNG_FLOATING_POINT_SUPPORTED)
|
||||
png_free(png_ptr, swidth);
|
||||
png_free(png_ptr, sheight);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
png_set_sCAL(png_ptr, info_ptr, unit, width, height);
|
||||
#ifdef PNG_FLOATING_POINT_SUPPORTED
|
||||
png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
|
||||
#else
|
||||
#ifdef PNG_FIXED_POINT_SUPPORTED
|
||||
png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
png_free(png_ptr, unit);
|
||||
png_free(png_ptr, buffer);
|
||||
#if defined(PNG_FIXED_POINT_SUPPORTED)&& !defined(PNG_FLOATING_POINT_SUPPORTED)
|
||||
png_free(png_ptr, swidth);
|
||||
png_free(png_ptr, sheight);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1637,9 +1712,12 @@ png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
|
||||
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
|
||||
text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
text_ptr->lang = NULL;
|
||||
text_ptr->key = key;
|
||||
text_ptr->lang = NULL;
|
||||
text_ptr->lang_key = NULL;
|
||||
text_ptr->text = text;
|
||||
text_ptr->text_length = png_strlen(text);
|
||||
text_ptr->itxt_length = 0;
|
||||
|
||||
png_set_text(png_ptr, info_ptr, text_ptr, 1);
|
||||
|
||||
@@ -1700,7 +1778,7 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
else
|
||||
{
|
||||
comp_type = *(++text);
|
||||
text++; /* skip the compression byte */
|
||||
text++; /* skip the compression_method byte */
|
||||
}
|
||||
prefix_len = text - chunkdata;
|
||||
|
||||
@@ -1711,7 +1789,10 @@ png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
text_ptr->compression = comp_type;
|
||||
text_ptr->lang = NULL;
|
||||
text_ptr->key = chunkdata;
|
||||
text_ptr->lang_key = NULL;
|
||||
text_ptr->text = chunkdata + prefix_len;
|
||||
text_ptr->text_length = png_strlen(text);
|
||||
text_ptr->itxt_length = 0;
|
||||
|
||||
png_set_text(png_ptr, info_ptr, text_ptr, 1);
|
||||
|
||||
@@ -1727,9 +1808,9 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
png_textp text_ptr;
|
||||
png_charp chunkdata;
|
||||
png_charp lang, text;
|
||||
int comp_type = PNG_TEXT_COMPRESSION_NONE;
|
||||
int comp_flag = 0;
|
||||
png_charp key, lang, text, lang_key;
|
||||
int comp_flag = PNG_TEXT_COMPRESSION_NONE;
|
||||
int comp_type = 0;
|
||||
png_size_t slength, prefix_len;
|
||||
|
||||
png_debug(1, "in png_handle_iTXt\n");
|
||||
@@ -1766,10 +1847,13 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
/* empty loop */ ;
|
||||
lang++; /* skip NUL separator */
|
||||
|
||||
/* iTXt must have a language tag and some text after the keyword */
|
||||
/* iTXt must have a language tag (possibly empty), two compression bytes,
|
||||
translated keyword (possibly empty), and possibly some text after the
|
||||
keyword */
|
||||
|
||||
if (lang >= chunkdata + slength)
|
||||
{
|
||||
comp_type = PNG_TEXT_COMPRESSION_NONE;
|
||||
comp_flag = PNG_TEXT_COMPRESSION_NONE;
|
||||
png_warning(png_ptr, "Zero length iTXt chunk");
|
||||
}
|
||||
else
|
||||
@@ -1778,25 +1862,31 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
comp_type = *lang++;
|
||||
}
|
||||
|
||||
for (text = lang; *text; text++)
|
||||
for (lang_key = lang; *lang_key; lang_key++)
|
||||
/* empty loop */ ;
|
||||
lang_key++; /* skip NUL separator */
|
||||
|
||||
for (text = lang_key; *text; text++)
|
||||
/* empty loop */ ;
|
||||
text++; /* skip NUL separator */
|
||||
|
||||
prefix_len = text - chunkdata;
|
||||
|
||||
key=chunkdata;
|
||||
if (comp_flag)
|
||||
chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
|
||||
(size_t)length, prefix_len);
|
||||
|
||||
(size_t)length, prefix_len);
|
||||
text_ptr = (png_textp)png_malloc(png_ptr, (png_uint_32)sizeof(png_text));
|
||||
text_ptr->compression = (png_byte)comp_type;
|
||||
text_ptr->lang = NULL;
|
||||
text_ptr->compression = (int)comp_flag + 1;
|
||||
text_ptr->lang_key = chunkdata+(lang_key-key);
|
||||
text_ptr->lang = chunkdata+(lang-key);
|
||||
text_ptr->key = chunkdata;
|
||||
text_ptr->text = chunkdata + prefix_len;
|
||||
text_ptr->text_length = 0;
|
||||
text_ptr->itxt_length = png_strlen(text_ptr->text);
|
||||
|
||||
png_set_text(png_ptr, info_ptr, text_ptr, 1);
|
||||
|
||||
png_free(png_ptr, text_ptr->key);
|
||||
png_free(png_ptr, text_ptr);
|
||||
png_free(png_ptr, chunkdata);
|
||||
}
|
||||
@@ -1804,12 +1894,19 @@ png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
|
||||
/* This function is called when we haven't found a handler for a
|
||||
chunk. If there isn't a problem with the chunk itself (ie bad
|
||||
chunk name, CRC, or a critical chunk), the chunk is silently ignored. */
|
||||
chunk name, CRC, or a critical chunk), the chunk is silently ignored
|
||||
-- unless the PNG_FLAG_UNKNOWN_CHUNKS_SUPPORTED flag is on in which
|
||||
case it will be saved away to be written out later. */
|
||||
void
|
||||
png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
{
|
||||
png_uint_32 skip = 0;
|
||||
|
||||
png_debug(1, "in png_handle_unknown\n");
|
||||
|
||||
if (png_ptr->mode & PNG_HAVE_IDAT)
|
||||
png_ptr->mode |= PNG_AFTER_IDAT;
|
||||
|
||||
/* In the future we can have code here that calls user-supplied
|
||||
* callback functions for unknown chunks before they are ignored or
|
||||
* cause an error.
|
||||
@@ -1825,11 +1922,33 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
|
||||
return;
|
||||
}
|
||||
|
||||
if (png_ptr->mode & PNG_HAVE_IDAT)
|
||||
png_ptr->mode |= PNG_AFTER_IDAT;
|
||||
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
|
||||
if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
|
||||
{
|
||||
png_unknown_chunk chunk;
|
||||
|
||||
png_crc_finish(png_ptr, length);
|
||||
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
if (length > (png_uint_32)65535L)
|
||||
{
|
||||
png_warning(png_ptr, "unknown chunk too large to fit in memory");
|
||||
skip = length - (png_uint_32)65535L;
|
||||
length = (png_uint_32)65535L;
|
||||
}
|
||||
#endif
|
||||
|
||||
strcpy((png_charp)chunk.name, (png_charp)png_ptr->chunk_name);
|
||||
chunk.data = (png_bytep)png_malloc(png_ptr, length);
|
||||
png_crc_read(png_ptr, chunk.data, length);
|
||||
chunk.size = length;
|
||||
png_set_unknown_chunks(png_ptr, info_ptr, &chunk, 1);
|
||||
png_free(png_ptr, chunk.data);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
skip = length;
|
||||
|
||||
png_crc_finish(png_ptr, skip);
|
||||
}
|
||||
|
||||
/* This function is called to verify that a chunk name is valid.
|
||||
@@ -2080,11 +2199,11 @@ png_do_read_interlace
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
|
||||
/* offset to next interlace block */
|
||||
const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||
#endif
|
||||
|
||||
|
||||
png_debug(1,"in png_do_read_interlace\n");
|
||||
if (row != NULL && row_info != NULL)
|
||||
{
|
||||
@@ -2425,20 +2544,20 @@ png_read_finish_row(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
|
||||
/* start of interlace block */
|
||||
const int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
||||
|
||||
|
||||
/* offset to next interlace block */
|
||||
const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||
|
||||
|
||||
/* start of interlace block in the y direction */
|
||||
const int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
|
||||
|
||||
|
||||
/* offset to next interlace block in the y direction */
|
||||
const int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
||||
#endif
|
||||
|
||||
|
||||
png_debug(1, "in png_read_finish_row\n");
|
||||
png_ptr->row_number++;
|
||||
if (png_ptr->row_number < png_ptr->num_rows)
|
||||
@@ -2547,20 +2666,20 @@ png_read_start_row(png_structp png_ptr)
|
||||
{
|
||||
#ifdef PNG_USE_LOCAL_ARRAYS
|
||||
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
|
||||
|
||||
|
||||
/* start of interlace block */
|
||||
const int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
|
||||
|
||||
|
||||
/* offset to next interlace block */
|
||||
const int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
|
||||
|
||||
|
||||
/* start of interlace block in the y direction */
|
||||
const int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
|
||||
|
||||
|
||||
/* offset to next interlace block in the y direction */
|
||||
const int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
|
||||
#endif
|
||||
|
||||
|
||||
int max_pixel_depth;
|
||||
png_uint_32 row_bytes;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user