Fix #309: gdImageGd2() writes wrong chunk sizes on boundaries
parent
25e18ebce8
commit
bb1998a16e
|
@ -938,8 +938,8 @@ _gdImageGd2 (gdImagePtr im, gdIOCtx * out, int cs, int fmt)
|
|||
};
|
||||
|
||||
/* Work out number of chunks. */
|
||||
ncx = im->sx / cs + 1;
|
||||
ncy = im->sy / cs + 1;
|
||||
ncx = (im->sx + cs - 1) / cs;
|
||||
ncy = (im->sy + cs - 1) / cs;
|
||||
|
||||
/* Write the standard header. */
|
||||
_gd2PutHeader (im, out, cs, fmt, ncx, ncy);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/bug_289
|
||||
/bug00309
|
||||
/gd2_empty_file
|
||||
/gd2_im2im
|
||||
/gd2_null
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
LIST(APPEND TESTS_FILES
|
||||
bug_289
|
||||
bug00309
|
||||
gd2_empty_file
|
||||
gd2_im2im
|
||||
gd2_null
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
libgd_test_programs += \
|
||||
gd2/bug_289 \
|
||||
gd2/bug00309 \
|
||||
gd2/gd2_empty_file \
|
||||
gd2/php_bug_72339 \
|
||||
gd2/gd2_read_corrupt
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* Regression test for <https://github.com/libgd/libgd/issues/309>.
|
||||
*
|
||||
* We test that an image with 64x64 pixels reports only a single chunk in the
|
||||
* GD2 image header when the chunk size is 64.
|
||||
*/
|
||||
|
||||
|
||||
#include "gd.h"
|
||||
#include "gdtest.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
gdImagePtr im;
|
||||
unsigned char *buf;
|
||||
int size, word;
|
||||
|
||||
im = gdImageCreate(64, 64);
|
||||
gdImageColorAllocate(im, 0, 0, 0);
|
||||
|
||||
buf = gdImageGd2Ptr(im, 64, 1, &size);
|
||||
|
||||
gdImageDestroy(im);
|
||||
|
||||
word = buf[10] << 8 | buf[11];
|
||||
gdTestAssertMsg(word == 64, "chunk size is %d, but expected 64\n", word);
|
||||
word = buf[14] << 8 | buf[15];
|
||||
gdTestAssertMsg(word == 1, "x chunk count is %d, but expected 1\n", word);
|
||||
word = buf[16] << 8 | buf[17];
|
||||
gdTestAssertMsg(word == 1, "y chunk count is %d, but expected 1\n", word);
|
||||
gdTestAssertMsg(size == 5145, "file size is %d, but expected 5145\n", size);
|
||||
|
||||
gdFree(buf);
|
||||
|
||||
return gdNumFailures();
|
||||
}
|
Loading…
Reference in New Issue