Fix #383 (amendment)
When reading images in GD or GD2 format, we have to ensure that the transparent color is not set, if it would refer to a non-extant palette entry. We back that up with respective regression tests.master
parent
a15130c6bb
commit
2dbd8f6e66
|
@ -108,10 +108,10 @@ _gdGetColors (gdIOCtx * in, gdImagePtr im, int gd2xFlag)
|
|||
if (!gdGetWord (&im->transparent, in)) {
|
||||
goto fail1;
|
||||
}
|
||||
/* Make sure transparent index is within bounds of the palette. */
|
||||
if (im->transparent >= 256 || im->transparent < 0) {
|
||||
im->transparent = (-1);
|
||||
}
|
||||
}
|
||||
/* Make sure transparent index is within bounds of the palette. */
|
||||
if (!(im->trueColor) && (im->transparent >= im->colorsTotal || im->transparent < 0)) {
|
||||
im->transparent = (-1);
|
||||
}
|
||||
GD2_DBG (printf
|
||||
("Palette had %d colours (T=%d)\n", im->colorsTotal,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/bug00383
|
||||
/gd_im2im
|
||||
/gd_null
|
||||
/gd_num_colors
|
||||
|
|
|
@ -4,6 +4,7 @@ LIST(APPEND TESTS_FILES
|
|||
|
||||
IF(ENABLE_GD_FORMATS)
|
||||
LIST(APPEND TESTS_FILES
|
||||
bug00383
|
||||
gd_null
|
||||
gd_num_colors
|
||||
)
|
||||
|
|
|
@ -3,6 +3,7 @@ libgd_test_programs += \
|
|||
|
||||
if ENABLE_GD_FORMATS
|
||||
libgd_test_programs += \
|
||||
gd/bug00383 \
|
||||
gd/gd_null \
|
||||
gd/gd_num_colors
|
||||
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* Test that invalid transparent colors can't be read
|
||||
*
|
||||
* We're reading a corrupt palette image in GD format, which has only a single
|
||||
* palette entry, but claims that the transparent color would be 1. We check
|
||||
* that the transparency is simply ignored in this case.
|
||||
*
|
||||
* See also <https://github.com/libgd/libgd/issues/383>
|
||||
*/
|
||||
|
||||
|
||||
#include "gd.h"
|
||||
#include "gdtest.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
gdImagePtr im;
|
||||
FILE *fp;
|
||||
|
||||
fp = gdTestFileOpen2("gd", "bug00383.gd");
|
||||
gdTestAssert(fp != NULL);
|
||||
im = gdImageCreateFromGd(fp);
|
||||
gdTestAssert(im != NULL);
|
||||
fclose(fp);
|
||||
|
||||
gdTestAssert(gdImageGetTransparent(im) == -1);
|
||||
|
||||
gdImageDestroy(im);
|
||||
|
||||
return gdNumFailures();
|
||||
}
|
Binary file not shown.
|
@ -2,6 +2,7 @@
|
|||
/bug00209
|
||||
/bug00309
|
||||
/bug00354
|
||||
/bug00383
|
||||
/gd2_empty_file
|
||||
/gd2_im2im
|
||||
/gd2_null
|
||||
|
|
|
@ -5,6 +5,7 @@ LIST(APPEND TESTS_FILES
|
|||
bug00209
|
||||
bug00309
|
||||
bug00354
|
||||
bug00383
|
||||
gd2_empty_file
|
||||
php_bug_72339
|
||||
gd2_null
|
||||
|
|
|
@ -5,6 +5,7 @@ libgd_test_programs += \
|
|||
gd2/bug00209 \
|
||||
gd2/bug00309 \
|
||||
gd2/bug00354 \
|
||||
gd2/bug00383 \
|
||||
gd2/gd2_empty_file \
|
||||
gd2/php_bug_72339 \
|
||||
gd2/gd2_null \
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* Test that invalid transparent colors can't be read
|
||||
*
|
||||
* We're reading a corrupt palette image in GD2 format, which has only a single
|
||||
* palette entry, but claims that the transparent color would be 1. We check
|
||||
* that the transparency is simply ignored in this case.
|
||||
*
|
||||
* See also <https://github.com/libgd/libgd/issues/383>
|
||||
*/
|
||||
|
||||
|
||||
#include "gd.h"
|
||||
#include "gdtest.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
gdImagePtr im;
|
||||
FILE *fp;
|
||||
|
||||
fp = gdTestFileOpen2("gd2", "bug00383.gd2");
|
||||
gdTestAssert(fp != NULL);
|
||||
im = gdImageCreateFromGd2(fp);
|
||||
gdTestAssert(im != NULL);
|
||||
fclose(fp);
|
||||
|
||||
gdTestAssert(gdImageGetTransparent(im) == -1);
|
||||
|
||||
gdImageDestroy(im);
|
||||
|
||||
return gdNumFailures();
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue