summaryrefslogtreecommitdiff
path: root/Build/source/libs/gd/libgd-src/tests/jpeg/jpeg_ptr_double_free.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/libs/gd/libgd-src/tests/jpeg/jpeg_ptr_double_free.c')
-rw-r--r--Build/source/libs/gd/libgd-src/tests/jpeg/jpeg_ptr_double_free.c31
1 files changed, 31 insertions, 0 deletions
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();
+}