mirror of
				https://git.code.sf.net/p/libpng/code.git
				synced 2025-07-10 18:04:09 +02:00 
			
		
		
		
	[libpng17] Port contrib/libtests/pngvalid.c from libpng16.
This commit is contained in:
		
							parent
							
								
									1982dc6c2f
								
							
						
					
					
						commit
						120f80369b
					
				
							
								
								
									
										5
									
								
								ANNOUNCE
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								ANNOUNCE
									
									
									
									
									
								
							@ -1,5 +1,5 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
Libpng 1.7.0beta81 - May 21, 2016
 | 
					Libpng 1.7.0beta81 - May 31, 2016
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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.
 | 
				
			||||||
@ -1290,7 +1290,7 @@ Version 1.7.0beta80 [May 6, 2016]
 | 
				
			|||||||
      unreachable code in pz_default_settings and eliminated a spurious
 | 
					      unreachable code in pz_default_settings and eliminated a spurious
 | 
				
			||||||
      warning in pngcp for small files.
 | 
					      warning in pngcp for small files.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Version 1.7.0beta81 [May 21, 2016]
 | 
					Version 1.7.0beta81 [May 31, 2016]
 | 
				
			||||||
  Check for CLOCK_PROCESS_CPUTIME_ID when building /contrib/libtests/timepng.
 | 
					  Check for CLOCK_PROCESS_CPUTIME_ID when building /contrib/libtests/timepng.
 | 
				
			||||||
    Otherwise it does not build on platforms that don't supply clock_gettime().
 | 
					    Otherwise it does not build on platforms that don't supply clock_gettime().
 | 
				
			||||||
  Add check for clock_gettime() in Makefile.am and configure.ac
 | 
					  Add check for clock_gettime() in Makefile.am and configure.ac
 | 
				
			||||||
@ -1328,6 +1328,7 @@ Version 1.7.0beta81 [May 21, 2016]
 | 
				
			|||||||
  The default write zlib settings are still lower than libpng16.  The
 | 
					  The default write zlib settings are still lower than libpng16.  The
 | 
				
			||||||
    selection algorithm is being refined (the overall results are worse than
 | 
					    selection algorithm is being refined (the overall results are worse than
 | 
				
			||||||
    not doing any filtering).
 | 
					    not doing any filtering).
 | 
				
			||||||
 | 
					  Port contrib/libtests/pngvalid.c from libpng16.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 | 
					Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 | 
				
			||||||
(subscription required; visit
 | 
					(subscription required; visit
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										3
									
								
								CHANGES
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								CHANGES
									
									
									
									
									
								
							@ -5590,7 +5590,7 @@ Version 1.7.0beta80 [May 6, 2016]
 | 
				
			|||||||
      unreachable code in pz_default_settings and eliminated a spurious
 | 
					      unreachable code in pz_default_settings and eliminated a spurious
 | 
				
			||||||
      warning in pngcp for small files.
 | 
					      warning in pngcp for small files.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Version 1.7.0beta81 [May 21, 2016]
 | 
					Version 1.7.0beta81 [May 31, 2016]
 | 
				
			||||||
  Check for CLOCK_PROCESS_CPUTIME_ID when building /contrib/libtests/timepng.
 | 
					  Check for CLOCK_PROCESS_CPUTIME_ID when building /contrib/libtests/timepng.
 | 
				
			||||||
    Otherwise it does not build on platforms that don't supply clock_gettime().
 | 
					    Otherwise it does not build on platforms that don't supply clock_gettime().
 | 
				
			||||||
  Add check for clock_gettime() in Makefile.am and configure.ac
 | 
					  Add check for clock_gettime() in Makefile.am and configure.ac
 | 
				
			||||||
@ -5628,6 +5628,7 @@ Version 1.7.0beta81 [May 21, 2016]
 | 
				
			|||||||
  The default write zlib settings are still lower than libpng16.  The
 | 
					  The default write zlib settings are still lower than libpng16.  The
 | 
				
			||||||
    selection algorithm is being refined (the overall results are worse than
 | 
					    selection algorithm is being refined (the overall results are worse than
 | 
				
			||||||
    not doing any filtering).
 | 
					    not doing any filtering).
 | 
				
			||||||
 | 
					  Port contrib/libtests/pngvalid.c from libpng16.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 | 
					Send comments/corrections/commendations to png-mng-implement at lists.sf.net
 | 
				
			||||||
(subscription required; visit
 | 
					(subscription required; visit
 | 
				
			||||||
 | 
				
			|||||||
@ -1,7 +1,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
/* pngvalid.c - validate libpng by constructing then reading png files.
 | 
					/* pngvalid.c - validate libpng by constructing then reading png files.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * Last changed in libpng 1.6.22 [May 26, 2016]
 | 
					 * Last changed in libpng 1.6.23 [(PENDING RELEASE)]
 | 
				
			||||||
 * Copyright (c) 2014-2016 Glenn Randers-Pehrson
 | 
					 * Copyright (c) 2014-2016 Glenn Randers-Pehrson
 | 
				
			||||||
 * Written by John Cunningham Bowler
 | 
					 * Written by John Cunningham Bowler
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
@ -308,38 +308,33 @@ randomize(void *pv, size_t size)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#define R8(this) randomize(&(this), sizeof (this))
 | 
					#define R8(this) randomize(&(this), sizeof (this))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void r16(png_uint_16p p16, size_t count)
 | 
					#ifdef PNG_READ_SUPPORTED
 | 
				
			||||||
 | 
					static png_byte
 | 
				
			||||||
 | 
					random_byte(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
   size_t i;
 | 
					   unsigned char b1[1];
 | 
				
			||||||
 | 
					   randomize(b1, sizeof b1);
 | 
				
			||||||
 | 
					   return b1[0];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif /* READ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   for (i=0; i<count; ++i)
 | 
					static png_uint_16
 | 
				
			||||||
 | 
					random_u16(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
   unsigned char b2[2];
 | 
					   unsigned char b2[2];
 | 
				
			||||||
   randomize(b2, sizeof b2);
 | 
					   randomize(b2, sizeof b2);
 | 
				
			||||||
      *p16++ = png_get_uint_16(b2);
 | 
					   return png_get_uint_16(b2);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define R16(this) r16(&(this), (sizeof (this))/(sizeof (png_uint_16)))
 | 
					 | 
				
			||||||
#define R16_1(this) r16(&(this), (size_t) 1U)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if defined PNG_READ_RGB_TO_GRAY_SUPPORTED ||\
 | 
					#if defined PNG_READ_RGB_TO_GRAY_SUPPORTED ||\
 | 
				
			||||||
    defined PNG_READ_FILLER_SUPPORTED
 | 
					    defined PNG_READ_FILLER_SUPPORTED
 | 
				
			||||||
static void r32(png_uint_32p p32, size_t count)
 | 
					static png_uint_32
 | 
				
			||||||
{
 | 
					random_u32(void)
 | 
				
			||||||
   size_t i;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
   for (i=0; i<count; ++i)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
   unsigned char b4[4];
 | 
					   unsigned char b4[4];
 | 
				
			||||||
   randomize(b4, sizeof b4);
 | 
					   randomize(b4, sizeof b4);
 | 
				
			||||||
      *p32++ = png_get_uint_32(b4);
 | 
					   return png_get_uint_32(b4);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#define R32(this) r32(&(this), (sizeof (this))/(sizeof (png_uint_32)))
 | 
					 | 
				
			||||||
#define R32_1(this) r32(&(this), (size_t) 1U)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
#endif /* READ_FILLER || READ_RGB_TO_GRAY */
 | 
					#endif /* READ_FILLER || READ_RGB_TO_GRAY */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif /* READ || WRITE_tRNS || WRITE_FILTER */
 | 
					#endif /* READ || WRITE_tRNS || WRITE_FILTER */
 | 
				
			||||||
@ -349,11 +344,7 @@ static void r32(png_uint_32p p32, size_t count)
 | 
				
			|||||||
static unsigned int
 | 
					static unsigned int
 | 
				
			||||||
random_mod(unsigned int max)
 | 
					random_mod(unsigned int max)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
   png_uint_16 x;
 | 
					   return random_u16() % max; /* 0 .. max-1 */
 | 
				
			||||||
 | 
					 | 
				
			||||||
   R16_1(x);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
   return x % max; /* 0 .. max-1 */
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif /* READ_TRANSFORMS || WRITE_FILTER */
 | 
					#endif /* READ_TRANSFORMS || WRITE_FILTER */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -362,11 +353,7 @@ random_mod(unsigned int max)
 | 
				
			|||||||
static int
 | 
					static int
 | 
				
			||||||
random_choice(void)
 | 
					random_choice(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
   unsigned char x;
 | 
					   return random_byte() & 1;
 | 
				
			||||||
 | 
					 | 
				
			||||||
   R8(x);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
   return x & 1;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
#endif /* READ_RGB_TO_GRAY || READ_FILLER */
 | 
					#endif /* READ_RGB_TO_GRAY || READ_FILLER */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1511,9 +1498,7 @@ store_read_chunk(png_store *ps, png_bytep pb, const png_size_t max,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
         if (IDAT_pos == IDAT_len)
 | 
					         if (IDAT_pos == IDAT_len)
 | 
				
			||||||
         {
 | 
					         {
 | 
				
			||||||
            png_byte random;
 | 
					            png_byte random = random_byte();
 | 
				
			||||||
 | 
					 | 
				
			||||||
            R8(random);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* Make a new IDAT chunk, if IDAT_len is 0 this is the first IDAT,
 | 
					            /* Make a new IDAT chunk, if IDAT_len is 0 this is the first IDAT,
 | 
				
			||||||
             * if IDAT_size is 0 this is the end.  At present this is set up
 | 
					             * if IDAT_size is 0 this is the end.  At present this is set up
 | 
				
			||||||
@ -1526,7 +1511,7 @@ store_read_chunk(png_store *ps, png_bytep pb, const png_size_t max,
 | 
				
			|||||||
               {
 | 
					               {
 | 
				
			||||||
                  case 0U: IDAT_len = 12U; break; /* 0 bytes */
 | 
					                  case 0U: IDAT_len = 12U; break; /* 0 bytes */
 | 
				
			||||||
                  case 1U: IDAT_len = 13U; break; /* 1 byte */
 | 
					                  case 1U: IDAT_len = 13U; break; /* 1 byte */
 | 
				
			||||||
                  default: R32(IDAT_len);
 | 
					                  default: IDAT_len = random_u32();
 | 
				
			||||||
                           IDAT_len %= IDAT_size;
 | 
					                           IDAT_len %= IDAT_size;
 | 
				
			||||||
                           IDAT_len += 13U; /* 1..IDAT_size bytes */
 | 
					                           IDAT_len += 13U; /* 1..IDAT_size bytes */
 | 
				
			||||||
                           break;
 | 
					                           break;
 | 
				
			||||||
@ -1568,7 +1553,7 @@ store_read_chunk(png_store *ps, png_bytep pb, const png_size_t max,
 | 
				
			|||||||
               /* Middle of IDATs, use 'random' to determine the number of bits
 | 
					               /* Middle of IDATs, use 'random' to determine the number of bits
 | 
				
			||||||
                * to use in the IDAT length.
 | 
					                * to use in the IDAT length.
 | 
				
			||||||
                */
 | 
					                */
 | 
				
			||||||
               R32(IDAT_len);
 | 
					               IDAT_len = random_u32();
 | 
				
			||||||
               IDAT_len &= (1U << (1U + random % ps->IDAT_bits)) - 1U;
 | 
					               IDAT_len &= (1U << (1U + random % ps->IDAT_bits)) - 1U;
 | 
				
			||||||
               if (IDAT_len > IDAT_size)
 | 
					               if (IDAT_len > IDAT_size)
 | 
				
			||||||
                  IDAT_len = IDAT_size;
 | 
					                  IDAT_len = IDAT_size;
 | 
				
			||||||
@ -3721,8 +3706,8 @@ set_random_tRNS(png_structp pp, png_infop pi, const png_byte colour_type,
 | 
				
			|||||||
   {
 | 
					   {
 | 
				
			||||||
      if (bit_depth == 8)
 | 
					      if (bit_depth == 8)
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
         R16(tRNS.red);
 | 
					         tRNS.red = random_u16();
 | 
				
			||||||
         R16(tRNS.green);
 | 
					         tRNS.green = random_u16();
 | 
				
			||||||
         tRNS.blue = tRNS.red ^ tRNS.green;
 | 
					         tRNS.blue = tRNS.red ^ tRNS.green;
 | 
				
			||||||
         tRNS.red &= mask;
 | 
					         tRNS.red &= mask;
 | 
				
			||||||
         tRNS.green &= mask;
 | 
					         tRNS.green &= mask;
 | 
				
			||||||
@ -3731,7 +3716,7 @@ set_random_tRNS(png_structp pp, png_infop pi, const png_byte colour_type,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      else /* bit_depth == 16 */
 | 
					      else /* bit_depth == 16 */
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
         R16(tRNS.red);
 | 
					         tRNS.red = random_u16();
 | 
				
			||||||
         tRNS.green = (png_uint_16)(tRNS.red * 257);
 | 
					         tRNS.green = (png_uint_16)(tRNS.red * 257);
 | 
				
			||||||
         tRNS.blue = (png_uint_16)(tRNS.green * 17);
 | 
					         tRNS.blue = (png_uint_16)(tRNS.green * 17);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@ -3739,7 +3724,7 @@ set_random_tRNS(png_structp pp, png_infop pi, const png_byte colour_type,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
   else
 | 
					   else
 | 
				
			||||||
   {
 | 
					   {
 | 
				
			||||||
      R16(tRNS.gray);
 | 
					      tRNS.gray = random_u16();
 | 
				
			||||||
      tRNS.gray &= mask;
 | 
					      tRNS.gray &= mask;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -7691,7 +7676,7 @@ image_transform_png_set_rgb_to_gray_ini(const image_transform *this,
 | 
				
			|||||||
      png_uint_32 ru;
 | 
					      png_uint_32 ru;
 | 
				
			||||||
      double total;
 | 
					      double total;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      R32_1(ru);
 | 
					      ru = random_u32();
 | 
				
			||||||
      data.green_coefficient = total = (ru & 0xffff) / 65535.;
 | 
					      data.green_coefficient = total = (ru & 0xffff) / 65535.;
 | 
				
			||||||
      ru >>= 16;
 | 
					      ru >>= 16;
 | 
				
			||||||
      data.red_coefficient = (1 - total) * (ru & 0xffff) / 65535.;
 | 
					      data.red_coefficient = (1 - total) * (ru & 0xffff) / 65535.;
 | 
				
			||||||
@ -8619,7 +8604,7 @@ image_transform_png_set_filler_set(const image_transform *this,
 | 
				
			|||||||
    * filler.  The 'filler' value has all 32 bits set, but only bit_depth
 | 
					    * filler.  The 'filler' value has all 32 bits set, but only bit_depth
 | 
				
			||||||
    * will be used.  At this point we don't know bit_depth.
 | 
					    * will be used.  At this point we don't know bit_depth.
 | 
				
			||||||
    */
 | 
					    */
 | 
				
			||||||
   R32(data.filler);
 | 
					   data.filler = random_u32();
 | 
				
			||||||
   data.flags = random_choice();
 | 
					   data.flags = random_choice();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   png_set_filler(pp, data.filler, data.flags);
 | 
					   png_set_filler(pp, data.filler, data.flags);
 | 
				
			||||||
@ -8692,7 +8677,7 @@ image_transform_png_set_add_alpha_set(const image_transform *this,
 | 
				
			|||||||
    * filler.  The 'filler' value has all 32 bits set, but only bit_depth
 | 
					    * filler.  The 'filler' value has all 32 bits set, but only bit_depth
 | 
				
			||||||
    * will be used.  At this point we don't know bit_depth.
 | 
					    * will be used.  At this point we don't know bit_depth.
 | 
				
			||||||
    */
 | 
					    */
 | 
				
			||||||
   R32(data.filler);
 | 
					   data.filler = random_u32();
 | 
				
			||||||
   data.flags = random_choice();
 | 
					   data.flags = random_choice();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   png_set_add_alpha(pp, data.filler, data.flags);
 | 
					   png_set_add_alpha(pp, data.filler, data.flags);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user