Browse code

avcodec/h264_cabac: Check decode_cabac_mb_mvd() for failure

Fixes harmless integer overflow
Fixes Ticket5150

No speedloss measured, actually its slightly faster, but please benchmark & double check this

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

Michael Niedermayer authored on 2016/01/26 10:23:31
Showing 1 changed files
... ...
@@ -1540,8 +1540,12 @@ static int decode_cabac_mb_mvd(H264SliceContext *sl, int ctxbase, int amvd, int
1540 1540
     int amvd1 = sl->mvd_cache[list][scan8[n] - 1][1] +\
1541 1541
                 sl->mvd_cache[list][scan8[n] - 8][1];\
1542 1542
 \
1543
-    mx += decode_cabac_mb_mvd(sl, 40, amvd0, &mpx);\
1544
-    my += decode_cabac_mb_mvd(sl, 47, amvd1, &mpy);\
1543
+    int mxd = decode_cabac_mb_mvd(sl, 40, amvd0, &mpx);\
1544
+    int myd = decode_cabac_mb_mvd(sl, 47, amvd1, &mpy);\
1545
+    if (mxd == INT_MIN || myd == INT_MIN) \
1546
+        return AVERROR_INVALIDDATA; \
1547
+    mx += mxd;\
1548
+    my += myd;\
1545 1549
 }
1546 1550
 
1547 1551
 static av_always_inline int get_cabac_cbf_ctx(H264SliceContext *sl,