mirror of
				https://git.code.sf.net/p/libpng/code.git
				synced 2025-07-10 18:04:09 +02:00 
			
		
		
		
	[libpng14] Eliminated redundant png_push_read_tEXt|zTXt|iTXt|unknown code from
pngpread.c and use the sequential png_handle_tEXt, etc., in pngrutil.c;
    now that png_ptr->buffer is inaccessible to applications, the special
    handling is no longer useful.
  Fixed bug with png_handle_hIST with odd chunk length (Frank Busse).
			
			
This commit is contained in:
		
							parent
							
								
									0d95b3d8dc
								
							
						
					
					
						commit
						53060e0c54
					
				
							
								
								
									
										11
									
								
								ANNOUNCE
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								ANNOUNCE
									
									
									
									
									
								
							@ -1,5 +1,5 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Libpng 1.4.10beta01 - February 20, 2012
 | 
					Libpng 1.4.10beta01 - February 21, 2012
 | 
				
			||||||
 | 
					
 | 
				
			||||||
This is not intended to be a public release.  It will be replaced
 | 
					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.
 | 
					within a few weeks by a public version or by another test version.
 | 
				
			||||||
@ -24,10 +24,15 @@ Other information:
 | 
				
			|||||||
   1.4.10beta01-README.txt
 | 
					   1.4.10beta01-README.txt
 | 
				
			||||||
   1.4.10beta01-LICENSE.txt
 | 
					   1.4.10beta01-LICENSE.txt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Changes since the last public release (1.4.8):
 | 
					Changes since the last public release (1.4.9):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
version 1.4.10beta01 [February 20, 2012]
 | 
					version 1.4.10beta01 [February 21, 2012]
 | 
				
			||||||
  Removed two useless #ifdef directives from pngread.c and one from pngrutil.c
 | 
					  Removed two useless #ifdef directives from pngread.c and one from pngrutil.c
 | 
				
			||||||
 | 
					  Eliminated redundant png_push_read_tEXt|zTXt|iTXt|unknown code from
 | 
				
			||||||
 | 
					    pngpread.c and use the sequential png_handle_tEXt, etc., in pngrutil.c;
 | 
				
			||||||
 | 
					    now that png_ptr->buffer is inaccessible to applications, the special
 | 
				
			||||||
 | 
					    handling is no longer useful.
 | 
				
			||||||
 | 
					  Fixed bug with png_handle_hIST with odd chunk length (Frank Busse).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Send comments/corrections/commendations to glennrp at users.sourceforge.net
 | 
					Send comments/corrections/commendations to glennrp at users.sourceforge.net
 | 
				
			||||||
or to png-mng-implement at lists.sf.net (subscription required; visit
 | 
					or to png-mng-implement at lists.sf.net (subscription required; visit
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										7
									
								
								CHANGES
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								CHANGES
									
									
									
									
									
								
							@ -2839,8 +2839,13 @@ version 1.4.9rc01 [February 17, 2012]
 | 
				
			|||||||
version 1.4.9 [February 18, 2012]
 | 
					version 1.4.9 [February 18, 2012]
 | 
				
			||||||
  No changes.
 | 
					  No changes.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
version 1.4.10beta01 [February 20, 2012]
 | 
					version 1.4.10beta01 [February 21, 2012]
 | 
				
			||||||
  Removed two useless #ifdef directives from pngread.c and one from pngrutil.c
 | 
					  Removed two useless #ifdef directives from pngread.c and one from pngrutil.c
 | 
				
			||||||
 | 
					  Eliminated redundant png_push_read_tEXt|zTXt|iTXt|unknown code from
 | 
				
			||||||
 | 
					    pngpread.c and use the sequential png_handle_tEXt, etc., in pngrutil.c;
 | 
				
			||||||
 | 
					    now that png_ptr->buffer is inaccessible to applications, the special
 | 
				
			||||||
 | 
					    handling is no longer useful.
 | 
				
			||||||
 | 
					  Fixed bug with png_handle_hIST with odd chunk length (Frank Busse).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Send comments/corrections/commendations to glennrp at users.sourceforge.net
 | 
					Send comments/corrections/commendations to glennrp at users.sourceforge.net
 | 
				
			||||||
or to png-mng-implement at lists.sf.net (subscription required; visit
 | 
					or to png-mng-implement at lists.sf.net (subscription required; visit
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										544
									
								
								pngpread.c
									
									
									
									
									
								
							
							
						
						
									
										544
									
								
								pngpread.c
									
									
									
									
									
								
							@ -1,8 +1,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* pngpread.c - read a png file in push mode
 | 
					/* pngpread.c - read a png file in push mode
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Last changed in libpng 1.4.6 [March 8, 2011]
 | 
					 * Last changed in libpng 1.4.10 [February 21, 2012]
 | 
				
			||||||
 * Copyright (c) 1998-2011 Glenn Randers-Pehrson
 | 
					 * Copyright (c) 1998-2012 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.)
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
@ -71,30 +71,6 @@ png_process_some_data(png_structp png_ptr, png_infop info_ptr)
 | 
				
			|||||||
         break;
 | 
					         break;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef PNG_READ_tEXt_SUPPORTED
 | 
					 | 
				
			||||||
      case PNG_READ_tEXt_MODE:
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
         png_push_read_tEXt(png_ptr, info_ptr);
 | 
					 | 
				
			||||||
         break;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
#ifdef PNG_READ_zTXt_SUPPORTED
 | 
					 | 
				
			||||||
      case PNG_READ_zTXt_MODE:
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
         png_push_read_zTXt(png_ptr, info_ptr);
 | 
					 | 
				
			||||||
         break;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
#ifdef PNG_READ_iTXt_SUPPORTED
 | 
					 | 
				
			||||||
      case PNG_READ_iTXt_MODE:
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
         png_push_read_iTXt(png_ptr, info_ptr);
 | 
					 | 
				
			||||||
         break;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
      case PNG_SKIP_MODE:
 | 
					      case PNG_SKIP_MODE:
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
         png_push_crc_finish(png_ptr);
 | 
					         png_push_crc_finish(png_ptr);
 | 
				
			||||||
@ -527,7 +503,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
 | 
				
			|||||||
         return;
 | 
					         return;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
 | 
					      png_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@ -540,7 +516,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
 | 
				
			|||||||
         return;
 | 
					         return;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
 | 
					      png_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@ -553,7 +529,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
 | 
				
			|||||||
         return;
 | 
					         return;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
 | 
					      png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
@ -564,7 +540,7 @@ png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
 | 
				
			|||||||
         png_push_save_buffer(png_ptr);
 | 
					         png_push_save_buffer(png_ptr);
 | 
				
			||||||
         return;
 | 
					         return;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
 | 
					      png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
 | 
					   png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
 | 
				
			||||||
@ -1196,514 +1172,6 @@ png_read_push_finish_row(png_structp png_ptr)
 | 
				
			|||||||
#endif /* PNG_READ_INTERLACING_SUPPORTED */
 | 
					#endif /* PNG_READ_INTERLACING_SUPPORTED */
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef PNG_READ_tEXt_SUPPORTED
 | 
					 | 
				
			||||||
void /* PRIVATE */
 | 
					 | 
				
			||||||
png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
 | 
					 | 
				
			||||||
   length)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
   if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
         png_error(png_ptr, "Out of place tEXt");
 | 
					 | 
				
			||||||
         PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef PNG_MAX_MALLOC_64K
 | 
					 | 
				
			||||||
   png_ptr->skip_length = 0;  /* This may not be necessary */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
   if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
 | 
					 | 
				
			||||||
   {
 | 
					 | 
				
			||||||
      png_warning(png_ptr, "tEXt chunk too large to fit in memory");
 | 
					 | 
				
			||||||
      png_ptr->skip_length = length - (png_uint_32)65535L;
 | 
					 | 
				
			||||||
      length = (png_uint_32)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 = (png_size_t)length;
 | 
					 | 
				
			||||||
   png_ptr->current_text_left = (png_size_t)length;
 | 
					 | 
				
			||||||
   png_ptr->process_mode = PNG_READ_tEXt_MODE;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void /* PRIVATE */
 | 
					 | 
				
			||||||
png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
   if (png_ptr->buffer_size && png_ptr->current_text_left)
 | 
					 | 
				
			||||||
   {
 | 
					 | 
				
			||||||
      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_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 += text_size;
 | 
					 | 
				
			||||||
   }
 | 
					 | 
				
			||||||
   if (!(png_ptr->current_text_left))
 | 
					 | 
				
			||||||
   {
 | 
					 | 
				
			||||||
      png_textp text_ptr;
 | 
					 | 
				
			||||||
      png_charp text;
 | 
					 | 
				
			||||||
      png_charp key;
 | 
					 | 
				
			||||||
      int ret;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (png_ptr->buffer_size < 4)
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
         png_push_save_buffer(png_ptr);
 | 
					 | 
				
			||||||
         return;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      png_push_crc_finish(png_ptr);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef PNG_MAX_MALLOC_64K
 | 
					 | 
				
			||||||
      if (png_ptr->skip_length)
 | 
					 | 
				
			||||||
         return;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      key = png_ptr->current_text;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      for (text = key; *text; text++)
 | 
					 | 
				
			||||||
         /* Empty loop */ ;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (text < key + png_ptr->current_text_size)
 | 
					 | 
				
			||||||
         text++;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      text_ptr = (png_textp)png_malloc(png_ptr,
 | 
					 | 
				
			||||||
         png_sizeof(png_text));
 | 
					 | 
				
			||||||
      text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
 | 
					 | 
				
			||||||
      text_ptr->key = key;
 | 
					 | 
				
			||||||
#ifdef PNG_iTXt_SUPPORTED
 | 
					 | 
				
			||||||
      text_ptr->lang = NULL;
 | 
					 | 
				
			||||||
      text_ptr->lang_key = NULL;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
      text_ptr->text = text;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      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");
 | 
					 | 
				
			||||||
   }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef PNG_READ_zTXt_SUPPORTED
 | 
					 | 
				
			||||||
void /* PRIVATE */
 | 
					 | 
				
			||||||
png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
 | 
					 | 
				
			||||||
   length)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
   if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
         png_error(png_ptr, "Out of place zTXt");
 | 
					 | 
				
			||||||
         PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#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 > (png_uint_32)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 = (png_size_t)length;
 | 
					 | 
				
			||||||
   png_ptr->current_text_left = (png_size_t)length;
 | 
					 | 
				
			||||||
   png_ptr->process_mode = PNG_READ_zTXt_MODE;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void /* PRIVATE */
 | 
					 | 
				
			||||||
png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
   if (png_ptr->buffer_size && png_ptr->current_text_left)
 | 
					 | 
				
			||||||
   {
 | 
					 | 
				
			||||||
      png_size_t text_size;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      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_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 += text_size;
 | 
					 | 
				
			||||||
   }
 | 
					 | 
				
			||||||
   if (!(png_ptr->current_text_left))
 | 
					 | 
				
			||||||
   {
 | 
					 | 
				
			||||||
      png_textp text_ptr;
 | 
					 | 
				
			||||||
      png_charp text;
 | 
					 | 
				
			||||||
      png_charp key;
 | 
					 | 
				
			||||||
      int ret;
 | 
					 | 
				
			||||||
      png_size_t text_size, key_size;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (png_ptr->buffer_size < 4)
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
         png_push_save_buffer(png_ptr);
 | 
					 | 
				
			||||||
         return;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      png_push_crc_finish(png_ptr);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      key = png_ptr->current_text;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      for (text = key; *text; text++)
 | 
					 | 
				
			||||||
         /* Empty loop */ ;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      /* 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;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      text++;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (*text != PNG_TEXT_COMPRESSION_zTXt) /* Check compression byte */
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
         png_ptr->current_text = NULL;
 | 
					 | 
				
			||||||
         png_free(png_ptr, key);
 | 
					 | 
				
			||||||
         return;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      text++;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      png_ptr->zstream.next_in = (png_bytep )text;
 | 
					 | 
				
			||||||
      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 = (uInt)png_ptr->zbuf_size;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      key_size = text - key;
 | 
					 | 
				
			||||||
      text_size = 0;
 | 
					 | 
				
			||||||
      text = NULL;
 | 
					 | 
				
			||||||
      ret = Z_STREAM_END;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      while (png_ptr->zstream.avail_in)
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
         ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
 | 
					 | 
				
			||||||
         if (ret != Z_OK && ret != Z_STREAM_END)
 | 
					 | 
				
			||||||
         {
 | 
					 | 
				
			||||||
            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;
 | 
					 | 
				
			||||||
         }
 | 
					 | 
				
			||||||
         if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
 | 
					 | 
				
			||||||
         {
 | 
					 | 
				
			||||||
            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 + 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 + text_size) = '\0';
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            else
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
               png_charp tmp;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
               tmp = text;
 | 
					 | 
				
			||||||
               text = (png_charp)png_malloc(png_ptr, text_size +
 | 
					 | 
				
			||||||
                  (png_ptr->zbuf_size
 | 
					 | 
				
			||||||
                  - png_ptr->zstream.avail_out + 1));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
               png_memcpy(text, tmp, text_size);
 | 
					 | 
				
			||||||
               png_free(png_ptr, tmp);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
               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 + text_size) = '\0';
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            if (ret != Z_STREAM_END)
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
               png_ptr->zstream.next_out = png_ptr->zbuf;
 | 
					 | 
				
			||||||
               png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
         }
 | 
					 | 
				
			||||||
         else
 | 
					 | 
				
			||||||
         {
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
         }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
         if (ret == Z_STREAM_END)
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      inflateReset(&png_ptr->zstream);
 | 
					 | 
				
			||||||
      png_ptr->zstream.avail_in = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      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;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      text_ptr = (png_textp)png_malloc(png_ptr,
 | 
					 | 
				
			||||||
          png_sizeof(png_text));
 | 
					 | 
				
			||||||
      text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
 | 
					 | 
				
			||||||
      text_ptr->key = key;
 | 
					 | 
				
			||||||
#ifdef PNG_iTXt_SUPPORTED
 | 
					 | 
				
			||||||
      text_ptr->lang = NULL;
 | 
					 | 
				
			||||||
      text_ptr->lang_key = NULL;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
      text_ptr->text = text;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      png_free(png_ptr, key);
 | 
					 | 
				
			||||||
      png_free(png_ptr, text_ptr);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (ret)
 | 
					 | 
				
			||||||
        png_warning(png_ptr, "Insufficient memory to store text chunk");
 | 
					 | 
				
			||||||
   }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef PNG_READ_iTXt_SUPPORTED
 | 
					 | 
				
			||||||
void /* PRIVATE */
 | 
					 | 
				
			||||||
png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
 | 
					 | 
				
			||||||
   length)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
   if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
         png_error(png_ptr, "Out of place iTXt");
 | 
					 | 
				
			||||||
         PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef PNG_MAX_MALLOC_64K
 | 
					 | 
				
			||||||
   png_ptr->skip_length = 0;  /* This may not be necessary */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
   if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
 | 
					 | 
				
			||||||
   {
 | 
					 | 
				
			||||||
      png_warning(png_ptr, "iTXt chunk too large to fit in memory");
 | 
					 | 
				
			||||||
      png_ptr->skip_length = length - (png_uint_32)65535L;
 | 
					 | 
				
			||||||
      length = (png_uint_32)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 = (png_size_t)length;
 | 
					 | 
				
			||||||
   png_ptr->current_text_left = (png_size_t)length;
 | 
					 | 
				
			||||||
   png_ptr->process_mode = PNG_READ_iTXt_MODE;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void /* PRIVATE */
 | 
					 | 
				
			||||||
png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
   if (png_ptr->buffer_size && png_ptr->current_text_left)
 | 
					 | 
				
			||||||
   {
 | 
					 | 
				
			||||||
      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_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 += text_size;
 | 
					 | 
				
			||||||
   }
 | 
					 | 
				
			||||||
   if (!(png_ptr->current_text_left))
 | 
					 | 
				
			||||||
   {
 | 
					 | 
				
			||||||
      png_textp text_ptr;
 | 
					 | 
				
			||||||
      png_charp key;
 | 
					 | 
				
			||||||
      int comp_flag;
 | 
					 | 
				
			||||||
      png_charp lang;
 | 
					 | 
				
			||||||
      png_charp lang_key;
 | 
					 | 
				
			||||||
      png_charp text;
 | 
					 | 
				
			||||||
      int ret;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (png_ptr->buffer_size < 4)
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
         png_push_save_buffer(png_ptr);
 | 
					 | 
				
			||||||
         return;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      png_push_crc_finish(png_ptr);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef PNG_MAX_MALLOC_64K
 | 
					 | 
				
			||||||
      if (png_ptr->skip_length)
 | 
					 | 
				
			||||||
         return;
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      key = png_ptr->current_text;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      for (lang = key; *lang; lang++)
 | 
					 | 
				
			||||||
         /* Empty loop */ ;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (lang < key + png_ptr->current_text_size - 3)
 | 
					 | 
				
			||||||
         lang++;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      comp_flag = *lang++;
 | 
					 | 
				
			||||||
      lang++;     /* Skip comp_type, always zero */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      for (lang_key = lang; *lang_key; lang_key++)
 | 
					 | 
				
			||||||
         /* Empty loop */ ;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      lang_key++;        /* Skip NUL separator */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      text=lang_key;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (lang_key < key + png_ptr->current_text_size - 1)
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
        for (; *text; text++)
 | 
					 | 
				
			||||||
           /* Empty loop */ ;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (text < key + png_ptr->current_text_size)
 | 
					 | 
				
			||||||
         text++;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      text_ptr = (png_textp)png_malloc(png_ptr,
 | 
					 | 
				
			||||||
         png_sizeof(png_text));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      text_ptr->compression = comp_flag + 2;
 | 
					 | 
				
			||||||
      text_ptr->key = key;
 | 
					 | 
				
			||||||
      text_ptr->lang = lang;
 | 
					 | 
				
			||||||
      text_ptr->lang_key = lang_key;
 | 
					 | 
				
			||||||
      text_ptr->text = text;
 | 
					 | 
				
			||||||
      text_ptr->text_length = 0;
 | 
					 | 
				
			||||||
      text_ptr->itxt_length = png_strlen(text);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      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");
 | 
					 | 
				
			||||||
   }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/* This function is called when we haven't found a handler for this
 | 
					 | 
				
			||||||
 * chunk.  If there isn't a problem with the chunk itself (ie a bad chunk
 | 
					 | 
				
			||||||
 * name or a critical chunk), the chunk is (currently) silently ignored.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
void /* PRIVATE */
 | 
					 | 
				
			||||||
png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
 | 
					 | 
				
			||||||
   length)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
   png_uint_32 skip = 0;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
   if (!(png_ptr->chunk_name[0] & 0x20))
 | 
					 | 
				
			||||||
   {
 | 
					 | 
				
			||||||
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
 | 
					 | 
				
			||||||
      if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
 | 
					 | 
				
			||||||
         PNG_HANDLE_CHUNK_ALWAYS
 | 
					 | 
				
			||||||
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
 | 
					 | 
				
			||||||
         && png_ptr->read_user_chunk_fn == NULL
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
         )
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
         png_chunk_error(png_ptr, "unknown critical chunk");
 | 
					 | 
				
			||||||
         PNG_UNUSED(info_ptr) /* To quiet some compiler warnings */
 | 
					 | 
				
			||||||
   }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
 | 
					 | 
				
			||||||
   if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
 | 
					 | 
				
			||||||
   {
 | 
					 | 
				
			||||||
#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
 | 
					 | 
				
			||||||
      png_memcpy((png_charp)png_ptr->unknown_chunk.name,
 | 
					 | 
				
			||||||
                 (png_charp)png_ptr->chunk_name,
 | 
					 | 
				
			||||||
                 png_sizeof(png_ptr->unknown_chunk.name));
 | 
					 | 
				
			||||||
      png_ptr->unknown_chunk.name[png_sizeof(png_ptr->unknown_chunk.name) - 1]
 | 
					 | 
				
			||||||
        = '\0';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      png_ptr->unknown_chunk.size = length;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (length == 0)
 | 
					 | 
				
			||||||
         png_ptr->unknown_chunk.data = NULL;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      else
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
         png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr,
 | 
					 | 
				
			||||||
            length);
 | 
					 | 
				
			||||||
         png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#ifdef PNG_READ_USER_CHUNKS_SUPPORTED
 | 
					 | 
				
			||||||
      if (png_ptr->read_user_chunk_fn != NULL)
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
         /* Callback to user unknown chunk handler */
 | 
					 | 
				
			||||||
         int ret;
 | 
					 | 
				
			||||||
         ret = (*(png_ptr->read_user_chunk_fn))
 | 
					 | 
				
			||||||
           (png_ptr, &png_ptr->unknown_chunk);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
         if (ret < 0)
 | 
					 | 
				
			||||||
            png_chunk_error(png_ptr, "error in user chunk");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
         if (ret == 0)
 | 
					 | 
				
			||||||
         {
 | 
					 | 
				
			||||||
            if (!(png_ptr->chunk_name[0] & 0x20))
 | 
					 | 
				
			||||||
               if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
 | 
					 | 
				
			||||||
                    PNG_HANDLE_CHUNK_ALWAYS)
 | 
					 | 
				
			||||||
                  png_chunk_error(png_ptr, "unknown critical chunk");
 | 
					 | 
				
			||||||
            png_set_unknown_chunks(png_ptr, info_ptr,
 | 
					 | 
				
			||||||
               &png_ptr->unknown_chunk, 1);
 | 
					 | 
				
			||||||
         }
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      else
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
        png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
 | 
					 | 
				
			||||||
      png_free(png_ptr, png_ptr->unknown_chunk.data);
 | 
					 | 
				
			||||||
      png_ptr->unknown_chunk.data = NULL;
 | 
					 | 
				
			||||||
   }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
   else
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
      skip=length;
 | 
					 | 
				
			||||||
   png_push_crc_skip(png_ptr, skip);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
void /* PRIVATE */
 | 
					void /* PRIVATE */
 | 
				
			||||||
png_push_have_info(png_structp png_ptr, png_infop info_ptr)
 | 
					png_push_have_info(png_structp png_ptr, png_infop info_ptr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user