h264: fix overreads in cabac reader.
authorRonald S. Bultje <rsbultje@gmail.com>
Sat, 17 Mar 2012 04:56:40 +0000 (21:56 -0700)
committerRonald S. Bultje <rsbultje@gmail.com>
Wed, 28 Mar 2012 15:01:28 +0000 (08:01 -0700)
Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC: libav-stable@libav.org
libavcodec/cabac_functions.h

index b150aab..4c74cf7 100644 (file)
@@ -47,7 +47,8 @@ static void refill(CABACContext *c){
         c->low+= c->bytestream[0]<<1;
 #endif
     c->low -= CABAC_MASK;
-    c->bytestream+= CABAC_BITS/8;
+    if (c->bytestream < c->bytestream_end)
+        c->bytestream += CABAC_BITS / 8;
 }
 
 static inline void renorm_cabac_decoder_once(CABACContext *c){
@@ -74,7 +75,8 @@ static void refill2(CABACContext *c){
 #endif
 
     c->low += x<<i;
-    c->bytestream+= CABAC_BITS/8;
+    if (c->bytestream < c->bytestream_end)
+        c->bytestream += CABAC_BITS/8;
 }
 
 static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const state){