Fix #109: XBM reading fails with printed error
When calculating the number of required bytes of an XBM image, we have to take the line padding into account.master
parent
73aec753f5
commit
082c544483
|
@ -108,7 +108,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromXbm(FILE * fd)
|
|||
max_bit = 32768;
|
||||
}
|
||||
if (max_bit) {
|
||||
bytes = (width * height / 8) + 1;
|
||||
bytes = (width + 7) / 8 * height;
|
||||
if (!bytes) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
/github_bug_109
|
||||
/github_bug_170
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
LIST(APPEND TESTS_FILES
|
||||
github_bug_109
|
||||
github_bug_170
|
||||
)
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
libgd_test_programs += \
|
||||
xbm/github_bug_109 \
|
||||
xbm/github_bug_170
|
||||
|
||||
EXTRA_DIST += \
|
||||
xbm/CMakeLists.txt
|
||||
xbm/CMakeLists.txt \
|
||||
xbm/github_bug_109.xbm \
|
||||
xbm/github_bug_109_exp.png
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* Test reading of XBM images with a width that is not a multiple of 8
|
||||
*
|
||||
* We're reading such an XBM image, and check that we got what we've expected,
|
||||
* instead of an error message.
|
||||
*
|
||||
* See also <https://github.com/libgd/libgd/issues/109>.
|
||||
*/
|
||||
|
||||
|
||||
#include "gd.h"
|
||||
#include "gdtest.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
gdImagePtr im;
|
||||
FILE *fp;
|
||||
char *path;
|
||||
|
||||
fp = gdTestFileOpen2("xbm", "github_bug_109.xbm");
|
||||
im = gdImageCreateFromXbm(fp);
|
||||
fclose(fp);
|
||||
gdTestAssert(im != NULL);
|
||||
gdTestAssert(gdImageGetTrueColorPixel(im, 0, 0) == 0);
|
||||
gdTestAssert(gdImageGetTrueColorPixel(im, 0, 1) == 0xffffff);
|
||||
|
||||
path = gdTestFilePath2("xbm", "github_bug_109_exp.png");
|
||||
gdAssertImageEqualsToFile(path, im);
|
||||
gdFree(path);
|
||||
|
||||
gdImageDestroy(im);
|
||||
|
||||
return gdNumFailures();
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
#define test_width 10
|
||||
#define test_height 10
|
||||
static unsigned char test_bits[] = {
|
||||
0xFF, 0x03, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00,
|
||||
0xFF, 0x03, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00};
|
Binary file not shown.
After Width: | Height: | Size: 111 B |
Loading…
Reference in New Issue