aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVittorio Giovara <vittorio.giovara@gmail.com>2014-07-30 19:33:36 +0100
committerVittorio Giovara <vittorio.giovara@gmail.com>2014-08-01 13:15:07 +0100
commit2273e5ed992661e0c4b37208e792e2253d5a0b5b (patch)
tree52b1d26b43768f1d08dd8a3e2f171b0c76cfd877
parenta1f7844a11010d8552c75424d1a831b37a0ae5d9 (diff)
downloadffmpeg-2273e5ed992661e0c4b37208e792e2253d5a0b5b.tar.gz
h264: prevent theoretical infinite loop in SEI parsing
Properly address CVE-2011-3946 and parse bitstream as described in the spec. CC: libav-stable@libav.org Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
-rw-r--r--libavcodec/h264_sei.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c
index 6fca2c32a9..1e5a13458a 100644
--- a/libavcodec/h264_sei.c
+++ b/libavcodec/h264_sei.c
@@ -205,14 +205,20 @@ int ff_h264_decode_sei(H264Context *h)
int size = 0;
int type = 0;
int ret = 0;
+ int last = 0;
- do
- type += show_bits(&h->gb, 8);
- while (get_bits(&h->gb, 8) == 255);
+ while (get_bits_left(&h->gb) >= 8 &&
+ (last = get_bits(&h->gb, 8)) == 255) {
+ type += 255;
+ }
+ type += last;
- do
- size += show_bits(&h->gb, 8);
- while (get_bits(&h->gb, 8) == 255);
+ last = 0;
+ while (get_bits_left(&h->gb) >= 8 &&
+ (last = get_bits(&h->gb, 8)) == 255) {
+ size += 255;
+ }
+ size += last;
if (size > get_bits_left(&h->gb) / 8) {
av_log(h->avctx, AV_LOG_ERROR, "SEI type %d truncated at %d\n",