avcodec/mss2: Check for repeat overflow
[ffmpeg.git] / libavcodec / mss2.c
index 5e56e4d..1af2cd0 100644 (file)
@@ -27,6 +27,7 @@
 #include "error_resilience.h"
 #include "internal.h"
 #include "mpeg_er.h"
+#include "msmpeg4.h"
 #include "msmpeg4data.h"
 #include "qpeldsp.h"
 #include "vc1.h"
@@ -209,8 +210,13 @@ static int decode_555(GetByteContext *gB, uint16_t *dst, int stride,
                     last_symbol = b << 8 | bytestream2_get_byte(gB);
                 else if (b > 129) {
                     repeat = 0;
-                    while (b-- > 130)
+                    while (b-- > 130) {
+                        if (repeat >= (INT_MAX >> 8) - 1) {
+                            av_log(NULL, AV_LOG_ERROR, "repeat overflow\n");
+                            return AVERROR_INVALIDDATA;
+                        }
                         repeat = (repeat << 8) + bytestream2_get_byte(gB) + 1;
+                    }
                     if (last_symbol == -2) {
                         int skip = FFMIN((unsigned)repeat, dst + w - p);
                         repeat -= skip;