From ad547a6b5986815fda458221149728d9d9ab1d87 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 25 Feb 2021 19:22:25 +0000 Subject: restore Build,TODO from r57911 git-svn-id: svn://tug.org/texlive/trunk@57915 c570f23f-e606-0410-a88d-b1316a301751 --- .../libs/gd/libgd-src/tests/gd2/CMakeLists.txt | 27 +++++++++ .../libs/gd/libgd-src/tests/gd2/Makemodule.am | 37 ++++++++++++ .../source/libs/gd/libgd-src/tests/gd2/bug00209.c | 26 +++++++++ .../libs/gd/libgd-src/tests/gd2/bug00209.gd2 | Bin 0 -> 1050 bytes .../source/libs/gd/libgd-src/tests/gd2/bug00309.c | 37 ++++++++++++ .../source/libs/gd/libgd-src/tests/gd2/bug00354.c | 30 ++++++++++ .../libs/gd/libgd-src/tests/gd2/bug00354a.gd2 | Bin 0 -> 92 bytes .../libs/gd/libgd-src/tests/gd2/bug00354b.gd2 | Bin 0 -> 18 bytes .../source/libs/gd/libgd-src/tests/gd2/bug00383.c | 32 +++++++++++ .../libs/gd/libgd-src/tests/gd2/bug00383.gd2 | Bin 0 -> 1113 bytes Build/source/libs/gd/libgd-src/tests/gd2/bug_289.c | 35 ++++++++++++ .../libs/gd/libgd-src/tests/gd2/conv_gd2_exp.gd2 | 0 .../libs/gd/libgd-src/tests/gd2/conv_test.gd2 | Bin 0 -> 423 bytes .../libs/gd/libgd-src/tests/gd2/conv_test_exp.png | Bin 0 -> 87 bytes .../libgd-src/tests/gd2/createimagefromgd2part.c | 35 ++++++++++++ .../tests/gd2/createimagefromgd2partptr.c | 59 ++++++++++++++++++++ Build/source/libs/gd/libgd-src/tests/gd2/empty.gd2 | 0 .../libs/gd/libgd-src/tests/gd2/gd2_empty_file.c | 19 +++++++ .../source/libs/gd/libgd-src/tests/gd2/gd2_im2im.c | 62 +++++++++++++++++++++ .../source/libs/gd/libgd-src/tests/gd2/gd2_null.c | 14 +++++ .../source/libs/gd/libgd-src/tests/gd2/gd2_read.c | 59 ++++++++++++++++++++ .../libs/gd/libgd-src/tests/gd2/gd2_read_corrupt.c | 28 ++++++++++ .../libs/gd/libgd-src/tests/gd2/invalid_header.gd2 | Bin 0 -> 512 bytes .../gd/libgd-src/tests/gd2/invalid_neg_size.gd2 | Bin 0 -> 1676 bytes .../libs/gd/libgd-src/tests/gd2/php_bug_72339.c | 36 ++++++++++++ .../gd/libgd-src/tests/gd2/too_few_image_data.c | 22 ++++++++ .../gd/libgd-src/tests/gd2/too_few_image_data.gd2 | Bin 0 -> 1050 bytes 27 files changed, 558 insertions(+) create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/CMakeLists.txt create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/Makemodule.am create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/bug00209.c create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/bug00209.gd2 create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/bug00309.c create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/bug00354.c create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/bug00354a.gd2 create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/bug00354b.gd2 create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/bug00383.c create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/bug00383.gd2 create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/bug_289.c create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/conv_gd2_exp.gd2 create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/conv_test.gd2 create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/conv_test_exp.png create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/createimagefromgd2part.c create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/createimagefromgd2partptr.c create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/empty.gd2 create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/gd2_empty_file.c create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/gd2_im2im.c create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/gd2_null.c create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/gd2_read.c create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/gd2_read_corrupt.c create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/invalid_header.gd2 create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/invalid_neg_size.gd2 create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/php_bug_72339.c create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/too_few_image_data.c create mode 100644 Build/source/libs/gd/libgd-src/tests/gd2/too_few_image_data.gd2 (limited to 'Build/source/libs/gd/libgd-src/tests/gd2') diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/CMakeLists.txt b/Build/source/libs/gd/libgd-src/tests/gd2/CMakeLists.txt new file mode 100644 index 00000000000..cc188ca043d --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/CMakeLists.txt @@ -0,0 +1,27 @@ +IF(ENABLE_GD_FORMATS) +IF(ZLIB_FOUND) +LIST(APPEND TESTS_FILES + bug_289 + bug00209 + bug00309 + bug00354 + bug00383 + createimagefromgd2part + createimagefromgd2partptr + gd2_empty_file + php_bug_72339 + gd2_null + gd2_read_corrupt + too_few_image_data + gd2_im2im +) + +IF(PNG_FOUND) +LIST(APPEND TESTS_FILES + gd2_read +) +ENDIF(PNG_FOUND) +ENDIF(ZLIB_FOUND) +ENDIF(ENABLE_GD_FORMATS) + +ADD_GD_TESTS() diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/Makemodule.am b/Build/source/libs/gd/libgd-src/tests/gd2/Makemodule.am new file mode 100644 index 00000000000..5cd29e6f7f9 --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/Makemodule.am @@ -0,0 +1,37 @@ +if ENABLE_GD_FORMATS +if HAVE_LIBZ +libgd_test_programs += \ + gd2/bug_289 \ + gd2/bug00209 \ + gd2/bug00309 \ + gd2/bug00354 \ + gd2/bug00383 \ + gd2/createimagefromgd2part \ + gd2/createimagefromgd2partptr \ + gd2/gd2_empty_file \ + gd2/php_bug_72339 \ + gd2/gd2_null \ + gd2/gd2_read_corrupt \ + gd2/too_few_image_data \ + gd2/gd2_im2im + +if HAVE_LIBPNG +libgd_test_programs += \ + gd2/gd2_read +endif +endif +endif + +EXTRA_DIST += \ + gd2/CMakeLists.txt \ + gd2/bug00209.gd2 \ + gd2/bug00354a.gd2 \ + gd2/bug00354b.gd2 \ + gd2/bug00383.gd2 \ + gd2/conv_gd2_exp.gd2 \ + gd2/conv_test.gd2 \ + gd2/conv_test_exp.png \ + gd2/empty.gd2 \ + gd2/invalid_header.gd2 \ + gd2/invalid_neg_size.gd2 \ + gd2/too_few_image_data.gd2 diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/bug00209.c b/Build/source/libs/gd/libgd-src/tests/gd2/bug00209.c new file mode 100644 index 00000000000..7904d01fcf5 --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/bug00209.c @@ -0,0 +1,26 @@ +/** + * Regression test for github issue #209 + * + * We're testing that bug00209.gd2, which claims to have 12336 x 48 pixels, but + * actually provides not enough image data, is rejected, i.e. that + * gdImageCreateFromGd2() returns NULL + * + * See . + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + + fp = gdTestFileOpen2("gd2", "bug00209.gd2"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromGd2(fp); + gdTestAssert(im == NULL); + fclose(fp); + + return gdNumFailures(); +} diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/bug00209.gd2 b/Build/source/libs/gd/libgd-src/tests/gd2/bug00209.gd2 new file mode 100644 index 00000000000..1c797d1acfa Binary files /dev/null and b/Build/source/libs/gd/libgd-src/tests/gd2/bug00209.gd2 differ diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/bug00309.c b/Build/source/libs/gd/libgd-src/tests/gd2/bug00309.c new file mode 100644 index 00000000000..b649cdc2d63 --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/bug00309.c @@ -0,0 +1,37 @@ +/** + * Regression test for . + * + * 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(); +} diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/bug00354.c b/Build/source/libs/gd/libgd-src/tests/gd2/bug00354.c new file mode 100644 index 00000000000..1bce091ab09 --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/bug00354.c @@ -0,0 +1,30 @@ +/** + * We're testing GD2 image files which report illegal chunk counts. These should + * not cause integer overflows or other issues, but instead simply fail to be + * loaded. + * + * See also . + */ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + + fp = gdTestFileOpen2("gd2", "bug00354a.gd2"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromGd2(fp); + gdTestAssert(im == NULL); + fclose(fp); + + fp = gdTestFileOpen2("gd2", "bug00354b.gd2"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromGd2(fp); + gdTestAssert(im == NULL); + fclose(fp); + + return gdNumFailures(); +} diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/bug00354a.gd2 b/Build/source/libs/gd/libgd-src/tests/gd2/bug00354a.gd2 new file mode 100644 index 00000000000..5060bfde3aa Binary files /dev/null and b/Build/source/libs/gd/libgd-src/tests/gd2/bug00354a.gd2 differ diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/bug00354b.gd2 b/Build/source/libs/gd/libgd-src/tests/gd2/bug00354b.gd2 new file mode 100644 index 00000000000..8600126becb Binary files /dev/null and b/Build/source/libs/gd/libgd-src/tests/gd2/bug00354b.gd2 differ diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/bug00383.c b/Build/source/libs/gd/libgd-src/tests/gd2/bug00383.c new file mode 100644 index 00000000000..dbbf661aa58 --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/bug00383.c @@ -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 + */ + + +#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(); +} diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/bug00383.gd2 b/Build/source/libs/gd/libgd-src/tests/gd2/bug00383.gd2 new file mode 100644 index 00000000000..dcb164de288 Binary files /dev/null and b/Build/source/libs/gd/libgd-src/tests/gd2/bug00383.gd2 differ diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/bug_289.c b/Build/source/libs/gd/libgd-src/tests/gd2/bug_289.c new file mode 100644 index 00000000000..9ca03cc1ee1 --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/bug_289.c @@ -0,0 +1,35 @@ +/** + * Passing an unrecognized format to gdImageGd2() should result in + * GD2_FMT_TRUECOLOR_COMPRESSED for truecolor images. + * + * See . + */ + +#include "gd.h" +#include "gdtest.h" + + +#define GD2_FMT_UNRECOGNIZED 0 +#define GD2_FMT_TRUECOLOR_COMPRESSED 4 + +#define MSG "expected %s byte to be %d, but got %d\n" + + +int main() +{ + gdImagePtr im; + char *buffer; + int size; + + im = gdImageCreateTrueColor(10, 10); + gdTestAssert(im != NULL); + buffer = (char *) gdImageGd2Ptr(im, 128, GD2_FMT_UNRECOGNIZED, &size); + gdTestAssert(buffer != NULL); + gdImageDestroy(im); + gdTestAssertMsg(buffer[12] == 0, MSG, "1st", 0, buffer[12]); + gdTestAssertMsg(buffer[13] == GD2_FMT_TRUECOLOR_COMPRESSED, MSG, "2nd", GD2_FMT_TRUECOLOR_COMPRESSED, buffer[13]); + + gdFree(buffer); + + return gdNumFailures(); +} diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/conv_gd2_exp.gd2 b/Build/source/libs/gd/libgd-src/tests/gd2/conv_gd2_exp.gd2 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/conv_test.gd2 b/Build/source/libs/gd/libgd-src/tests/gd2/conv_test.gd2 new file mode 100644 index 00000000000..1c64b46d9ae Binary files /dev/null and b/Build/source/libs/gd/libgd-src/tests/gd2/conv_test.gd2 differ diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/conv_test_exp.png b/Build/source/libs/gd/libgd-src/tests/gd2/conv_test_exp.png new file mode 100644 index 00000000000..b4bc3fad9f4 Binary files /dev/null and b/Build/source/libs/gd/libgd-src/tests/gd2/conv_test_exp.png differ diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/createimagefromgd2part.c b/Build/source/libs/gd/libgd-src/tests/gd2/createimagefromgd2part.c new file mode 100644 index 00000000000..0c81ba6235b --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/createimagefromgd2part.c @@ -0,0 +1,35 @@ +/** + *Base test for gdImageCreateFromGd2Part() + */ +#include "gd.h" +#include "gdtest.h" +#include +#include + +int main() +{ + gdImagePtr im; + FILE *p; + int expected_color = 0xffffff; + int actual_color = 0; + + p = gdTestFileOpen2("gd2", "conv_test.gd2"); + + if (!p) { + gdTestErrorMsg("failed, connot open gd2 file: conv_test.gd2"); + return 1; + } + + im = gdImageCreateFromGd2Part(p, 3, 3, 3, 3); + fclose(p); + + if (!im) { + return 1; + } + + actual_color = gdImageGetPixel(im, 2, 2); + gdImageDestroy(im); + gdTestAssert(expected_color == actual_color); + + return gdNumFailures(); +} diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/createimagefromgd2partptr.c b/Build/source/libs/gd/libgd-src/tests/gd2/createimagefromgd2partptr.c new file mode 100644 index 00000000000..e432874667f --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/createimagefromgd2partptr.c @@ -0,0 +1,59 @@ +/** + * Base test for gdImageCreateFromGd2PartPtr() + */ +#include "gd.h" +#include "gdtest.h" +#include + +int main() +{ + FILE *p; + gdImagePtr im, partim; + void *pg; + int size = 0; + int status = 0; + int actual_color = 0; + int expected_color = 0xffffff; + + p = gdTestFileOpen2("gd2", "conv_test.gd2"); + if (!p) { + gdTestErrorMsg("failed, cannot open gd2 file:conv_test.gd2"); + return 1; + } + + im = gdImageCreateFromGd2(p); + fclose(p); + + if (!im) { + gdTestErrorMsg("failed, cannot create gd2 file."); + return 1; + } + + pg = gdImageGd2Ptr(im, (GD2_CHUNKSIZE_MIN + GD2_CHUNKSIZE_MAX) / 2, GD2_FMT_COMPRESSED, &size); + if (!pg) { + status = 1; + goto done1; + } + + if (size <= 0) { + status = 1; + goto done0; + } + + partim = gdImageCreateFromGd2PartPtr(size, pg, 3, 3, 3, 3); + if (!partim) { + status = 1; + goto done0; + } + + actual_color = gdImageGetPixel(partim, 2, 2); + status = (expected_color == actual_color) ? 0 : 1; + gdImageDestroy(partim); + +done0: + gdFree(pg); +done1: + gdImageDestroy(im); + + return status; +} diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/empty.gd2 b/Build/source/libs/gd/libgd-src/tests/gd2/empty.gd2 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/gd2_empty_file.c b/Build/source/libs/gd/libgd-src/tests/gd2/gd2_empty_file.c new file mode 100644 index 00000000000..9b1c5b2e1b5 --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/gd2_empty_file.c @@ -0,0 +1,19 @@ +#include "gd.h" +#include +#include +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp = gdTestFileOpen("gd2/empty.gd2"); + im = gdImageCreateFromGd2(fp); + fclose(fp); + + if (!im) { + return 0; + } else { + gdImageDestroy(im); + return 1; + } +} diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/gd2_im2im.c b/Build/source/libs/gd/libgd-src/tests/gd2/gd2_im2im.c new file mode 100644 index 00000000000..02a44206554 --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/gd2_im2im.c @@ -0,0 +1,62 @@ +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr src, dst; + int r, g, b; + void *p; + int size = 0; + int status = 0; + CuTestImageResult result = {0, 0}; + + src = gdImageCreate(100, 100); + if (src == NULL) { + gdTestErrorMsg("could not create src\n"); + return 1; + } + r = gdImageColorAllocate(src, 0xFF, 0, 0); + g = gdImageColorAllocate(src, 0, 0xFF, 0); + b = gdImageColorAllocate(src, 0, 0, 0xFF); + gdImageFilledRectangle(src, 0, 0, 99, 99, r); + gdImageRectangle(src, 20, 20, 79, 79, g); + gdImageEllipse(src, 70, 25, 30, 20, b); + +#define OUTPUT_GD2(x) do { \ + FILE *fp = gdTestTempFp(); \ + gdImageGd2(x, fp, (GD2_CHUNKSIZE_MIN+GD2_CHUNKSIZE_MAX)/2, GD2_FMT_COMPRESSED); \ + fclose(fp); \ + } while (0) + + OUTPUT_GD2(src); + p = gdImageGd2Ptr(src, (GD2_CHUNKSIZE_MIN+GD2_CHUNKSIZE_MAX)/2, GD2_FMT_COMPRESSED, &size); + if (p == NULL) { + status = 1; + gdTestErrorMsg("p is null\n"); + goto door0; + } + if (size <= 0) { + status = 1; + gdTestErrorMsg("size is non-positive\n"); + goto door1; + } + + dst = gdImageCreateFromGd2Ptr(size, p); + if (dst == NULL) { + status = 1; + gdTestErrorMsg("could not create dst\n"); + goto door1; + } + OUTPUT_GD2(dst); + gdTestImageDiff(src, dst, NULL, &result); + if (result.pixels_changed > 0) { + status = 1; + gdTestErrorMsg("pixels changed: %d\n", result.pixels_changed); + } + gdImageDestroy(dst); +door1: + gdFree(p); +door0: + gdImageDestroy(src); + return status; +} diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/gd2_null.c b/Build/source/libs/gd/libgd-src/tests/gd2/gd2_null.c new file mode 100644 index 00000000000..6c8fc96caae --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/gd2_null.c @@ -0,0 +1,14 @@ +#include "gd.h" + +int main() +{ + gdImagePtr im; + + im = gdImageCreateFromGd2(NULL); + if (im != NULL) { + gdImageDestroy(im); + return 1; + } + gdImageGd2(im, NULL, 0, GD2_FMT_RAW); /* noop safely */ + return 0; +} diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/gd2_read.c b/Build/source/libs/gd/libgd-src/tests/gd2/gd2_read.c new file mode 100644 index 00000000000..9f2b808255e --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/gd2_read.c @@ -0,0 +1,59 @@ +#include "gd.h" +#include +#include +#include "gdtest.h" + +int main(int argc, char *argv[]) +{ + int error = 0, i = 0; + gdImagePtr im, exp; + FILE *fp; + char *path[] = { + "conv_test.gd2", + "invalid_neg_size.gd2", + "invalid_header.gd2", + NULL + }; + char *path_exp[] = { + "conv_test_exp.png", + NULL, + NULL, + NULL + }; + while (path[i] != NULL) { + fp = gdTestFileOpen2("gd2", path[i]); + if (!fp) { + gdTestErrorMsg("failed, cannot open file: %s\n", path[0]); + return 1; + } + im = gdImageCreateFromGd2(fp); + fclose(fp); + + if (path_exp[i] != NULL) { + fp = gdTestFileOpen2("gd2", path_exp[i]); + if (!fp) { + gdTestErrorMsg("failed, cannot open file: %s\n", path_exp[i]); + gdImageDestroy(im); + return 1; + } + exp = gdImageCreateFromPng(fp); + if (!gdAssertImageEquals(exp, im)) { + gdTestErrorMsg("image %s differs from expected result\n", path[i]); + error = 1; + } + if (exp) { + gdImageDestroy(exp); + } + gdImageDestroy(im); + } else { + /* expected to fail */ + if (im) { + gdTestErrorMsg("image %s should have failed to be loaded\n", path[i]); + gdImageDestroy(im); + error = 1; + } + } + i++; + } + return error; +} diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/gd2_read_corrupt.c b/Build/source/libs/gd/libgd-src/tests/gd2/gd2_read_corrupt.c new file mode 100644 index 00000000000..7afc30393f2 --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/gd2_read_corrupt.c @@ -0,0 +1,28 @@ +/* Just try to read the invalid gd2 image & not crash. */ +#include "gd.h" +#include +#include +#include "gdtest.h" + +int main(int argc, char *argv[]) +{ + gdImagePtr im; + FILE *fp; + + fp = gdTestFileOpen2("gd2", "invalid_header.gd2"); + + if (!fp) { + gdTestErrorMsg("failed, cannot open file: %s\n", "invalid_header.gd2"); + return 1; + } + im = gdImageCreateFromGd2(fp); + fclose(fp); + + if (im != NULL) { + gdTestErrorMsg("image should have failed to be loaded\n"); + gdImageDestroy(im); + return 1; + } else { + return 0; + } +} diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/invalid_header.gd2 b/Build/source/libs/gd/libgd-src/tests/gd2/invalid_header.gd2 new file mode 100644 index 00000000000..45323da7f82 Binary files /dev/null and b/Build/source/libs/gd/libgd-src/tests/gd2/invalid_header.gd2 differ diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/invalid_neg_size.gd2 b/Build/source/libs/gd/libgd-src/tests/gd2/invalid_neg_size.gd2 new file mode 100644 index 00000000000..3075f15a81a Binary files /dev/null and b/Build/source/libs/gd/libgd-src/tests/gd2/invalid_neg_size.gd2 differ diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/php_bug_72339.c b/Build/source/libs/gd/libgd-src/tests/gd2/php_bug_72339.c new file mode 100644 index 00000000000..8217c87c1d5 --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/php_bug_72339.c @@ -0,0 +1,36 @@ +#include +#include +#include "gd.h" + +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + int i; + const char header[] = { + 0x00, 0x02, + 0x00, 0x01, + 0x00, 0x01, + 0x00, 0x40, + 0x00, 0x02, + 0x54, 0xA0, + 0x5B, 0x00 + }; + + /* we're creating the test image dynamically, due to its size */ + fp = gdTestTempFp(); + fwrite(header, sizeof(header[0]), sizeof(header), fp); + for (i = 0; i < 0x4000000; i++) { + fputc(0x41, fp); + } + rewind(fp); + + im = gdImageCreateFromGd2(fp); + fclose(fp); + + gdTestAssertMsg(im == NULL, "Image should have failed to be loaded\n"); + + return gdNumFailures(); +} diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/too_few_image_data.c b/Build/source/libs/gd/libgd-src/tests/gd2/too_few_image_data.c new file mode 100644 index 00000000000..3153a080078 --- /dev/null +++ b/Build/source/libs/gd/libgd-src/tests/gd2/too_few_image_data.c @@ -0,0 +1,22 @@ +/* +too_few_image_data.gd2 claims to have a size of 12336x48 pixels, but doesn't +provide as much image data. We test that gdImageCreateFromGd2Ctx() returns NULL +in this case. +*/ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + FILE *fp; + + fp = gdTestFileOpen2("gd2", "too_few_image_data.gd2"); + gdTestAssert(fp != NULL); + im = gdImageCreateFromGd2(fp); + gdTestAssert(im == NULL); + fclose(fp); + + return gdNumFailures(); +} diff --git a/Build/source/libs/gd/libgd-src/tests/gd2/too_few_image_data.gd2 b/Build/source/libs/gd/libgd-src/tests/gd2/too_few_image_data.gd2 new file mode 100644 index 00000000000..1c797d1acfa Binary files /dev/null and b/Build/source/libs/gd/libgd-src/tests/gd2/too_few_image_data.gd2 differ -- cgit v1.2.3