From c22cbd8bdf8ff2ae372f94391a4be2d322b36b41 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Sun, 30 Jul 2017 18:43:25 +0200 Subject: Avoid heap buffer overflow in function pnmtoimage of convert.c, and unsigned integer overflow in opj_image_create() (CVE-2016-9118, #861) --- src/bin/jp2/convert.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/bin') diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index b3eb8581..492911c9 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -41,6 +41,7 @@ #include #include #include +#include #include "openjpeg.h" #include "convert.h" @@ -1731,6 +1732,15 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) return NULL; } + /* This limitation could be removed by making sure to use size_t below */ + if (header_info.height != 0 && + header_info.width > INT_MAX / header_info.height) { + fprintf(stderr, "pnmtoimage:Image %dx%d too big!\n", + header_info.width, header_info.height); + fclose(fp); + return NULL; + } + format = header_info.format; switch (format) { -- cgit v1.2.3