From cbc8b26fb98ecaf2d2b802129b2b2227a9f5a8a7 Mon Sep 17 00:00:00 2001 From: Eharve14 <71228603+Eharve14@users.noreply.github.com> Date: Thu, 13 Jan 2022 16:22:29 -0500 Subject: [PATCH] Revert "Added overflow check to get_num_images, defined num_images as unsigned for conformity, relocated check for num images for exicution before allocation and image loading" This reverts commit ab6c7c720334f57232d33c609d904f3b955d4f2a. --- src/bin/jp2/opj_compress.c | 15 +++++---------- src/bin/jp2/opj_decompress.c | 17 ++++++----------- src/bin/jp2/opj_dump.c | 16 ++++++---------- 3 files changed, 17 insertions(+), 31 deletions(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 1072f5b5..646f1375 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -486,10 +486,6 @@ static unsigned int get_num_images(char *imgdirpath) continue; } num_images++; - if(num_images == 0) { - fprintf(stderr, "Integer overflow detected when reading %s\n", imgdirpath); - return 0; - } } closedir(dir); return num_images; @@ -1961,11 +1957,6 @@ 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 == 0) { - fprintf(stdout, "Folder is empty\n"); - ret = 0; - goto fin; - } dirptr = (dircnt_t*)malloc(sizeof(dircnt_t)); if (dirptr) { dirptr->filename_buf = (char*)calloc(num_images, OPJ_PATH_LEN * sizeof( @@ -1983,7 +1974,11 @@ int main(int argc, char **argv) ret = 0; goto fin; } - + if (num_images == 0) { + fprintf(stdout, "Folder is empty\n"); + ret = 0; + goto fin; + } } else { num_images = 1; } diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index 3a6b409f..0d3021cd 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -374,7 +374,7 @@ int get_num_images(char *imgdirpath) { DIR *dir; struct dirent* content; - unsigned int num_images = 0; + int num_images = 0; /*Reading the input images from given input directory*/ @@ -389,10 +389,6 @@ int get_num_images(char *imgdirpath) continue; } num_images++; - if(num_images == 0) { - fprintf(stderr, "Integer overflow detected when reading %s\n", imgdirpath); - return 0; - } } closedir(dir); return num_images; @@ -1371,11 +1367,6 @@ 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 == 0) { - fprintf(stderr, "Folder is empty\n"); - failed = 1; - goto fin; - } dirptr = (dircnt_t*)calloc(1, sizeof(dircnt_t)); if (!dirptr) { destroy_parameters(¶meters); @@ -1403,7 +1394,11 @@ int main(int argc, char **argv) failed = 1; goto fin; } - + if (num_images == 0) { + fprintf(stderr, "Folder is empty\n"); + failed = 1; + goto fin; + } } else { num_images = 1; } diff --git a/src/bin/jp2/opj_dump.c b/src/bin/jp2/opj_dump.c index 8eb73ada..46b976a9 100644 --- a/src/bin/jp2/opj_dump.c +++ b/src/bin/jp2/opj_dump.c @@ -126,7 +126,7 @@ static int get_num_images(char *imgdirpath) { DIR *dir; struct dirent* content; - unsigned int num_images = 0; + int num_images = 0; /*Reading the input images from given input directory*/ @@ -141,10 +141,6 @@ static int get_num_images(char *imgdirpath) continue; } num_images++; - if(num_images == 0) { - fprintf(stderr, "Integer overflow detected when reading images from %s\n", imgdirpath); - return 0; - } } closedir(dir); return num_images; @@ -514,10 +510,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 == 0) { - fprintf(stdout, "Folder is empty\n"); - goto fails; - } + dirptr = (dircnt_t*)malloc(sizeof(dircnt_t)); if (!dirptr) { return EXIT_FAILURE; @@ -543,7 +536,10 @@ int main(int argc, char *argv[]) if (load_images(dirptr, img_fol.imgdirpath) == 1) { goto fails; } - + if (num_images == 0) { + fprintf(stdout, "Folder is empty\n"); + goto fails; + } } else { num_images = 1; }