summaryrefslogtreecommitdiff
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:36:37 +0100
commit512354191328c559fcff56070dab897ee2a1b4c1 (patch)
tree6ee331569b219e498ac6c8c37093bf4960e07295
parent01f9540320279954b2764645ab7136847d53d89f (diff)
downloadffmpeg-512354191328c559fcff56070dab897ee2a1b4c1.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.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c
index 5995a8efec..776ce57d46 100644
--- a/libavcodec/h264_sei.c
+++ b/libavcodec/h264_sei.c
@@ -165,17 +165,22 @@ int ff_h264_decode_sei(H264Context *h){
MpegEncContext * const s = &h->s;
while (get_bits_left(&s->gb) > 16) {
- int size, type;
+ int type = 0;
+ int size = 0;
+ int last = 0;
- type=0;
- do{
- type+= show_bits(&s->gb, 8);
- }while(get_bits(&s->gb, 8) == 255);
+ while (get_bits_left(&s->gb) >= 8 &&
+ (last = get_bits(&s->gb, 8)) == 255) {
+ type += 255;
+ }
+ type += last;
- size=0;
- do{
- size+= show_bits(&s->gb, 8);
- }while(get_bits(&s->gb, 8) == 255);
+ last = 0;
+ while (get_bits_left(&s->gb) >= 8 &&
+ (last = get_bits(&s->gb, 8)) == 255) {
+ size += 255;
+ }
+ size += last;
if (size > get_bits_left(&s->gb) / 8) {
av_log(s->avctx, AV_LOG_ERROR, "SEI type %d truncated at %d\n",