diff options
author | Glenn Randers-Pehrson <glennrp at users.sourceforge.net> | 2002-06-20 06:54:34 -0500 |
---|---|---|
committer | Glenn Randers-Pehrson <glennrp at users.sourceforge.net> | 2009-04-06 16:07:14 -0500 |
commit | d1e8c8694dfc6a3e1ae6cbdc1982cc3f646bb7b3 (patch) | |
tree | cb31826378c946b75859de5cfd7405b14e4163a8 /pngpread.c | |
parent | 07748d1b2c0353bf7a5eadfbe988cb5b87e897b4 (diff) | |
download | libpng-d1e8c8694dfc6a3e1ae6cbdc1982cc3f646bb7b3.tar.gz |
Imported from libpng-1.2.4beta2.tarv1.2.4beta2
Diffstat (limited to 'pngpread.c')
-rw-r--r-- | pngpread.c | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/pngpread.c b/pngpread.c index 897fc32e3..78d75d121 100644 --- a/pngpread.c +++ b/pngpread.c @@ -1,7 +1,7 @@ /* pngpread.c - read a png file in push mode * - * libpng 1.2.4beta1 - May 25, 2002 + * libpng 1.2.4beta2 - June 20, 2002 * For conditions of distribution and use, see copyright notice in png.h * Copyright (c) 1998-2002 Glenn Randers-Pehrson * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) @@ -221,7 +221,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length); } else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4)) @@ -231,7 +230,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length); } else if (!png_memcmp(png_ptr->chunk_name, (png_bytep)png_IDAT, 4)) @@ -243,7 +241,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) if (!(png_ptr->mode & PNG_HAVE_IHDR)) png_error(png_ptr, "Missing IHDR before IDAT"); else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && - !(png_ptr->mode & PNG_HAVE_PLTE)) + !(png_ptr->mode & PNG_HAVE_PLTE)) png_error(png_ptr, "Missing PLTE before IDAT"); if (png_ptr->mode & PNG_HAVE_IDAT) @@ -270,8 +268,8 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length); + png_ptr->process_mode = PNG_READ_DONE_MODE; png_push_have_end(png_ptr, info_ptr); } @@ -283,7 +281,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length); } #endif @@ -295,7 +292,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length); } #endif @@ -307,7 +303,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length); } #endif @@ -319,7 +314,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length); } #endif @@ -331,7 +325,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length); } #endif @@ -343,7 +336,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length); } #endif @@ -355,7 +347,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length); } #endif @@ -367,7 +358,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length); } #endif @@ -379,7 +369,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length); } #endif @@ -391,7 +380,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length); } #endif @@ -403,7 +391,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length); } #endif @@ -415,7 +402,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length); } #endif @@ -427,7 +413,6 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length); } #endif @@ -439,30 +424,49 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr) png_push_save_buffer(png_ptr); return; } - png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length); } #endif #if defined(PNG_READ_tEXt_SUPPORTED) else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4)) { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length); } #endif #if defined(PNG_READ_zTXt_SUPPORTED) else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4)) { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length); } #endif #if defined(PNG_READ_iTXt_SUPPORTED) else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4)) { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length); } #endif else { + if (png_ptr->push_length + 4 > png_ptr->buffer_size) + { + png_push_save_buffer(png_ptr); + return; + } png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length); } @@ -802,13 +806,13 @@ png_push_process_row(png_structp png_ptr) png_read_push_finish_row(png_ptr); } } - if (png_ptr->pass == 4 && png_ptr->height <= 4) - { - for (i = 0; i < 2 && png_ptr->pass == 4; i++) - { - png_push_have_row(png_ptr, png_bytep_NULL); - png_read_push_finish_row(png_ptr); - } + if (png_ptr->pass == 4 && png_ptr->height <= 4) + { + for (i = 0; i < 2 && png_ptr->pass == 4; i++) + { + png_push_have_row(png_ptr, png_bytep_NULL); + png_read_push_finish_row(png_ptr); + } } if (png_ptr->pass == 6 && png_ptr->height <= 4) { @@ -1067,7 +1071,6 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr) #endif key = png_ptr->current_text; - png_ptr->current_text = 0; for (text = key; *text; text++) /* empty loop */ ; @@ -1088,6 +1091,7 @@ png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr) png_free(png_ptr, key); png_free(png_ptr, text_ptr); + png_ptr->current_text = NULL; if (ret) png_warning(png_ptr, "Insufficient memory to store text chunk."); @@ -1161,7 +1165,6 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) png_push_crc_finish(png_ptr); key = png_ptr->current_text; - png_ptr->current_text = 0; for (text = key; *text; text++) /* empty loop */ ; @@ -1169,6 +1172,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) /* zTXt can't have zero text */ if (text == key + png_ptr->current_text_size) { + png_ptr->current_text = NULL; png_free(png_ptr, key); return; } @@ -1177,6 +1181,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */ { + png_ptr->current_text = NULL; png_free(png_ptr, key); return; } @@ -1201,6 +1206,7 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) { inflateReset(&png_ptr->zstream); png_ptr->zstream.avail_in = 0; + png_ptr->current_text = NULL; png_free(png_ptr, key); png_free(png_ptr, text); return; @@ -1254,11 +1260,13 @@ png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr) if (ret != Z_STREAM_END) { + png_ptr->current_text = NULL; png_free(png_ptr, key); png_free(png_ptr, text); return; } + png_ptr->current_text = NULL; png_free(png_ptr, key); key = text; text += key_size; @@ -1355,7 +1363,6 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr) #endif key = png_ptr->current_text; - png_ptr->current_text = 0; for (lang = key; *lang; lang++) /* empty loop */ ; @@ -1387,6 +1394,8 @@ png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr) ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1); + png_ptr->current_text = NULL; + png_free(png_ptr, text_ptr); if (ret) png_warning(png_ptr, "Insufficient memory to store iTXt chunk."); |