|
|
f408d8 |
--- gzip-1.3.9/unlzh.c.4337 2007-01-15 16:31:53.000000000 +0100
|
|
|
f408d8 |
+++ gzip-1.3.9/unlzh.c 2007-01-15 16:38:08.000000000 +0100
|
|
|
f408d8 |
@@ -146,8 +146,8 @@
|
|
|
f408d8 |
start[1] = 0;
|
|
|
f408d8 |
for (i = 1; i <= 16; i++)
|
|
|
f408d8 |
start[i + 1] = start[i] + (count[i] << (16 - i));
|
|
|
f408d8 |
- if ((start[17] & 0xffff) != 0)
|
|
|
f408d8 |
- gzip_error ("Bad table\n");
|
|
|
f408d8 |
+ if ((start[17] & 0xffff) != 0 || tablebits > 16) /* 16 for weight below */
|
|
|
f408d8 |
+ gzip_error ("Bad table (case b)\n");
|
|
|
f408d8 |
|
|
|
f408d8 |
jutbits = 16 - tablebits;
|
|
|
f408d8 |
for (i = 1; i <= (unsigned)tablebits; i++) {
|
|
|
f408d8 |
@@ -161,15 +162,15 @@
|
|
|
f408d8 |
|
|
|
f408d8 |
i = start[tablebits + 1] >> jutbits;
|
|
|
f408d8 |
if (i != 0) {
|
|
|
f408d8 |
- k = 1 << tablebits;
|
|
|
f408d8 |
- while (i != k) table[i++] = 0;
|
|
|
f408d8 |
+ k = MIN(1 << tablebits, DIST_BUFSIZE);
|
|
|
f408d8 |
+ while (i < k) table[i++] = 0;
|
|
|
f408d8 |
}
|
|
|
f408d8 |
|
|
|
f408d8 |
avail = nchar;
|
|
|
f408d8 |
mask = (unsigned) 1 << (15 - tablebits);
|
|
|
f408d8 |
for (ch = 0; ch < (unsigned)nchar; ch++) {
|
|
|
f408d8 |
if ((len = bitlen[ch]) == 0) continue;
|
|
|
f408d8 |
- nextcode = start[len] + weight[len];
|
|
|
f408d8 |
+ nextcode = MIN(start[len] + weight[len], DIST_BUFSIZE);
|
|
|
f408d8 |
if (len <= (unsigned)tablebits) {
|
|
|
f408d8 |
if ((unsigned) 1 << tablebits < nextcode)
|
|
|
f408d8 |
gzip_error ("Bad table\n");
|
|
|
f408d8 |
@@ -212,7 +213,7 @@
|
|
|
f408d8 |
for (i = 0; i < 256; i++) pt_table[i] = c;
|
|
|
f408d8 |
} else {
|
|
|
f408d8 |
i = 0;
|
|
|
f408d8 |
- while (i < n) {
|
|
|
f408d8 |
+ while (i < MIN(n,NPT)) {
|
|
|
f408d8 |
c = bitbuf >> (BITBUFSIZ - 3);
|
|
|
f408d8 |
if (c == 7) {
|
|
|
f408d8 |
mask = (unsigned) 1 << (BITBUFSIZ - 1 - 3);
|
|
|
f408d8 |
@@ -224,7 +225,7 @@
|
|
|
f408d8 |
pt_len[i++] = c;
|
|
|
f408d8 |
if (i == i_special) {
|
|
|
f408d8 |
c = getbits(2);
|
|
|
f408d8 |
- while (--c >= 0) pt_len[i++] = 0;
|
|
|
f408d8 |
+ while (--c >= 0 && i < NPT) pt_len[i++] = 0;
|
|
|
f408d8 |
}
|
|
|
f408d8 |
}
|
|
|
f408d8 |
while (i < nn) pt_len[i++] = 0;
|
|
|
f408d8 |
@@ -244,7 +245,7 @@
|
|
|
f408d8 |
for (i = 0; i < 4096; i++) c_table[i] = c;
|
|
|
f408d8 |
} else {
|
|
|
f408d8 |
i = 0;
|
|
|
f408d8 |
- while (i < n) {
|
|
|
f408d8 |
+ while (i < MIN(n,NC)) {
|
|
|
f408d8 |
c = pt_table[bitbuf >> (BITBUFSIZ - 8)];
|
|
|
f408d8 |
if (c >= NT) {
|
|
|
f408d8 |
mask = (unsigned) 1 << (BITBUFSIZ - 1 - 8);
|
|
|
f408d8 |
@@ -259,7 +260,7 @@
|
|
|
f408d8 |
if (c == 0) c = 1;
|
|
|
f408d8 |
else if (c == 1) c = getbits(4) + 3;
|
|
|
f408d8 |
else c = getbits(CBIT) + 20;
|
|
|
f408d8 |
- while (--c >= 0) c_len[i++] = 0;
|
|
|
f408d8 |
+ while (--c >= 0 && i < NC) c_len[i++] = 0;
|
|
|
f408d8 |
} else c_len[i++] = c - 2;
|
|
|
f408d8 |
}
|
|
|
f408d8 |
while (i < NC) c_len[i++] = 0;
|
|
|
f408d8 |
@@ -352,7 +353,7 @@
|
|
|
f408d8 |
while (--j >= 0) {
|
|
|
f408d8 |
buffer[r] = buffer[i];
|
|
|
f408d8 |
i = (i + 1) & (DICSIZ - 1);
|
|
|
f408d8 |
- if (++r == count) return r;
|
|
|
f408d8 |
+ if (++r >= count) return r;
|
|
|
f408d8 |
}
|
|
|
f408d8 |
for ( ; ; ) {
|
|
|
f408d8 |
c = decode_c();
|
|
|
f408d8 |
@@ -362,14 +363,14 @@
|
|
|
f408d8 |
}
|
|
|
f408d8 |
if (c <= UCHAR_MAX) {
|
|
|
f408d8 |
buffer[r] = c;
|
|
|
f408d8 |
- if (++r == count) return r;
|
|
|
f408d8 |
+ if (++r >= count) return r;
|
|
|
f408d8 |
} else {
|
|
|
f408d8 |
j = c - (UCHAR_MAX + 1 - THRESHOLD);
|
|
|
f408d8 |
i = (r - decode_p() - 1) & (DICSIZ - 1);
|
|
|
f408d8 |
while (--j >= 0) {
|
|
|
f408d8 |
buffer[r] = buffer[i];
|
|
|
f408d8 |
i = (i + 1) & (DICSIZ - 1);
|
|
|
f408d8 |
- if (++r == count) return r;
|
|
|
f408d8 |
+ if (++r >= count) return r;
|
|
|
f408d8 |
}
|
|
|
f408d8 |
}
|
|
|
f408d8 |
}
|
|
|
f408d8 |
--- gzip-1.3.9/gzip.h.4337 2007-01-15 16:31:53.000000000 +0100
|
|
|
f408d8 |
+++ gzip-1.3.9/gzip.h 2007-01-15 16:38:52.000000000 +0100
|
|
|
f408d8 |
@@ -224,6 +224,8 @@
|
|
|
f408d8 |
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
|
|
|
f408d8 |
#define try_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(1))
|
|
|
f408d8 |
|
|
|
f408d8 |
+#define MIN(a,b) ((a) <= (b) ? (a) : (b))
|
|
|
f408d8 |
+
|
|
|
f408d8 |
/* put_byte is used for the compressed output, put_ubyte for the
|
|
|
f408d8 |
* uncompressed output. However unlzw() uses window for its
|
|
|
f408d8 |
* suffix table instead of its output buffer, so it does not use put_ubyte
|
|
|
f408d8 |
--- gzip-1.3.9/unpack.c.4337 2007-01-15 16:31:53.000000000 +0100
|
|
|
f408d8 |
+++ gzip-1.3.9/unpack.c 2007-01-15 16:39:12.000000000 +0100
|
|
|
f408d8 |
@@ -21,9 +21,6 @@
|
|
|
f408d8 |
#include "tailor.h"
|
|
|
f408d8 |
#include "gzip.h"
|
|
|
f408d8 |
|
|
|
f408d8 |
-#define MIN(a,b) ((a) <= (b) ? (a) : (b))
|
|
|
f408d8 |
-/* The arguments must not have side effects. */
|
|
|
f408d8 |
-
|
|
|
f408d8 |
#define MAX_BITLEN 25
|
|
|
f408d8 |
/* Maximum length of Huffman codes. (Minor modifications to the code
|
|
|
f408d8 |
* would be needed to support 32 bits codes, but pack never generates
|
|
|
f408d8 |
|