diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-26 19:33:05 +0100 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2015-12-01 11:05:07 -0500 |
commit | 6767af17f11144c7cd3cfe9ef799d7f89a78fe65 (patch) | |
tree | bcd59085964f038615069781a97dc754b98956f9 /archival | |
parent | 5c23f2566c1d26c62024cc2c78ca5aad4c99dd33 (diff) | |
download | busybox-w32-6767af17f11144c7cd3cfe9ef799d7f89a78fe65.tar.gz busybox-w32-6767af17f11144c7cd3cfe9ef799d7f89a78fe65.tar.bz2 busybox-w32-6767af17f11144c7cd3cfe9ef799d7f89a78fe65.zip |
unzip: test for bad archive SEGVing
function old new delta
huft_build 1296 1300 +4
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
(cherry picked from commit 1de25a6e87e0e627aa34298105a3d17c60a1f44e)
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'archival')
-rw-r--r-- | archival/libarchive/decompress_gunzip.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c index 1360abef7..c76fd31da 100644 --- a/archival/libarchive/decompress_gunzip.c +++ b/archival/libarchive/decompress_gunzip.c | |||
@@ -305,11 +305,12 @@ static int huft_build(const unsigned *b, const unsigned n, | |||
305 | unsigned i; /* counter, current code */ | 305 | unsigned i; /* counter, current code */ |
306 | unsigned j; /* counter */ | 306 | unsigned j; /* counter */ |
307 | int k; /* number of bits in current code */ | 307 | int k; /* number of bits in current code */ |
308 | unsigned *p; /* pointer into c[], b[], or v[] */ | 308 | const unsigned *p; /* pointer into c[], b[], or v[] */ |
309 | huft_t *q; /* points to current table */ | 309 | huft_t *q; /* points to current table */ |
310 | huft_t r; /* table entry for structure assignment */ | 310 | huft_t r; /* table entry for structure assignment */ |
311 | huft_t *u[BMAX]; /* table stack */ | 311 | huft_t *u[BMAX]; /* table stack */ |
312 | unsigned v[N_MAX]; /* values in order of bit length */ | 312 | unsigned v[N_MAX]; /* values in order of bit length */ |
313 | unsigned v_end; | ||
313 | int ws[BMAX + 1]; /* bits decoded stack */ | 314 | int ws[BMAX + 1]; /* bits decoded stack */ |
314 | int w; /* bits decoded */ | 315 | int w; /* bits decoded */ |
315 | unsigned x[BMAX + 1]; /* bit offsets, then code stack */ | 316 | unsigned x[BMAX + 1]; /* bit offsets, then code stack */ |
@@ -324,7 +325,7 @@ static int huft_build(const unsigned *b, const unsigned n, | |||
324 | 325 | ||
325 | /* Generate counts for each bit length */ | 326 | /* Generate counts for each bit length */ |
326 | memset(c, 0, sizeof(c)); | 327 | memset(c, 0, sizeof(c)); |
327 | p = (unsigned *) b; /* cast allows us to reuse p for pointing to b */ | 328 | p = b; |
328 | i = n; | 329 | i = n; |
329 | do { | 330 | do { |
330 | c[*p]++; /* assume all entries <= BMAX */ | 331 | c[*p]++; /* assume all entries <= BMAX */ |
@@ -365,12 +366,14 @@ static int huft_build(const unsigned *b, const unsigned n, | |||
365 | } | 366 | } |
366 | 367 | ||
367 | /* Make a table of values in order of bit lengths */ | 368 | /* Make a table of values in order of bit lengths */ |
368 | p = (unsigned *) b; | 369 | p = b; |
369 | i = 0; | 370 | i = 0; |
371 | v_end = 0; | ||
370 | do { | 372 | do { |
371 | j = *p++; | 373 | j = *p++; |
372 | if (j != 0) { | 374 | if (j != 0) { |
373 | v[x[j]++] = i; | 375 | v[x[j]++] = i; |
376 | v_end = x[j]; | ||
374 | } | 377 | } |
375 | } while (++i < n); | 378 | } while (++i < n); |
376 | 379 | ||
@@ -432,7 +435,7 @@ static int huft_build(const unsigned *b, const unsigned n, | |||
432 | 435 | ||
433 | /* set up table entry in r */ | 436 | /* set up table entry in r */ |
434 | r.b = (unsigned char) (k - w); | 437 | r.b = (unsigned char) (k - w); |
435 | if (p >= v + n) { | 438 | if (p >= v + v_end) { // Was "if (p >= v + n)" but v[] can be shorter! |
436 | r.e = 99; /* out of values--invalid code */ | 439 | r.e = 99; /* out of values--invalid code */ |
437 | } else if (*p < s) { | 440 | } else if (*p < s) { |
438 | r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */ | 441 | r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */ |