X-Git-Url: http://git.draconx.ca/gitweb/liblbx.git/blobdiff_plain/d4c47ce48c5de8bd1066ae3996f6e34cd790cd7c..5057c6695cbe55f5d13e8e10a1e630c7ee00ea12:/src/image.c diff --git a/src/image.c b/src/image.c index 98d1a31..f68f2da 100644 --- a/src/image.c +++ b/src/image.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #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);