diff options
author | Ronald S. Bultje <rsbultje@gmail.com> | 2012-03-28 17:06:00 -0700 |
---|---|---|
committer | Reinhard Tartler <siretart@tauware.de> | 2012-04-29 22:07:03 +0200 |
commit | 562c6a7bf129f0c8c49ad6bacc9674a9d2daa5ec (patch) | |
tree | 2dae7b90115b3847bddaf0018a43a79ed099f4ca /libavcodec | |
parent | e711ccee4d6b4e9b81ea3b12fdbec293a836e7da (diff) | |
download | ffmpeg-562c6a7bf129f0c8c49ad6bacc9674a9d2daa5ec.tar.gz |
lzw: prevent buffer overreads.
Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
CC: libav-stable@libav.org
(cherry picked from commit ddcf67c8a51c67b122a826d8b5819e96d591d813)
Signed-off-by: Reinhard Tartler <siretart@tauware.de>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/lzw.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/libavcodec/lzw.c b/libavcodec/lzw.c index 873b31445b..b674d4e296 100644 --- a/libavcodec/lzw.c +++ b/libavcodec/lzw.c @@ -101,9 +101,14 @@ void ff_lzw_decode_tail(LZWState *p) struct LZWState *s = (struct LZWState *)p; if(s->mode == FF_LZW_GIF) { - while(s->pbuf < s->ebuf && s->bs>0){ - s->pbuf += s->bs; - s->bs = *s->pbuf++; + while (s->bs > 0) { + if (s->pbuf + s->bs >= s->ebuf) { + s->pbuf = s->ebuf; + break; + } else { + s->pbuf += s->bs; + s->bs = *s->pbuf++; + } } }else s->pbuf= s->ebuf; |