avcodec/cfhd: Check the number of tag/value pairs
authorMichael Niedermayer <michael@niedermayer.cc>
Thu, 11 Feb 2016 21:12:36 +0000 (22:12 +0100)
committerMichael Niedermayer <michael@niedermayer.cc>
Fri, 12 Feb 2016 00:52:44 +0000 (01:52 +0100)
Fixes potentially long loop
Fixes: CID1351382/11

Reviewed-by: Kieran Kunhya <kieran@kunhya.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavcodec/cfhd.c

index 2436aae..5ecfcef 100644 (file)
@@ -344,6 +344,11 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
             break;
         } else if (tag == 2) {
             av_log(avctx, AV_LOG_DEBUG, "tag=2 header - skipping %i tag/value pairs\n", data);
+            if (data > bytestream2_get_bytes_left(&gb) / 4) {
+                av_log(avctx, AV_LOG_ERROR, "too many tag/value pairs (%d)\n", data);
+                ret = AVERROR_INVALIDDATA;
+                break;
+            }
             for (i = 0; i < data; i++) {
                 uint16_t tag2 = bytestream2_get_be16(&gb);
                 uint16_t val2 = bytestream2_get_be16(&gb);