]> git.sesse.net Git - ffmpeg/commitdiff
lcl: error out if uncompressed input buffer is smaller than framesize.
authorRonald S. Bultje <rsbultje@gmail.com>
Fri, 24 Feb 2012 00:09:36 +0000 (16:09 -0800)
committerRonald S. Bultje <rsbultje@gmail.com>
Fri, 24 Feb 2012 15:28:57 +0000 (07:28 -0800)
This prevents crashes when trying to read beyond the end of the buffer
while decoding frame data.

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC: libav-stable@libav.org
libavcodec/lcldec.c

index a7f0bde23e170738873f3ded61ed2e9618c5b923..d3a85f7863ec553c779f4385b0599419053a4486 100644 (file)
@@ -223,8 +223,29 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
                 len = mszh_dlen;
             }
             break;
-        case COMP_MSZH_NOCOMP:
+        case COMP_MSZH_NOCOMP: {
+            int bppx2;
+            switch (c->imgtype) {
+            case IMGTYPE_YUV111:
+            case IMGTYPE_RGB24:
+                bppx2 = 6;
+                break;
+            case IMGTYPE_YUV422:
+            case IMGTYPE_YUV211:
+                bppx2 = 4;
+                break;
+            case IMGTYPE_YUV411:
+            case IMGTYPE_YUV420:
+                bppx2 = 3;
+                break;
+            default:
+                bppx2 = 0; // will error out below
+                break;
+            }
+            if (len < ((width * height * bppx2) >> 1))
+                return AVERROR_INVALIDDATA;
             break;
+        }
         default:
             av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n");
             return -1;