pgxtoimage(): fix write stack buffer overflow (#997)
[openjpeg.git] / src / bin / jp2 / opj_decompress.c
index 3dc651ddcbfbce35b099a5a60249f2955df45d72..848167babe15a1003d1e959cc93864bfe96c7c50 100644 (file)
@@ -237,6 +237,8 @@ static void decode_help_display(void)
         fprintf(stdout, "  -threads <num_threads>\n"
                 "    Number of threads to use for decoding.\n");
     }
+    fprintf(stdout, "  -quiet\n"
+            "    Disable output from the library and other output.\n");
     /* UniPG>> */
 #ifdef USE_JPWL
     fprintf(stdout, "  -W <options>\n"
@@ -1352,7 +1354,9 @@ int main(int argc, char **argv)
     /*Decoding image one by one*/
     for (imageno = 0; imageno < num_images ; imageno++)  {
 
-        fprintf(stderr, "\n");
+        if (!parameters.quiet) {
+            fprintf(stderr, "\n");
+        }
 
         if (img_fol.set_imgdir == 1) {
             if (get_next_file(imageno, dirptr, &img_fol, &parameters)) {
@@ -1489,6 +1493,17 @@ int main(int argc, char **argv)
             }
         }
 
+        /* FIXME? Shouldn't that situation be considered as an error of */
+        /* opj_decode() / opj_get_decoded_tile() ? */
+        if (image->comps[0].data == NULL) {
+            fprintf(stderr, "ERROR -> opj_decompress: no image data!\n");
+            opj_destroy_codec(l_codec);
+            opj_stream_destroy(l_stream);
+            opj_image_destroy(image);
+            failed = 1;
+            goto fin;
+        }
+
         tCumulative += opj_clock() - t;
         numDecompressedImages++;
 
@@ -1711,7 +1726,7 @@ fin:
         }
         free(dirptr);
     }
-    if (numDecompressedImages && !(parameters.quiet)) {
+    if (numDecompressedImages && !failed && !(parameters.quiet)) {
         fprintf(stdout, "decode time: %d ms\n",
                 (int)((tCumulative * 1000.0) / (OPJ_FLOAT64)numDecompressedImages));
     }