mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
Imported from libpng-0.96.tar
This commit is contained in:
committed by
Glenn Randers-Pehrson
parent
02ad0efbc8
commit
47a0c422ca
286
pngpread.c
286
pngpread.c
@@ -1,10 +1,11 @@
|
||||
|
||||
/* pngpread.c - read a png file in push mode
|
||||
|
||||
libpng 1.0 beta 4 - version 0.90
|
||||
libpng 1.0 beta 6 - version 0.96
|
||||
For conditions of distribution and use, see copyright notice in png.h
|
||||
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
|
||||
January 10, 1997
|
||||
Copyright (c) 1996, 1997 Andreas Dilger
|
||||
May 12, 1997
|
||||
*/
|
||||
|
||||
#define PNG_INTERNAL
|
||||
@@ -14,7 +15,7 @@
|
||||
|
||||
void
|
||||
png_process_data(png_structp png_ptr, png_infop info_ptr,
|
||||
png_bytep buffer, png_uint_32 buffer_size)
|
||||
png_bytep buffer, png_size_t buffer_size)
|
||||
{
|
||||
png_push_restore_buffer(png_ptr, buffer, buffer_size);
|
||||
|
||||
@@ -61,14 +62,9 @@ png_process_some_data(png_structp png_ptr, png_infop info_ptr)
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
case PNG_READ_END_MODE:
|
||||
{
|
||||
png_push_read_chunk(png_ptr, info_ptr);
|
||||
break;
|
||||
}
|
||||
case PNG_SKIP_MODE:
|
||||
{
|
||||
png_push_skip(png_ptr);
|
||||
png_push_crc_finish(png_ptr);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -87,8 +83,8 @@ png_process_some_data(png_structp png_ptr, png_infop info_ptr)
|
||||
void
|
||||
png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
int num_checked = png_ptr->sig_bytes,
|
||||
num_to_check = 8 - num_checked;
|
||||
png_size_t num_checked = png_ptr->sig_bytes,
|
||||
num_to_check = 8 - num_checked;
|
||||
|
||||
if (png_ptr->buffer_size < num_to_check)
|
||||
{
|
||||
@@ -96,7 +92,7 @@ png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
|
||||
(png_uint_32)num_to_check);
|
||||
num_to_check);
|
||||
png_ptr->sig_bytes += num_to_check;
|
||||
|
||||
if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
|
||||
@@ -137,8 +133,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
png_push_fill_buffer(png_ptr, chunk_length, 4);
|
||||
png_ptr->push_length = png_get_uint_32(chunk_length);
|
||||
png_reset_crc(png_ptr);
|
||||
png_push_fill_buffer(png_ptr, png_ptr->chunk_name, 4);
|
||||
png_calculate_crc(png_ptr, png_ptr->chunk_name, 4);
|
||||
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
|
||||
png_ptr->flags |= PNG_FLAG_HAVE_CHUNK_HEADER;
|
||||
}
|
||||
|
||||
@@ -292,6 +287,18 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_pCAL_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
|
||||
{
|
||||
if (png_ptr->push_length + 4 > png_ptr->buffer_size)
|
||||
{
|
||||
png_push_save_buffer(png_ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
|
||||
}
|
||||
#endif
|
||||
#if defined(PNG_READ_tIME_SUPPORTED)
|
||||
else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
|
||||
{
|
||||
@@ -325,21 +332,21 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
|
||||
}
|
||||
|
||||
void
|
||||
png_push_crc_skip(png_structp png_ptr, png_uint_32 length)
|
||||
png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
|
||||
{
|
||||
png_ptr->process_mode = PNG_SKIP_MODE;
|
||||
png_ptr->skip_length = length;
|
||||
png_ptr->skip_length = skip;
|
||||
}
|
||||
|
||||
void
|
||||
png_push_skip(png_structp png_ptr)
|
||||
png_push_crc_finish(png_structp png_ptr)
|
||||
{
|
||||
if (png_ptr->skip_length && png_ptr->save_buffer_size)
|
||||
{
|
||||
png_uint_32 save_size;
|
||||
png_size_t save_size;
|
||||
|
||||
if (png_ptr->skip_length < png_ptr->save_buffer_size)
|
||||
save_size = png_ptr->skip_length;
|
||||
if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
|
||||
save_size = (png_size_t)png_ptr->skip_length;
|
||||
else
|
||||
save_size = png_ptr->save_buffer_size;
|
||||
|
||||
@@ -348,14 +355,14 @@ png_push_skip(png_structp png_ptr)
|
||||
png_ptr->skip_length -= save_size;
|
||||
png_ptr->buffer_size -= save_size;
|
||||
png_ptr->save_buffer_size -= save_size;
|
||||
png_ptr->save_buffer_ptr += (png_size_t)save_size;
|
||||
png_ptr->save_buffer_ptr += save_size;
|
||||
}
|
||||
if (png_ptr->skip_length && png_ptr->current_buffer_size)
|
||||
{
|
||||
png_uint_32 save_size;
|
||||
png_size_t save_size;
|
||||
|
||||
if (png_ptr->skip_length < png_ptr->current_buffer_size)
|
||||
save_size = png_ptr->skip_length;
|
||||
if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
|
||||
save_size = (png_size_t)png_ptr->skip_length;
|
||||
else
|
||||
save_size = png_ptr->current_buffer_size;
|
||||
|
||||
@@ -364,7 +371,7 @@ png_push_skip(png_structp png_ptr)
|
||||
png_ptr->skip_length -= save_size;
|
||||
png_ptr->buffer_size -= save_size;
|
||||
png_ptr->current_buffer_size -= save_size;
|
||||
png_ptr->current_buffer_ptr += (png_size_t)save_size;
|
||||
png_ptr->current_buffer_ptr += save_size;
|
||||
}
|
||||
if (!png_ptr->skip_length)
|
||||
{
|
||||
@@ -375,50 +382,45 @@ png_push_skip(png_structp png_ptr)
|
||||
}
|
||||
|
||||
png_crc_finish(png_ptr, 0);
|
||||
|
||||
if (png_ptr->mode & PNG_AFTER_IDAT)
|
||||
png_ptr->process_mode = PNG_READ_END_MODE;
|
||||
else
|
||||
png_ptr->process_mode = PNG_READ_CHUNK_MODE;
|
||||
png_ptr->process_mode = PNG_READ_CHUNK_MODE;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
png_push_fill_buffer(png_structp png_ptr, png_bytep buffer,
|
||||
png_uint_32 length)
|
||||
png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
|
||||
{
|
||||
png_bytep ptr;
|
||||
|
||||
ptr = buffer;
|
||||
if (png_ptr->save_buffer_size)
|
||||
{
|
||||
png_uint_32 save_size;
|
||||
png_size_t save_size;
|
||||
|
||||
if (length < png_ptr->save_buffer_size)
|
||||
save_size = length;
|
||||
else
|
||||
save_size = png_ptr->save_buffer_size;
|
||||
|
||||
png_memcpy(ptr, png_ptr->save_buffer_ptr, (png_size_t)save_size);
|
||||
png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
|
||||
length -= save_size;
|
||||
ptr += (png_size_t)save_size;
|
||||
ptr += save_size;
|
||||
png_ptr->buffer_size -= save_size;
|
||||
png_ptr->save_buffer_size -= save_size;
|
||||
png_ptr->save_buffer_ptr += (png_size_t)save_size;
|
||||
png_ptr->save_buffer_ptr += save_size;
|
||||
}
|
||||
if (length && png_ptr->current_buffer_size)
|
||||
{
|
||||
png_uint_32 save_size;
|
||||
png_size_t save_size;
|
||||
|
||||
if (length < png_ptr->current_buffer_size)
|
||||
save_size = length;
|
||||
else
|
||||
save_size = png_ptr->current_buffer_size;
|
||||
|
||||
png_memcpy(ptr, png_ptr->current_buffer_ptr, (png_size_t)save_size);
|
||||
png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
|
||||
png_ptr->buffer_size -= save_size;
|
||||
png_ptr->current_buffer_size -= save_size;
|
||||
png_ptr->current_buffer_ptr += (png_size_t)save_size;
|
||||
png_ptr->current_buffer_ptr += save_size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -429,7 +431,7 @@ png_push_save_buffer(png_structp png_ptr)
|
||||
{
|
||||
if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
|
||||
{
|
||||
int i;
|
||||
png_size_t i;
|
||||
png_bytep sp;
|
||||
png_bytep dp;
|
||||
|
||||
@@ -444,25 +446,20 @@ png_push_save_buffer(png_structp png_ptr)
|
||||
if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
|
||||
png_ptr->save_buffer_max)
|
||||
{
|
||||
png_uint_32 new_max;
|
||||
png_size_t new_max;
|
||||
png_bytep old_buffer;
|
||||
|
||||
new_max = (int)(png_ptr->save_buffer_size +
|
||||
png_ptr->current_buffer_size + 256);
|
||||
new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
|
||||
old_buffer = png_ptr->save_buffer;
|
||||
png_ptr->save_buffer = (png_bytep)
|
||||
png_malloc(png_ptr, new_max);
|
||||
png_memcpy(png_ptr->save_buffer, old_buffer,
|
||||
(png_size_t)png_ptr->save_buffer_size);
|
||||
png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr, new_max);
|
||||
png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
|
||||
png_free(png_ptr, old_buffer);
|
||||
png_ptr->save_buffer_max = new_max;
|
||||
png_ptr->save_buffer_max = new_max;
|
||||
}
|
||||
if (png_ptr->current_buffer_size)
|
||||
{
|
||||
png_memcpy(png_ptr->save_buffer +
|
||||
(png_size_t)png_ptr->save_buffer_size,
|
||||
png_ptr->current_buffer_ptr,
|
||||
(png_size_t)png_ptr->current_buffer_size);
|
||||
png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
|
||||
png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
|
||||
png_ptr->save_buffer_size += png_ptr->current_buffer_size;
|
||||
png_ptr->current_buffer_size = 0;
|
||||
}
|
||||
@@ -472,7 +469,7 @@ png_push_save_buffer(png_structp png_ptr)
|
||||
|
||||
void
|
||||
png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
|
||||
png_uint_32 buffer_length)
|
||||
png_size_t buffer_length)
|
||||
{
|
||||
png_ptr->current_buffer = buffer;
|
||||
png_ptr->current_buffer_size = buffer_length;
|
||||
@@ -497,13 +494,12 @@ png_push_read_IDAT(png_structp png_ptr)
|
||||
png_ptr->push_length = png_get_uint_32(chunk_length);
|
||||
|
||||
png_reset_crc(png_ptr);
|
||||
png_push_fill_buffer(png_ptr, png_ptr->chunk_name, 4);
|
||||
png_calculate_crc(png_ptr, chunk_length, 4);
|
||||
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
|
||||
png_ptr->flags |= PNG_FLAG_HAVE_CHUNK_HEADER;
|
||||
|
||||
if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
|
||||
{
|
||||
png_ptr->process_mode = PNG_READ_END_MODE;
|
||||
png_ptr->process_mode = PNG_READ_CHUNK_MODE;
|
||||
if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
|
||||
png_error(png_ptr, "Not enough compressed data");
|
||||
return;
|
||||
@@ -513,9 +509,9 @@ png_push_read_IDAT(png_structp png_ptr)
|
||||
}
|
||||
if (png_ptr->idat_size && png_ptr->save_buffer_size)
|
||||
{
|
||||
png_uint_32 save_size;
|
||||
png_size_t save_size;
|
||||
|
||||
if (png_ptr->idat_size < png_ptr->save_buffer_size)
|
||||
if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
|
||||
save_size = png_ptr->idat_size;
|
||||
else
|
||||
save_size = png_ptr->save_buffer_size;
|
||||
@@ -526,13 +522,13 @@ png_push_read_IDAT(png_structp png_ptr)
|
||||
png_ptr->idat_size -= save_size;
|
||||
png_ptr->buffer_size -= save_size;
|
||||
png_ptr->save_buffer_size -= save_size;
|
||||
png_ptr->save_buffer_ptr += (png_size_t)save_size;
|
||||
png_ptr->save_buffer_ptr += save_size;
|
||||
}
|
||||
if (png_ptr->idat_size && png_ptr->current_buffer_size)
|
||||
{
|
||||
png_uint_32 save_size;
|
||||
png_size_t save_size;
|
||||
|
||||
if (png_ptr->idat_size < png_ptr->current_buffer_size)
|
||||
if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
|
||||
save_size = png_ptr->idat_size;
|
||||
else
|
||||
save_size = png_ptr->current_buffer_size;
|
||||
@@ -543,7 +539,7 @@ png_push_read_IDAT(png_structp png_ptr)
|
||||
png_ptr->idat_size -= save_size;
|
||||
png_ptr->buffer_size -= save_size;
|
||||
png_ptr->current_buffer_size -= save_size;
|
||||
png_ptr->current_buffer_ptr += (png_size_t)save_size;
|
||||
png_ptr->current_buffer_ptr += save_size;
|
||||
}
|
||||
if (!png_ptr->idat_size)
|
||||
{
|
||||
@@ -560,7 +556,7 @@ png_push_read_IDAT(png_structp png_ptr)
|
||||
|
||||
void
|
||||
png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
|
||||
png_uint_32 buffer_length)
|
||||
png_size_t buffer_length)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@@ -569,22 +565,25 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
|
||||
|
||||
png_ptr->zstream.next_in = buffer;
|
||||
png_ptr->zstream.avail_in = (uInt)buffer_length;
|
||||
do
|
||||
while(1)
|
||||
{
|
||||
ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
|
||||
if (ret == Z_STREAM_END)
|
||||
{
|
||||
if (png_ptr->zstream.avail_in)
|
||||
png_error(png_ptr, "Extra compressed data");
|
||||
if (!png_ptr->zstream.avail_out)
|
||||
if (!(png_ptr->zstream.avail_out))
|
||||
{
|
||||
png_push_process_row(png_ptr);
|
||||
}
|
||||
png_ptr->mode = PNG_AFTER_IDAT;
|
||||
|
||||
png_ptr->mode |= PNG_AFTER_IDAT;
|
||||
png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
|
||||
break;
|
||||
}
|
||||
if (ret != Z_OK)
|
||||
else if (ret == Z_BUF_ERROR)
|
||||
break;
|
||||
else if (ret != Z_OK)
|
||||
png_error(png_ptr, "Decompression Error");
|
||||
if (!(png_ptr->zstream.avail_out))
|
||||
{
|
||||
@@ -592,8 +591,9 @@ png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
|
||||
png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
|
||||
png_ptr->zstream.next_out = png_ptr->row_buf;
|
||||
}
|
||||
|
||||
} while (png_ptr->zstream.avail_in);
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -611,19 +611,18 @@ png_push_process_row(png_structp png_ptr)
|
||||
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
|
||||
(int)(png_ptr->row_buf[0]));
|
||||
|
||||
png_memcpy(png_ptr->prev_row, png_ptr->row_buf, (png_size_t)png_ptr->rowbytes + 1);
|
||||
png_memcpy(png_ptr->prev_row, png_ptr->row_buf, png_ptr->rowbytes + 1);
|
||||
|
||||
if (png_ptr->transformations)
|
||||
png_do_read_transformations(png_ptr);
|
||||
|
||||
#if defined(PNG_READ_INTERLACING_SUPPORTED)
|
||||
/* blow up interlaced rows to full size */
|
||||
if (png_ptr->interlaced &&
|
||||
(png_ptr->transformations & PNG_INTERLACE))
|
||||
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
|
||||
{
|
||||
if (png_ptr->pass < 6)
|
||||
png_do_read_interlace(&(png_ptr->row_info),
|
||||
png_ptr->row_buf + 1, png_ptr->pass);
|
||||
png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
|
||||
|
||||
switch (png_ptr->pass)
|
||||
{
|
||||
@@ -747,7 +746,7 @@ png_read_push_finish_row(png_structp png_ptr)
|
||||
if (png_ptr->interlaced)
|
||||
{
|
||||
png_ptr->row_number = 0;
|
||||
png_memset(png_ptr->prev_row, 0, (png_size_t)png_ptr->rowbytes + 1);
|
||||
png_memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
|
||||
do
|
||||
{
|
||||
png_ptr->pass++;
|
||||
@@ -781,8 +780,19 @@ png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length
|
||||
if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND)
|
||||
png_error(png_ptr, "Out of place tEXt");
|
||||
|
||||
png_ptr->current_text = (png_charp)png_malloc(png_ptr, length + 1);
|
||||
png_ptr->current_text[(png_size_t)length] = '\0';
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
png_ptr->skip_length = 0; /* This may not be necessary */
|
||||
|
||||
if (length > 65535L) /* We can't hold the entire string in memory */
|
||||
{
|
||||
png_warning(png_ptr, "tEXt chunk too large to fit in memory");
|
||||
png_ptr->skip_length = length - 65535L;
|
||||
length = 65535L;
|
||||
}
|
||||
#endif
|
||||
|
||||
png_ptr->current_text = (png_charp)png_malloc(png_ptr, length+1);
|
||||
png_ptr->current_text[length] = '\0';
|
||||
png_ptr->current_text_ptr = png_ptr->current_text;
|
||||
png_ptr->current_text_size = length;
|
||||
png_ptr->current_text_left = length;
|
||||
@@ -794,21 +804,19 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr->buffer_size && png_ptr->current_text_left)
|
||||
{
|
||||
png_uint_32 text_size;
|
||||
png_size_t text_size;
|
||||
|
||||
if (png_ptr->buffer_size < png_ptr->current_text_left)
|
||||
text_size = png_ptr->buffer_size;
|
||||
else
|
||||
text_size = png_ptr->current_text_left;
|
||||
png_push_fill_buffer(png_ptr, (png_bytep)png_ptr->current_text_ptr,
|
||||
text_size);
|
||||
png_calculate_crc(png_ptr, (png_bytep)png_ptr->current_text_ptr,
|
||||
text_size);
|
||||
png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
|
||||
png_ptr->current_text_left -= text_size;
|
||||
png_ptr->current_text_ptr += (png_size_t)text_size;
|
||||
png_ptr->current_text_ptr += text_size;
|
||||
}
|
||||
if (!(png_ptr->current_text_left))
|
||||
{
|
||||
png_textp text_ptr;
|
||||
png_charp text;
|
||||
png_charp key;
|
||||
|
||||
@@ -818,7 +826,12 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
|
||||
return;
|
||||
}
|
||||
|
||||
png_crc_finish(png_ptr, 0);
|
||||
png_push_crc_finish(png_ptr);
|
||||
|
||||
#if defined(PNG_MAX_MALLOC_64K)
|
||||
if (png_ptr->skip_length)
|
||||
return;
|
||||
#endif
|
||||
|
||||
key = png_ptr->current_text;
|
||||
png_ptr->current_text = 0;
|
||||
@@ -826,20 +839,17 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
|
||||
for (text = key; *text; text++)
|
||||
/* empty loop */ ;
|
||||
|
||||
if (text != key + (png_size_t)png_ptr->current_text_size)
|
||||
if (text != key + png_ptr->current_text_size)
|
||||
text++;
|
||||
|
||||
png_read_tEXt(png_ptr, info_ptr, key, text,
|
||||
png_ptr->current_text_size - (text - key));
|
||||
text_ptr = (png_textp)png_malloc(png_ptr, sizeof(png_text));
|
||||
text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
|
||||
text_ptr->key = key;
|
||||
text_ptr->text = text;
|
||||
|
||||
if (png_ptr->mode == PNG_AFTER_IDAT)
|
||||
{
|
||||
png_ptr->process_mode = PNG_READ_END_MODE;
|
||||
}
|
||||
else
|
||||
{
|
||||
png_ptr->process_mode = PNG_READ_CHUNK_MODE;
|
||||
}
|
||||
png_set_text(png_ptr, info_ptr, text_ptr, 1);
|
||||
|
||||
png_free(png_ptr, text_ptr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -851,8 +861,21 @@ png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length
|
||||
if (png_ptr->mode == PNG_BEFORE_IHDR || png_ptr->mode & PNG_HAVE_IEND)
|
||||
png_error(png_ptr, "Out of place zTXt");
|
||||
|
||||
png_ptr->current_text = (png_charp)png_malloc(png_ptr, length + 1);
|
||||
png_ptr->current_text[(png_size_t)length] = '\0';
|
||||
#ifdef PNG_MAX_MALLOC_64K
|
||||
/* We can't handle zTXt chunks > 64K, since we don't have enough space
|
||||
* to be able to store the uncompressed data. Actually, the threshold
|
||||
* is probably around 32K, but it isn't as definite as 64K is.
|
||||
*/
|
||||
if (length > 65535L)
|
||||
{
|
||||
png_warning(png_ptr, "zTXt chunk too large to fit in memory");
|
||||
png_push_crc_skip(png_ptr, length);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
png_ptr->current_text = (png_charp)png_malloc(png_ptr, length+1);
|
||||
png_ptr->current_text[length] = '\0';
|
||||
png_ptr->current_text_ptr = png_ptr->current_text;
|
||||
png_ptr->current_text_size = length;
|
||||
png_ptr->current_text_left = length;
|
||||
@@ -864,25 +887,23 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr->buffer_size && png_ptr->current_text_left)
|
||||
{
|
||||
png_uint_32 text_size;
|
||||
png_size_t text_size;
|
||||
|
||||
if (png_ptr->buffer_size < png_ptr->current_text_left)
|
||||
if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
|
||||
text_size = png_ptr->buffer_size;
|
||||
else
|
||||
text_size = png_ptr->current_text_left;
|
||||
png_push_fill_buffer(png_ptr, (png_bytep)png_ptr->current_text_ptr,
|
||||
text_size);
|
||||
png_calculate_crc(png_ptr, (png_bytep)png_ptr->current_text_ptr,
|
||||
text_size);
|
||||
png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
|
||||
png_ptr->current_text_left -= text_size;
|
||||
png_ptr->current_text_ptr += (png_size_t)text_size;
|
||||
png_ptr->current_text_ptr += text_size;
|
||||
}
|
||||
if (!(png_ptr->current_text_left))
|
||||
{
|
||||
png_textp text_ptr;
|
||||
png_charp text;
|
||||
png_charp key;
|
||||
int ret;
|
||||
png_uint_32 text_size, key_size;
|
||||
png_size_t text_size, key_size;
|
||||
|
||||
if (png_ptr->buffer_size < 4)
|
||||
{
|
||||
@@ -890,7 +911,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
return;
|
||||
}
|
||||
|
||||
png_crc_finish(png_ptr, 0);
|
||||
png_push_crc_finish(png_ptr);
|
||||
|
||||
key = png_ptr->current_text;
|
||||
png_ptr->current_text = 0;
|
||||
@@ -899,7 +920,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
/* empty loop */ ;
|
||||
|
||||
/* zTXt can't have zero text */
|
||||
if (text == key + (png_size_t)png_ptr->current_text_size)
|
||||
if (text == key + png_ptr->current_text_size)
|
||||
{
|
||||
png_free(png_ptr, key);
|
||||
return;
|
||||
@@ -907,7 +928,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
text++;
|
||||
|
||||
if (*text) /* check compression byte */
|
||||
if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
|
||||
{
|
||||
png_free(png_ptr, key);
|
||||
return;
|
||||
@@ -919,7 +940,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
|
||||
(text - key));
|
||||
png_ptr->zstream.next_out = png_ptr->zbuf;
|
||||
png_ptr->zstream.avail_out = (png_size_t)png_ptr->zbuf_size;
|
||||
png_ptr->zstream.avail_out = png_ptr->zbuf_size;
|
||||
|
||||
key_size = text - key;
|
||||
text_size = 0;
|
||||
@@ -937,19 +958,19 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
png_free(png_ptr, text);
|
||||
return;
|
||||
}
|
||||
if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
|
||||
if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
|
||||
{
|
||||
if (!text)
|
||||
if (text == NULL)
|
||||
{
|
||||
text = (png_charp)png_malloc(png_ptr,
|
||||
png_ptr->zbuf_size - png_ptr->zstream.avail_out +
|
||||
key_size + 1);
|
||||
png_memcpy(text + (png_size_t)key_size, png_ptr->zbuf,
|
||||
(png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out));
|
||||
png_memcpy(text, key, (png_size_t)key_size);
|
||||
text_size = key_size + (png_size_t)png_ptr->zbuf_size -
|
||||
png_memcpy(text + key_size, png_ptr->zbuf,
|
||||
png_ptr->zbuf_size - png_ptr->zstream.avail_out);
|
||||
png_memcpy(text, key, key_size);
|
||||
text_size = key_size + png_ptr->zbuf_size -
|
||||
png_ptr->zstream.avail_out;
|
||||
*(text + (png_size_t)text_size) = '\0';
|
||||
*(text + text_size) = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -958,12 +979,12 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
tmp = text;
|
||||
text = png_malloc(png_ptr, text_size +
|
||||
png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1);
|
||||
png_memcpy(text, tmp, (png_size_t)text_size);
|
||||
png_memcpy(text, tmp, text_size);
|
||||
png_free(png_ptr, tmp);
|
||||
png_memcpy(text + (png_size_t)text_size, png_ptr->zbuf,
|
||||
(png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out));
|
||||
png_memcpy(text + text_size, png_ptr->zbuf,
|
||||
png_ptr->zbuf_size - png_ptr->zstream.avail_out);
|
||||
text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
|
||||
*(text + (png_size_t)text_size) = '\0';
|
||||
*(text + text_size) = '\0';
|
||||
}
|
||||
if (ret != Z_STREAM_END)
|
||||
{
|
||||
@@ -992,18 +1013,17 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
|
||||
|
||||
png_free(png_ptr, key);
|
||||
key = text;
|
||||
text += (png_size_t)key_size;
|
||||
text += key_size;
|
||||
text_size -= key_size;
|
||||
|
||||
png_read_zTXt(png_ptr, info_ptr, key, text, text_size, 0);
|
||||
if (png_ptr->mode == PNG_AFTER_IDAT)
|
||||
{
|
||||
png_ptr->process_mode = PNG_READ_END_MODE;
|
||||
}
|
||||
else
|
||||
{
|
||||
png_ptr->process_mode = PNG_READ_CHUNK_MODE;
|
||||
}
|
||||
text_ptr = (png_textp)png_malloc(png_ptr, sizeof(png_text));
|
||||
text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
|
||||
text_ptr->key = key;
|
||||
text_ptr->text = text;
|
||||
|
||||
png_set_text(png_ptr, info_ptr, text_ptr, 1);
|
||||
|
||||
png_free(png_ptr, text_ptr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1033,21 +1053,21 @@ png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 len
|
||||
void
|
||||
png_push_have_info(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr->info_fn)
|
||||
if (png_ptr->info_fn != NULL)
|
||||
(*(png_ptr->info_fn))(png_ptr, info_ptr);
|
||||
}
|
||||
|
||||
void
|
||||
png_push_have_end(png_structp png_ptr, png_infop info_ptr)
|
||||
{
|
||||
if (png_ptr->end_fn)
|
||||
if (png_ptr->end_fn != NULL)
|
||||
(*(png_ptr->end_fn))(png_ptr, info_ptr);
|
||||
}
|
||||
|
||||
void
|
||||
png_push_have_row(png_structp png_ptr, png_bytep row)
|
||||
{
|
||||
if (png_ptr->row_fn)
|
||||
if (png_ptr->row_fn != NULL)
|
||||
(*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
|
||||
(int)png_ptr->pass);
|
||||
}
|
||||
@@ -1056,7 +1076,7 @@ void
|
||||
png_progressive_combine_row (png_structp png_ptr,
|
||||
png_bytep old_row, png_bytep new_row)
|
||||
{
|
||||
if (new_row)
|
||||
if (new_row != NULL)
|
||||
png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user