summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2013-02-18 21:06:35 -0800
committerMark Adler <madler@alumni.caltech.edu>2013-02-18 21:47:00 -0800
commit51370f365607fe14a6a7a1a27b3bd29d788f5e5b (patch)
tree09db363475af028a7b9157b949667491d132f6de
parent10056909c00bca2684340856ce20272f3fd8fa43 (diff)
downloadzlib-51370f365607fe14a6a7a1a27b3bd29d788f5e5b.tar.gz
Fix serious but very rare decompression bug in inftrees.c.
inftrees.c compared the number of used table entries to the maximum allowed value using >= instead of >. This patch fixes those to use >. The bug was discovered by Ignat Kolesnichenko of Yandex LC where they have run petabytes of data through zlib. Triggering the bug is apparently very rare, seeing as how it has been out there in the wild for almost three years before being discovered. The bug is instantiated only if the exact maximum number of decoding table entries, ENOUGH_DISTS or ENOUGH_LENS is used by the block being decoded, resulting in the false positive of overflowing the table.
-rw-r--r--inftrees.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/inftrees.c b/inftrees.c
index 873da59..3781399 100644
--- a/inftrees.c
+++ b/inftrees.c
@@ -208,8 +208,8 @@ unsigned short FAR *work;
mask = used - 1; /* mask for comparing low */
/* check available table space */
- if ((type == LENS && used >= ENOUGH_LENS) ||
- (type == DISTS && used >= ENOUGH_DISTS))
+ if ((type == LENS && used > ENOUGH_LENS) ||
+ (type == DISTS && used > ENOUGH_DISTS))
return 1;
/* process all codes and make table entries */
@@ -277,8 +277,8 @@ unsigned short FAR *work;
/* check for enough space */
used += 1U << curr;
- if ((type == LENS && used >= ENOUGH_LENS) ||
- (type == DISTS && used >= ENOUGH_DISTS))
+ if ((type == LENS && used > ENOUGH_LENS) ||
+ (type == DISTS && used > ENOUGH_DISTS))
return 1;
/* point entry in root table to sub-table */