summaryrefslogtreecommitdiff
path: root/archivers/gzip/patches/patch-ab
blob: 2809c0a6ae572646bc5beff5791669aa4c501171 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$NetBSD: patch-ab,v 1.3 2013/06/11 08:28:30 adam Exp $

--- unpack.c.orig	2013-02-02 04:39:13.000000000 +0000
+++ unpack.c
@@ -21,7 +21,6 @@
 #include "tailor.h"
 #include "gzip.h"
 
-#define MIN(a,b) ((a) <= (b) ? (a) : (b))
 /* The arguments must not have side effects. */
 
 #define MAX_BITLEN 25
@@ -157,7 +156,7 @@ local void read_tree()
         /* Remember where the literals of this length start in literal[] : */
         lit_base[len] = base;
         /* And read the literals: */
-        for (n = leaves[len]; n > 0; n--) {
+        for (n = leaves[len]; n > 0 && base < LITERALS; n--) {
             literal[base++] = read_byte ();
         }
     }
@@ -193,7 +192,7 @@ local void build_tree()
     prefixp = &prefix_len[1<<peek_bits];
     for (len = 1; len <= peek_bits; len++) {
         int prefixes = leaves[len] << (peek_bits-len); /* may be 0 */
-        while (prefixes--) *--prefixp = (uch)len;
+        while (prefixes-- && prefixp > prefix_len) *--prefixp = (uch)len;
     }
     /* The length of all other codes is unknown: */
     while (prefixp > prefix_len) *--prefixp = 0;