Skip to contentSkip to conversation

zlib inflate: Fix potential buffer overflow

PATCH New Guenter Roeck 1 participant 1 message Apr 3, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 zlib inflate: Fix potential buffer overflow

smatch says:

lib/zlib_inflate/inftrees.c:240 zlib_inflate_table() error:
buffer overflow 'count' 16 <= 16

The loop calculating the value for 'min', which is later used to access count[], can indeed result in an index larger than ARRAY_SIZE(count) if the array is filled with 0.

Fixes 4f3865fb57a04 ("zlib_inflate: Upgrade library code to a recent version")
---
 lib/zlib_inflate/inftrees.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/zlib_inflate/inftrees.c +1 -1
index 3fe6ce5b53e5..028943052926 100644
@@ -109,7 +109,7 @@ int zlib_inflate_table(codetype type, unsigned short *lens, unsigned codes,
         *bits = 1;
         return 0;     /* no symbols, but wait for decoding to report error */
     }
-    for (min = 1; min <= MAXBITS; min++)
+    for (min = 1; min < MAXBITS; min++)
         if (count[min] != 0) break;
     if (root < min) root = min;
 
Signature · 1 line
2.7.4