lzw: prevent buffer overreads.
authorRonald S. Bultje <rsbultje@gmail.com>
Thu, 29 Mar 2012 00:06:00 +0000 (17:06 -0700)
committerReinhard Tartler <siretart@tauware.de>
Sun, 29 Apr 2012 20:07:03 +0000 (22:07 +0200)
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>
libavcodec/lzw.c

index 873b31445bd2b418ae175a4cea63828c91a38ea7..b674d4e296bed64214bfdf9ef44b3690cbd23ade 100644 (file)
@@ -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;