From af40847681b978441fdd25276685414f9e17820a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 15 Nov 2013 10:15:24 +0100 Subject: [PATCH] h264: check buffer size before accessing it Fixes invalid reads. Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind CC:libav-stable@libav.org --- libavcodec/h264.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/h264.c b/libavcodec/h264.c index d6d3d42495..20fa82cae2 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -3941,7 +3941,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 -