h264: check buffer size before accessing it
authorAnton Khirnov <anton@khirnov.net>
Fri, 15 Nov 2013 09:15:24 +0000 (10:15 +0100)
committerReinhard Tartler <siretart@tauware.de>
Sun, 1 Jun 2014 00:05:18 +0000 (20:05 -0400)
Fixes invalid reads.
Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC:libav-stable@libav.org

libavcodec/h264.c

index ba8872c..f021e59 100644 (file)
@@ -3919,7 +3919,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
             s->workaround_bugs |= FF_BUG_TRUNCATED;
 
         if(!(s->workaround_bugs & FF_BUG_TRUNCATED)){
-        while(ptr[dst_length - 1] == 0 && dst_length > 0)
+        while(dst_length > 0 && ptr[dst_length - 1] == 0)
             dst_length--;
         }
         bit_length= !dst_length ? 0 : (8*dst_length - ff_h264_decode_rbsp_trailing(h, ptr + dst_length - 1));