File openjpeg2-CVE-2021-29338.patch of Package openjpeg2.26563

Index: openjpeg-2.3.0/src/bin/jp2/opj_compress.c
===================================================================
--- openjpeg-2.3.0.orig/src/bin/jp2/opj_compress.c
+++ openjpeg-2.3.0/src/bin/jp2/opj_compress.c
@@ -1770,11 +1770,11 @@ int main(int argc, char **argv)
     /* Read directory if necessary */
     if (img_fol.set_imgdir == 1) {
         num_images = get_num_images(img_fol.imgdirpath);
-        dirptr = (dircnt_t*)malloc(sizeof(dircnt_t));
+        dirptr = (dircnt_t*)calloc(1, sizeof(dircnt_t));
         if (dirptr) {
-            dirptr->filename_buf = (char*)malloc(num_images * OPJ_PATH_LEN * sizeof(
+            dirptr->filename_buf = (char*)calloc(num_images, OPJ_PATH_LEN * sizeof(
                     char)); /* Stores at max 10 image file names*/
-            dirptr->filename = (char**) malloc(num_images * sizeof(char*));
+            dirptr->filename = (char**) calloc(num_images, sizeof(char*));
             if (!dirptr->filename_buf) {
                 return 0;
             }
Index: openjpeg-2.3.0/src/bin/jp2/opj_decompress.c
===================================================================
--- openjpeg-2.3.0.orig/src/bin/jp2/opj_decompress.c
+++ openjpeg-2.3.0/src/bin/jp2/opj_decompress.c
@@ -1360,14 +1360,14 @@ int main(int argc, char **argv)
             destroy_parameters(&parameters);
             return EXIT_FAILURE;
         }
-        dirptr->filename_buf = (char*)malloc((size_t)num_images * OPJ_PATH_LEN * sizeof(
+        dirptr->filename_buf = (char*)calloc((size_t)num_images, OPJ_PATH_LEN * sizeof(
                 char)); /* Stores at max 10 image file names*/
         if (!dirptr->filename_buf) {
             failed = 1;
             goto fin;
         }
 
-        dirptr->filename = (char**) malloc((size_t)num_images * sizeof(char*));
+        dirptr->filename = (char**) calloc((size_t)num_images, sizeof(char*));
 
         if (!dirptr->filename) {
             failed = 1;
Index: openjpeg-2.3.0/src/bin/jp2/opj_dump.c
===================================================================
--- openjpeg-2.3.0.orig/src/bin/jp2/opj_dump.c
+++ openjpeg-2.3.0/src/bin/jp2/opj_dump.c
@@ -482,17 +482,17 @@ int main(int argc, char *argv[])
         int it_image;
         num_images = get_num_images(img_fol.imgdirpath);
 
-        dirptr = (dircnt_t*)malloc(sizeof(dircnt_t));
+        dirptr = (dircnt_t*)calloc(1, sizeof(dircnt_t));
         if (!dirptr) {
             return EXIT_FAILURE;
         }
-        dirptr->filename_buf = (char*)malloc((size_t)num_images * OPJ_PATH_LEN * sizeof(
+        dirptr->filename_buf = (char*)calloc((size_t)num_images, OPJ_PATH_LEN * sizeof(
                 char)); /* Stores at max 10 image file names*/
         if (!dirptr->filename_buf) {
             free(dirptr);
             return EXIT_FAILURE;
         }
-        dirptr->filename = (char**) malloc((size_t)num_images * sizeof(char*));
+        dirptr->filename = (char**) calloc((size_t)num_images, sizeof(char*));
 
         if (!dirptr->filename) {
             goto fails;
openSUSE Build Service is sponsored by