summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Randers-Pehrson <glennrp at users.sourceforge.net>2016-05-31 10:05:56 -0500
committerGlenn Randers-Pehrson <glennrp at users.sourceforge.net>2016-05-31 10:05:56 -0500
commitc1ac308d12888bc2442eef29123c1d719261c25f (patch)
treee8e3bb3837ed9c9403ea231f2110113921f4fe60
parent94727db1eaf6181eacecf544bbdb36e1030db136 (diff)
downloadlibpng-c1ac308d12888bc2442eef29123c1d719261c25f.tar.gz
[libpng15] Merge contrib/libtests/pngvalid.c with libpng16
-rw-r--r--ANNOUNCE4
-rw-r--r--CHANGES2
-rw-r--r--contrib/libtests/pngvalid.c77
3 files changed, 34 insertions, 49 deletions
diff --git a/ANNOUNCE b/ANNOUNCE
index 15dab0fa3..e49e2abe0 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -1,5 +1,5 @@
-Libpng 1.5.28beta01 - May 29, 2016
+Libpng 1.5.28beta01 - May 31, 2016
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.
@@ -26,7 +26,7 @@ Other information:
Changes since the last public release (1.5.27):
-version 1.5.28beta01 [May 29, 2016]
+version 1.5.28beta01 [May 31, 2016]
Merge with current libpng16 pngvalid.c
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
diff --git a/CHANGES b/CHANGES
index 01ffafccb..1c39d45f8 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4496,7 +4496,7 @@ version 1.5.27rc01 [May 14, 2016]
version 1.5.27 [May 26, 2016]
No changes.
-version 1.5.28beta01 [May 29, 2016]
+version 1.5.28beta01 [May 31, 2016]
Merge with current libpng16 pngvalid.c
Send comments/corrections/commendations to png-mng-implement at lists.sf.net
diff --git a/contrib/libtests/pngvalid.c b/contrib/libtests/pngvalid.c
index 8b8fbda8d..b21390ba2 100644
--- a/contrib/libtests/pngvalid.c
+++ b/contrib/libtests/pngvalid.c
@@ -308,38 +308,33 @@ randomize(void *pv, size_t size)
#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;
-
- for (i=0; i<count; ++i)
- {
- unsigned char b2[2];
- randomize(b2, sizeof b2);
- *p16++ = png_get_uint_16(b2);
- }
+ unsigned char b1[1];
+ randomize(b1, sizeof b1);
+ return b1[0];
}
+#endif /* READ */
-#define R16(this) r16(&(this), (sizeof (this))/(sizeof (png_uint_16)))
-#define R16_1(this) r16(&(this), (size_t) 1U)
+static png_uint_16
+random_u16(void)
+{
+ unsigned char b2[2];
+ randomize(b2, sizeof b2);
+ return png_get_uint_16(b2);
+}
#if defined PNG_READ_RGB_TO_GRAY_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];
- randomize(b4, sizeof b4);
- *p32++ = png_get_uint_32(b4);
- }
+ unsigned char b4[4];
+ randomize(b4, sizeof 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 || WRITE_tRNS || WRITE_FILTER */
@@ -349,11 +344,7 @@ static void r32(png_uint_32p p32, size_t count)
static unsigned int
random_mod(unsigned int max)
{
- png_uint_16 x;
-
- R16_1(x);
-
- return x % max; /* 0 .. max-1 */
+ return random_u16() % max; /* 0 .. max-1 */
}
#endif /* READ_TRANSFORMS || WRITE_FILTER */
@@ -362,11 +353,7 @@ random_mod(unsigned int max)
static int
random_choice(void)
{
- unsigned char x;
-
- R8(x);
-
- return x & 1;
+ return random_byte() & 1;
}
#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)
{
- png_byte random;
-
- R8(random);
+ png_byte random = random_byte();
/* 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
@@ -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 1U: IDAT_len = 13U; break; /* 1 byte */
- default: R32(IDAT_len);
+ default: IDAT_len = random_u32();
IDAT_len %= IDAT_size;
IDAT_len += 13U; /* 1..IDAT_size bytes */
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
* to use in the IDAT length.
*/
- R32(IDAT_len);
+ IDAT_len = random_u32();
IDAT_len &= (1U << (1U + random % ps->IDAT_bits)) - 1U;
if (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)
{
- R16(tRNS.red);
- R16(tRNS.green);
+ tRNS.red = random_u16();
+ tRNS.green = random_u16();
tRNS.blue = tRNS.red ^ tRNS.green;
tRNS.red &= 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 */
{
- R16(tRNS.red);
+ tRNS.red = random_u16();
tRNS.green = (png_uint_16)(tRNS.red * 257);
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
{
- R16(tRNS.gray);
+ tRNS.gray = random_u16();
tRNS.gray &= mask;
}
@@ -7691,7 +7676,7 @@ image_transform_png_set_rgb_to_gray_ini(const image_transform *this,
png_uint_32 ru;
double total;
- R32_1(ru);
+ ru = random_u32();
data.green_coefficient = total = (ru & 0xffff) / 65535.;
ru >>= 16;
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
* will be used. At this point we don't know bit_depth.
*/
- R32(data.filler);
+ data.filler = random_u32();
data.flags = random_choice();
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
* will be used. At this point we don't know bit_depth.
*/
- R32(data.filler);
+ data.filler = random_u32();
data.flags = random_choice();
png_set_add_alpha(pp, data.filler, data.flags);