libopenjpegdec: check existence of image component data
authorAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Sat, 30 May 2015 14:18:48 +0000 (16:18 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Tue, 28 Jul 2015 00:33:56 +0000 (02:33 +0200)
libopenjpeg can return images with components without data.

This fixes segmentation faults.

Reviewed-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
(cherry picked from commit 3ef5702926c495232ffe685303ba8661bdff1149)

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavcodec/libopenjpegdec.c

index 0cf46e6..33c570f 100644 (file)
@@ -356,6 +356,15 @@ static int libopenjpeg_decode_frame(AVCodecContext *avctx,
         goto done;
     }
 
+    for (i = 0; i < image->numcomps; i++) {
+        if (!image->comps[i].data) {
+            av_log(avctx, AV_LOG_ERROR,
+                   "Image component %d contains no data.\n", i);
+            ret = AVERROR_INVALIDDATA;
+            goto done;
+        }
+    }
+
     desc       = av_pix_fmt_desc_get(avctx->pix_fmt);
     pixel_size = desc->comp[0].step_minus1 + 1;
     ispacked   = libopenjpeg_ispacked(avctx->pix_fmt);