summaryrefslogtreecommitdiff
path: root/Build/source/libs/gd/libgd-src/tests/jpeg
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/libs/gd/libgd-src/tests/jpeg')
-rw-r--r--Build/source/libs/gd/libgd-src/tests/jpeg/CMakeLists.txt3
-rw-r--r--Build/source/libs/gd/libgd-src/tests/jpeg/Makemodule.am7
-rw-r--r--Build/source/libs/gd/libgd-src/tests/jpeg/bug00338.c35
-rw-r--r--Build/source/libs/gd/libgd-src/tests/jpeg/jpeg_ptr_double_free.c31
4 files changed, 52 insertions, 24 deletions
diff --git a/Build/source/libs/gd/libgd-src/tests/jpeg/CMakeLists.txt b/Build/source/libs/gd/libgd-src/tests/jpeg/CMakeLists.txt
index 19964b0ce2c..ff188a93888 100644
--- a/Build/source/libs/gd/libgd-src/tests/jpeg/CMakeLists.txt
+++ b/Build/source/libs/gd/libgd-src/tests/jpeg/CMakeLists.txt
@@ -2,14 +2,15 @@ IF(JPEG_FOUND)
LIST(APPEND TESTS_FILES
jpeg_empty_file
jpeg_im2im
+ jpeg_ptr_double_free
jpeg_null
+ jpeg_resolution
)
IF(PNG_FOUND)
LIST(APPEND TESTS_FILES
bug_github_18
jpeg_read
- jpeg_resolution
bug00338
)
ENDIF(PNG_FOUND)
diff --git a/Build/source/libs/gd/libgd-src/tests/jpeg/Makemodule.am b/Build/source/libs/gd/libgd-src/tests/jpeg/Makemodule.am
index 7e5d317b69f..b778470a9de 100644
--- a/Build/source/libs/gd/libgd-src/tests/jpeg/Makemodule.am
+++ b/Build/source/libs/gd/libgd-src/tests/jpeg/Makemodule.am
@@ -2,14 +2,15 @@ if HAVE_LIBJPEG
libgd_test_programs += \
jpeg/jpeg_empty_file \
jpeg/jpeg_im2im \
- jpeg/jpeg_null
+ jpeg/jpeg_null \
+ jpeg/jpeg_ptr_double_free \
+ jpeg/jpeg_resolution
if HAVE_LIBPNG
libgd_test_programs += \
jpeg/bug_github_18 \
jpeg/bug00338 \
- jpeg/jpeg_read \
- jpeg/jpeg_resolution
+ jpeg/jpeg_read
endif
endif
diff --git a/Build/source/libs/gd/libgd-src/tests/jpeg/bug00338.c b/Build/source/libs/gd/libgd-src/tests/jpeg/bug00338.c
index 15224d32b34..7874df28ed2 100644
--- a/Build/source/libs/gd/libgd-src/tests/jpeg/bug00338.c
+++ b/Build/source/libs/gd/libgd-src/tests/jpeg/bug00338.c
@@ -8,44 +8,39 @@
* See also ../png/bug00338.c
*/
-
#include <string.h>
#include "gd.h"
#include "gd_errors.h"
#include "gdtest.h"
-
#define MSG "gd-jpeg: JPEG library reports unrecoverable error: %s"
-
static int error_handler_called = 0;
-
static void error_handler(int priority, const char *format, va_list args)
{
- if (!strcmp(format, MSG)) {
- gdTestAssertMsg(priority == GD_WARNING, "expected priority %d, but got %d", GD_WARNING, priority);
- error_handler_called = 1;
- }
+ if (!strcmp(format, MSG)) {
+ gdTestAssertMsg(priority == GD_WARNING, "expected priority %d, but got %d", GD_WARNING, priority);
+ error_handler_called = 1;
+ }
}
-
int main()
{
- gdImagePtr im;
- FILE *fp;
+ gdImagePtr im;
+ FILE *fp;
- gdSetErrorMethod(error_handler);
+ gdSetErrorMethod(error_handler);
- im = gdImageCreateTrueColor(10, 10);
- fp = gdTestTempFp();
- gdImagePng(im, fp);
- gdImageDestroy(im);
+ im = gdImageCreateTrueColor(10, 10);
+ fp = gdTestTempFp();
+ gdImagePng(im, fp);
+ gdImageDestroy(im);
- im = gdImageCreateFromJpeg(fp);
- gdTestAssert(im == NULL);
+ im = gdImageCreateFromJpeg(fp);
+ gdTestAssert(im == NULL);
- gdTestAssert(error_handler_called);
+ gdTestAssert(error_handler_called);
- return gdNumFailures();
+ return gdNumFailures();
}
diff --git a/Build/source/libs/gd/libgd-src/tests/jpeg/jpeg_ptr_double_free.c b/Build/source/libs/gd/libgd-src/tests/jpeg/jpeg_ptr_double_free.c
new file mode 100644
index 00000000000..df5a510bb55
--- /dev/null
+++ b/Build/source/libs/gd/libgd-src/tests/jpeg/jpeg_ptr_double_free.c
@@ -0,0 +1,31 @@
+/**
+ * Test that failure to convert to JPEG returns NULL
+ *
+ * We are creating an image, set its width to zero, and pass this image to
+ * `gdImageJpegPtr()` which is supposed to fail, and as such should return NULL.
+ *
+ * See also <https://github.com/libgd/libgd/issues/381>
+ */
+
+
+#include "gd.h"
+#include "gdtest.h"
+
+
+int main()
+{
+ gdImagePtr src, dst;
+ int size;
+
+ src = gdImageCreateTrueColor(1, 10);
+ gdTestAssert(src != NULL);
+
+ src->sx = 0; /* this hack forces gdImageJpegPtr() to fail */
+
+ dst = gdImageJpegPtr(src, &size, 0);
+ gdTestAssert(dst == NULL);
+
+ gdImageDestroy(src);
+
+ return gdNumFailures();
+}