mirror of
https://git.code.sf.net/p/libpng/code.git
synced 2025-07-10 18:04:09 +02:00
[master] Fixed atomicity of chunk header serialization (Cosmin)
and added test for io_state in pngtest.c (Cosmin)
This commit is contained in:
parent
1f5a0b9fa6
commit
453ceae85f
4
ANNOUNCE
4
ANNOUNCE
@ -49,6 +49,10 @@ version 1.4.5rc01 [November 19, 2010]
|
|||||||
version 1.4.5rc02 [November 20, 2010]
|
version 1.4.5rc02 [November 20, 2010]
|
||||||
Removed some extraneous parentheses that appeared in pngrutil.c of
|
Removed some extraneous parentheses that appeared in pngrutil.c of
|
||||||
libpng-1.4.3bet01
|
libpng-1.4.3bet01
|
||||||
|
Revised png_get_uint_32, png_get_int_32, png_get_uint_16 (Cosmin)
|
||||||
|
Moved reading of file signature into png_read_sig (Cosmin)
|
||||||
|
Fixed atomicity of chunk header serialization (Cosmin)
|
||||||
|
Added test for io_state in pngtest.c (Cosmin)
|
||||||
|
|
||||||
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
|
||||||
|
4
CHANGES
4
CHANGES
@ -2702,9 +2702,11 @@ version 1.4.5rc01 [November 19, 2010]
|
|||||||
|
|
||||||
version 1.4.5rc02 [November 20, 2010]
|
version 1.4.5rc02 [November 20, 2010]
|
||||||
Removed some extraneous parentheses that appeared in pngrutil.c of
|
Removed some extraneous parentheses that appeared in pngrutil.c of
|
||||||
libpng-1.4.3bet01 (Cosmin)
|
libpng-1.4.3bet01
|
||||||
Revised png_get_uint_32, png_get_int_32, png_get_uint_16 (Cosmin)
|
Revised png_get_uint_32, png_get_int_32, png_get_uint_16 (Cosmin)
|
||||||
Moved reading of file signature into png_read_sig (Cosmin)
|
Moved reading of file signature into png_read_sig (Cosmin)
|
||||||
|
Fixed atomicity of chunk header serialization (Cosmin)
|
||||||
|
Added test for io_state in pngtest.c (Cosmin)
|
||||||
|
|
||||||
*/ }
|
*/ }
|
||||||
#endif
|
#endif
|
||||||
|
1
png.h
1
png.h
@ -2657,6 +2657,7 @@ PNG_EXPORT(png_bytep,png_get_io_chunk_name)
|
|||||||
? -((png_int_32)((png_get_uint_32(buf) ^ 0xffffffffL) + 1)) \
|
? -((png_int_32)((png_get_uint_32(buf) ^ 0xffffffffL) + 1)) \
|
||||||
: (png_int_32)png_get_uint_32(buf)))
|
: (png_int_32)png_get_uint_32(buf)))
|
||||||
#else
|
#else
|
||||||
|
PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
|
||||||
PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
|
PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
|
||||||
#ifdef PNG_GET_INT_32_SUPPORTED
|
#ifdef PNG_GET_INT_32_SUPPORTED
|
||||||
PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
|
PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
|
||||||
|
66
pngtest.c
66
pngtest.c
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
/* pngtest.c - a simple test program to test libpng
|
/* pngtest.c - a simple test program to test libpng
|
||||||
*
|
*
|
||||||
* Last changed in libpng 1.4.1 [February 25, 2010]
|
* Last changed in libpng 1.4.5 [$RDATE]
|
||||||
* Copyright (c) 1998-2010 Glenn Randers-Pehrson
|
* Copyright (c) 1998-2010 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.)
|
||||||
@ -263,6 +263,48 @@ static int wrote_question = 0;
|
|||||||
* than changing the library.
|
* than changing the library.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef PNG_IO_STATE_SUPPORTED
|
||||||
|
void
|
||||||
|
pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
|
||||||
|
png_uint_32 io_op);
|
||||||
|
void
|
||||||
|
pngtest_check_io_state(png_structp png_ptr, png_size_t data_length,
|
||||||
|
png_uint_32 io_op)
|
||||||
|
{
|
||||||
|
png_uint_32 io_state = png_get_io_state(png_ptr);
|
||||||
|
int err = 0;
|
||||||
|
|
||||||
|
/* Check if the current operation (reading / writing) is as expected. */
|
||||||
|
if ((io_state & PNG_IO_MASK_OP) != io_op)
|
||||||
|
png_error(png_ptr, "Incorrect operation in I/O state");
|
||||||
|
|
||||||
|
/* Check if the buffer size specific to the current location
|
||||||
|
* (file signature / header / data / crc) is as expected.
|
||||||
|
*/
|
||||||
|
switch (io_state & PNG_IO_MASK_LOC)
|
||||||
|
{
|
||||||
|
case PNG_IO_SIGNATURE:
|
||||||
|
if (data_length > 8)
|
||||||
|
err = 1;
|
||||||
|
break;
|
||||||
|
case PNG_IO_CHUNK_HDR:
|
||||||
|
if (data_length != 8)
|
||||||
|
err = 1;
|
||||||
|
break;
|
||||||
|
case PNG_IO_CHUNK_DATA:
|
||||||
|
break; /* no restrictions here */
|
||||||
|
case PNG_IO_CHUNK_CRC:
|
||||||
|
if (data_length != 4)
|
||||||
|
err = 1;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
err = 1; /* uninitialized */
|
||||||
|
}
|
||||||
|
if (err)
|
||||||
|
png_error(png_ptr, "Bad I/O state or buffer size");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef USE_FAR_KEYWORD
|
#ifndef USE_FAR_KEYWORD
|
||||||
static void
|
static void
|
||||||
pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||||
@ -281,8 +323,12 @@ pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
|||||||
|
|
||||||
if (check != length)
|
if (check != length)
|
||||||
{
|
{
|
||||||
png_error(png_ptr, "Read Error!");
|
png_error(png_ptr, "Read Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PNG_IO_STATE_SUPPORTED
|
||||||
|
pngtest_check_io_state(png_ptr, length, PNG_IO_READING);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* This is the model-independent version. Since the standard I/O library
|
/* This is the model-independent version. Since the standard I/O library
|
||||||
@ -328,7 +374,11 @@ pngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
|||||||
while (remaining != 0);
|
while (remaining != 0);
|
||||||
}
|
}
|
||||||
if (check != length)
|
if (check != length)
|
||||||
png_error(png_ptr, "read Error");
|
png_error(png_ptr, "Read Error");
|
||||||
|
|
||||||
|
#ifdef PNG_IO_STATE_SUPPORTED
|
||||||
|
pngtest_check_io_state(png_ptr, length, PNG_IO_READING);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif /* USE_FAR_KEYWORD */
|
#endif /* USE_FAR_KEYWORD */
|
||||||
|
|
||||||
@ -359,6 +409,10 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
|||||||
{
|
{
|
||||||
png_error(png_ptr, "Write Error");
|
png_error(png_ptr, "Write Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PNG_IO_STATE_SUPPORTED
|
||||||
|
pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
/* This is the model-independent version. Since the standard I/O library
|
/* This is the model-independent version. Since the standard I/O library
|
||||||
@ -407,6 +461,10 @@ pngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
|||||||
{
|
{
|
||||||
png_error(png_ptr, "Write Error");
|
png_error(png_ptr, "Write Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef PNG_IO_STATE_SUPPORTED
|
||||||
|
pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif /* USE_FAR_KEYWORD */
|
#endif /* USE_FAR_KEYWORD */
|
||||||
|
|
||||||
@ -1629,4 +1687,4 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Generate a compiler error if there is an old png.h in the search path. */
|
/* Generate a compiler error if there is an old png.h in the search path. */
|
||||||
typedef version_1_4_5rc01 your_png_h_is_not_version_1_4_5rc01;
|
typedef version_1_4_5rc02 your_png_h_is_not_version_1_4_5rc02;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user