Fix #309: gdImageGd2() writes wrong chunk sizes on boundaries

master
Christoph M. Becker 2016-09-23 18:29:52 +02:00
parent 25e18ebce8
commit bb1998a16e
5 changed files with 42 additions and 2 deletions

View File

@ -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);

View File

@ -1,4 +1,5 @@
/bug_289
/bug00309
/gd2_empty_file
/gd2_im2im
/gd2_null

View File

@ -1,5 +1,6 @@
LIST(APPEND TESTS_FILES
bug_289
bug00309
gd2_empty_file
gd2_im2im
gd2_null

View File

@ -1,5 +1,6 @@
libgd_test_programs += \
gd2/bug_289 \
gd2/bug00309 \
gd2/gd2_empty_file \
gd2/php_bug_72339 \
gd2/gd2_read_corrupt

37
tests/gd2/bug00309.c Normal file
View File

@ -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();
}