h264: check buffer size before accessing it
authorAnton Khirnov <anton@khirnov.net>
Fri, 15 Nov 2013 09:15:24 +0000 (10:15 +0100)
committerAnton Khirnov <anton@khirnov.net>
Thu, 21 Nov 2013 19:54:20 +0000 (20:54 +0100)
Fixes invalid reads.
Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC:libav-stable@libav.org

libavcodec/h264.c

index 62e4940dc126e325285f400ac37ab2b7029b7925..86d453bba7835bedcffbbbaf4f6f37d34fb8bd7c 100644 (file)
@@ -4554,7 +4554,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size,
                 h->workaround_bugs |= FF_BUG_TRUNCATED;
 
             if (!(h->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 -