summaryrefslogtreecommitdiff
path: root/tests/avif/avif_ptr_double_free.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/avif/avif_ptr_double_free.c')
-rw-r--r--tests/avif/avif_ptr_double_free.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/avif/avif_ptr_double_free.c b/tests/avif/avif_ptr_double_free.c
new file mode 100644
index 0000000..8160950
--- /dev/null
+++ b/tests/avif/avif_ptr_double_free.c
@@ -0,0 +1,34 @@
+/**
+ * Test that failure to convert to AVIF returns NULL
+ *
+ * We are creating an image, set its width to zero, and pass this image to
+ * gdImageAvifPtr().
+ * This 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; // making the width 0 should cause gdImageAvifPtr() to fail
+
+ dst = gdImageAvifPtr(src, &size);
+ gdTestAssert(dst == NULL);
+
+ if (src)
+ gdImageDestroy(src);
+
+ if (dst)
+ gdImageDestroy(dst);
+
+ return gdNumFailures();
+}