]> git.draconx.ca Git - liblbx.git/blobdiff - src/image.c
liblbx: Fix framebuffer allocation for 0x0 images.
[liblbx.git] / src / image.c
index 98d1a31118ceb03085d14d860045ef267ed52244..f68f2da9f9ac4b1573e9d16ed53279ac9a236043 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <inttypes.h>
 #include <errno.h>
 
 #include "pack.h"
@@ -280,6 +281,15 @@ static unsigned char **allocframebuffer(size_t width, size_t height)
        unsigned char **new, *tmp;
        size_t i;
 
+       if (height > SIZE_MAX / sizeof *new) {
+               lbx_error_raise(LBX_ENOMEM);
+               return NULL;
+       }
+
+       /* Ensure that there is at least one row in the framebuffer. */
+       if (height == 0 || width == 0)
+               width = height = 1;
+
        tmp = calloc(height, width);
        if (!tmp) {
                lbx_error_raise(LBX_ENOMEM);