diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index d077d539..8c531d17 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -1957,7 +1957,7 @@ int main(int argc, char **argv) /* Read directory if necessary */ if (img_fol.set_imgdir == 1) { num_images = get_num_images(img_fol.imgdirpath); - if((num_images > SIZE_MAX/(OPJ_PATH_LEN * sizeof(char)))){ + if(num_images > SIZE_MAX/(OPJ_PATH_LEN * sizeof(char)) || num_images < 0){ fprintf(stdout, "Max images exceeded\n"); ret = 0; goto fin; diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index 22b7a1e7..c5c71e91 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -1367,7 +1367,7 @@ int main(int argc, char **argv) if (img_fol.set_imgdir == 1) { int it_image; num_images = get_num_images(img_fol.imgdirpath); - if( num_images > SIZE_MAX/(sizeof(char)* OPJ_PATH_LEN)){ + if( num_images > SIZE_MAX/(sizeof(char)* OPJ_PATH_LEN) || num_images < 0){ fprintf(stderr, "Max number of images exceeded\n"); failed = 1; goto fin; diff --git a/src/bin/jp2/opj_dump.c b/src/bin/jp2/opj_dump.c index 73874e63..92921b33 100644 --- a/src/bin/jp2/opj_dump.c +++ b/src/bin/jp2/opj_dump.c @@ -516,7 +516,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } /* Stores at max 10 image file names*/ - if(num_images> SIZE_MAX/(OPJ_PATH_LEN * sizeof(char))){ + if(num_images> SIZE_MAX/(OPJ_PATH_LEN * sizeof(char)) || num_images < 0){ free(dirptr); return EXIT_FAILURE; }else{