Avoid overflow in multiplications in utilities related to big number of files in...
authorEharve14 <71228603+Eharve14@users.noreply.github.com>
Thu, 13 Jan 2022 20:05:52 +0000 (15:05 -0500)
committerGitHub <noreply@github.com>
Thu, 13 Jan 2022 20:05:52 +0000 (21:05 +0100)
src/bin/jp2/opj_compress.c
src/bin/jp2/opj_decompress.c
src/bin/jp2/opj_dump.c

index 1399d52771e31bee96de2de27b20e94ec82b0309..646f137578614302bd91835149ea0622a138f062 100644 (file)
@@ -1967,7 +1967,7 @@ int main(int argc, char **argv)
                 goto fin;
             }
             for (i = 0; i < num_images; i++) {
-                dirptr->filename[i] = dirptr->filename_buf + i * OPJ_PATH_LEN;
+                dirptr->filename[i] = dirptr->filename_buf + (size_t)i * OPJ_PATH_LEN;
             }
         }
         if (load_images(dirptr, img_fol.imgdirpath) == 1) {
index e1217f8913a0145f383daf4e48c63fcda64d9b3d..0d3021cdf2a21da15aa42463c4570a5da9da61d2 100644 (file)
@@ -1367,7 +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);
-
         dirptr = (dircnt_t*)calloc(1, sizeof(dircnt_t));
         if (!dirptr) {
             destroy_parameters(&parameters);
@@ -1387,7 +1386,8 @@ int main(int argc, char **argv)
             goto fin;
         }
         for (it_image = 0; it_image < num_images; it_image++) {
-            dirptr->filename[it_image] = dirptr->filename_buf + it_image * OPJ_PATH_LEN;
+            dirptr->filename[it_image] = dirptr->filename_buf + (size_t)it_image *
+                                         OPJ_PATH_LEN;
         }
 
         if (load_images(dirptr, img_fol.imgdirpath) == 1) {
index d2646f10e1a54d730e9dd7612abcdb4ed2fe63bf..46b976a9ad4f058829e719accbd42183982e51ab 100644 (file)
@@ -529,13 +529,13 @@ int main(int argc, char *argv[])
         }
 
         for (it_image = 0; it_image < num_images; it_image++) {
-            dirptr->filename[it_image] = dirptr->filename_buf + it_image * OPJ_PATH_LEN;
+            dirptr->filename[it_image] = dirptr->filename_buf + (size_t)it_image *
+                                         OPJ_PATH_LEN;
         }
 
         if (load_images(dirptr, img_fol.imgdirpath) == 1) {
             goto fails;
         }
-
         if (num_images == 0) {
             fprintf(stdout, "Folder is empty\n");
             goto fails;