Stopped doing assignments inside expressions.
Who wrote this gem, I wonder? n -= (e = (e = gunzip_wsize - ((d &= gunzip_wsize - 1) > w ? d : w)) > n ? n : e);
This commit is contained in:
parent
cc33ef12d2
commit
447b543eaf
@ -64,12 +64,6 @@
|
|||||||
#undef MAXSEG_64K
|
#undef MAXSEG_64K
|
||||||
#define MAXCODE(n) (1L << (n))
|
#define MAXCODE(n) (1L << (n))
|
||||||
|
|
||||||
/* Block compress mode -C compatible with 2.0 */
|
|
||||||
static int block_mode = BLOCK_MODE;
|
|
||||||
|
|
||||||
/* user settable max # bits/code */
|
|
||||||
static int maxbits = BITS;
|
|
||||||
|
|
||||||
#define htabof(i) htab[i]
|
#define htabof(i) htab[i]
|
||||||
#define codetabof(i) codetab[i]
|
#define codetabof(i) codetab[i]
|
||||||
#define tab_prefixof(i) codetabof(i)
|
#define tab_prefixof(i) codetabof(i)
|
||||||
@ -109,25 +103,38 @@ uncompress(int fd_in, int fd_out)
|
|||||||
RESERVE_CONFIG_UBUFFER(outbuf, OBUFSIZ + 2048);
|
RESERVE_CONFIG_UBUFFER(outbuf, OBUFSIZ + 2048);
|
||||||
unsigned char htab[HSIZE];
|
unsigned char htab[HSIZE];
|
||||||
unsigned short codetab[HSIZE];
|
unsigned short codetab[HSIZE];
|
||||||
|
|
||||||
|
/* Hmm, these were statics - why?! */
|
||||||
|
/* user settable max # bits/code */
|
||||||
|
int maxbits; /* = BITS; */
|
||||||
|
/* block compress mode -C compatible with 2.0 */
|
||||||
|
int block_mode; /* = BLOCK_MODE; */
|
||||||
|
|
||||||
memset(inbuf, 0, IBUFSIZ + 64);
|
memset(inbuf, 0, IBUFSIZ + 64);
|
||||||
memset(outbuf, 0, OBUFSIZ + 2048);
|
memset(outbuf, 0, OBUFSIZ + 2048);
|
||||||
|
|
||||||
insize = 0;
|
insize = 0;
|
||||||
|
|
||||||
inbuf[0] = xread_char(fd_in);
|
/* xread isn't good here, we have to return - caller may want
|
||||||
|
* to do some cleanup (e.g. delete incomplete unpacked file etc) */
|
||||||
|
if (full_read(fd_in, inbuf, 1) != 1) {
|
||||||
|
bb_error_msg("short read");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
maxbits = inbuf[0] & BIT_MASK;
|
maxbits = inbuf[0] & BIT_MASK;
|
||||||
block_mode = inbuf[0] & BLOCK_MODE;
|
block_mode = inbuf[0] & BLOCK_MODE;
|
||||||
maxmaxcode = MAXCODE(maxbits);
|
maxmaxcode = MAXCODE(maxbits);
|
||||||
|
|
||||||
if (maxbits > BITS) {
|
if (maxbits > BITS) {
|
||||||
bb_error_msg("compressed with %d bits, can only handle %d bits", maxbits,
|
bb_error_msg("compressed with %d bits, can only handle "
|
||||||
BITS);
|
"%d bits", maxbits, BITS);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
maxcode = MAXCODE(n_bits = INIT_BITS) - 1;
|
n_bits = INIT_BITS;
|
||||||
bitmask = (1 << n_bits) - 1;
|
maxcode = MAXCODE(INIT_BITS) - 1;
|
||||||
|
bitmask = (1 << INIT_BITS) - 1;
|
||||||
oldcode = -1;
|
oldcode = -1;
|
||||||
finchar = 0;
|
finchar = 0;
|
||||||
outpos = 0;
|
outpos = 0;
|
||||||
@ -143,13 +150,14 @@ uncompress(int fd_in, int fd_out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
resetbuf:;
|
resetbuf:
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int e;
|
int e;
|
||||||
int o;
|
int o;
|
||||||
|
|
||||||
e = insize - (o = (posbits >> 3));
|
o = posbits >> 3;
|
||||||
|
e = insize - o;
|
||||||
|
|
||||||
for (i = 0; i < e; ++i)
|
for (i = 0; i < e; ++i)
|
||||||
inbuf[i] = inbuf[i + o];
|
inbuf[i] = inbuf[i + o];
|
||||||
@ -160,6 +168,7 @@ uncompress(int fd_in, int fd_out)
|
|||||||
|
|
||||||
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
|
if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
|
||||||
rsize = safe_read(fd_in, inbuf + insize, IBUFSIZ);
|
rsize = safe_read(fd_in, inbuf + insize, IBUFSIZ);
|
||||||
|
//error check??
|
||||||
insize += rsize;
|
insize += rsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,8 +193,8 @@ uncompress(int fd_in, int fd_out)
|
|||||||
{
|
{
|
||||||
unsigned char *p = &inbuf[posbits >> 3];
|
unsigned char *p = &inbuf[posbits >> 3];
|
||||||
|
|
||||||
code = ((((long) (p[0])) | ((long) (p[1]) << 8) |
|
code = ((((long) (p[0])) | ((long) (p[1]) << 8) |
|
||||||
((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
|
((long) (p[2]) << 16)) >> (posbits & 0x7)) & bitmask;
|
||||||
}
|
}
|
||||||
posbits += n_bits;
|
posbits += n_bits;
|
||||||
|
|
||||||
@ -204,8 +213,9 @@ uncompress(int fd_in, int fd_out)
|
|||||||
((posbits - 1) +
|
((posbits - 1) +
|
||||||
((n_bits << 3) -
|
((n_bits << 3) -
|
||||||
(posbits - 1 + (n_bits << 3)) % (n_bits << 3)));
|
(posbits - 1 + (n_bits << 3)) % (n_bits << 3)));
|
||||||
maxcode = MAXCODE(n_bits = INIT_BITS) - 1;
|
n_bits = INIT_BITS;
|
||||||
bitmask = (1 << n_bits) - 1;
|
maxcode = MAXCODE(INIT_BITS) - 1;
|
||||||
|
bitmask = (1 << INIT_BITS) - 1;
|
||||||
goto resetbuf;
|
goto resetbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,13 +248,15 @@ uncompress(int fd_in, int fd_out)
|
|||||||
code = tab_prefixof(code);
|
code = tab_prefixof(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*--stackp = (unsigned char) (finchar = tab_suffixof(code));
|
finchar = tab_suffixof(code);
|
||||||
|
*--stackp = (unsigned char) finchar;
|
||||||
|
|
||||||
/* And put them out in forward order */
|
/* And put them out in forward order */
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (outpos + (i = (de_stack - stackp)) >= OBUFSIZ) {
|
i = de_stack - stackp;
|
||||||
|
if (outpos + i >= OBUFSIZ) {
|
||||||
do {
|
do {
|
||||||
if (i > OBUFSIZ - outpos) {
|
if (i > OBUFSIZ - outpos) {
|
||||||
i = OBUFSIZ - outpos;
|
i = OBUFSIZ - outpos;
|
||||||
@ -256,12 +268,14 @@ uncompress(int fd_in, int fd_out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (outpos >= OBUFSIZ) {
|
if (outpos >= OBUFSIZ) {
|
||||||
write(fd_out, outbuf, outpos);
|
full_write(fd_out, outbuf, outpos);
|
||||||
|
//error check??
|
||||||
USE_DESKTOP(total_written += outpos;)
|
USE_DESKTOP(total_written += outpos;)
|
||||||
outpos = 0;
|
outpos = 0;
|
||||||
}
|
}
|
||||||
stackp += i;
|
stackp += i;
|
||||||
} while ((i = (de_stack - stackp)) > 0);
|
i = de_stack - stackp;
|
||||||
|
} while (i > 0);
|
||||||
} else {
|
} else {
|
||||||
memcpy(outbuf + outpos, stackp, i);
|
memcpy(outbuf + outpos, stackp, i);
|
||||||
outpos += i;
|
outpos += i;
|
||||||
@ -269,7 +283,8 @@ uncompress(int fd_in, int fd_out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Generate the new entry. */
|
/* Generate the new entry. */
|
||||||
if ((code = free_ent) < maxmaxcode) {
|
code = free_ent;
|
||||||
|
if (code < maxmaxcode) {
|
||||||
tab_prefixof(code) = (unsigned short) oldcode;
|
tab_prefixof(code) = (unsigned short) oldcode;
|
||||||
tab_suffixof(code) = (unsigned char) finchar;
|
tab_suffixof(code) = (unsigned char) finchar;
|
||||||
free_ent = code + 1;
|
free_ent = code + 1;
|
||||||
@ -282,7 +297,8 @@ uncompress(int fd_in, int fd_out)
|
|||||||
} while (rsize > 0);
|
} while (rsize > 0);
|
||||||
|
|
||||||
if (outpos > 0) {
|
if (outpos > 0) {
|
||||||
write(fd_out, outbuf, outpos);
|
full_write(fd_out, outbuf, outpos);
|
||||||
|
//error check??
|
||||||
USE_DESKTOP(total_written += outpos;)
|
USE_DESKTOP(total_written += outpos;)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,9 @@ static unsigned fill_bitbuffer(unsigned bitbuffer, unsigned *current, const unsi
|
|||||||
/* Leave the first 4 bytes empty so we can always unwind the bitbuffer
|
/* Leave the first 4 bytes empty so we can always unwind the bitbuffer
|
||||||
* to the front of the bytebuffer, leave 4 bytes free at end of tail
|
* to the front of the bytebuffer, leave 4 bytes free at end of tail
|
||||||
* so we can easily top up buffer in check_trailer_gzip() */
|
* so we can easily top up buffer in check_trailer_gzip() */
|
||||||
if (1 > (bytebuffer_size = safe_read(gunzip_src_fd, &bytebuffer[4], bytebuffer_max - 8)))
|
bytebuffer_size = safe_read(gunzip_src_fd, &bytebuffer[4], bytebuffer_max - 8);
|
||||||
|
if (1 > bytebuffer_size)
|
||||||
|
//shouldn't we propagate error?
|
||||||
bb_error_msg_and_die("unexpected end of file");
|
bb_error_msg_and_die("unexpected end of file");
|
||||||
bytebuffer_size += 4;
|
bytebuffer_size += 4;
|
||||||
bytebuffer_offset = 4;
|
bytebuffer_offset = 4;
|
||||||
@ -193,7 +195,7 @@ int huft_build(unsigned *b, const unsigned n,
|
|||||||
eob_len = n > 256 ? b[256] : BMAX;
|
eob_len = n > 256 ? b[256] : BMAX;
|
||||||
|
|
||||||
/* Generate counts for each bit length */
|
/* Generate counts for each bit length */
|
||||||
memset((void *)c, 0, sizeof(c));
|
memset(c, 0, sizeof(c));
|
||||||
p = b;
|
p = b;
|
||||||
i = n;
|
i = n;
|
||||||
do {
|
do {
|
||||||
@ -215,11 +217,13 @@ int huft_build(unsigned *b, const unsigned n,
|
|||||||
|
|
||||||
/* Adjust last length count to fill out codes, if needed */
|
/* Adjust last length count to fill out codes, if needed */
|
||||||
for (y = 1 << j; j < i; j++, y <<= 1) {
|
for (y = 1 << j; j < i; j++, y <<= 1) {
|
||||||
if ((y -= c[j]) < 0) {
|
y -= c[j];
|
||||||
|
if (y < 0) {
|
||||||
return 2; /* bad input: more codes than bits */
|
return 2; /* bad input: more codes than bits */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((y -= c[i]) < 0) {
|
y -= c[i];
|
||||||
|
if (y < 0) {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
c[i] += y;
|
c[i] += y;
|
||||||
@ -229,14 +233,16 @@ int huft_build(unsigned *b, const unsigned n,
|
|||||||
p = c + 1;
|
p = c + 1;
|
||||||
xp = x + 2;
|
xp = x + 2;
|
||||||
while (--i) { /* note that i == g from above */
|
while (--i) { /* note that i == g from above */
|
||||||
*xp++ = (j += *p++);
|
j += *p++;
|
||||||
|
*xp++ = j;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make a table of values in order of bit lengths */
|
/* Make a table of values in order of bit lengths */
|
||||||
p = b;
|
p = b;
|
||||||
i = 0;
|
i = 0;
|
||||||
do {
|
do {
|
||||||
if ((j = *p++) != 0) {
|
j = *p++;
|
||||||
|
if (j != 0) {
|
||||||
v[x[j]++] = i;
|
v[x[j]++] = i;
|
||||||
}
|
}
|
||||||
} while (++i < n);
|
} while (++i < n);
|
||||||
@ -260,13 +266,17 @@ int huft_build(unsigned *b, const unsigned n,
|
|||||||
w = ws[++htl];
|
w = ws[++htl];
|
||||||
|
|
||||||
/* compute minimum size table less than or equal to *m bits */
|
/* compute minimum size table less than or equal to *m bits */
|
||||||
z = (z = g - w) > *m ? *m : z; /* upper limit on table size */
|
z = g - w;
|
||||||
if ((f = 1 << (j = k - w)) > a + 1) { /* try a k-w bit table */
|
z = z > *m ? *m : z; /* upper limit on table size */
|
||||||
|
j = k - w;
|
||||||
|
f = 1 << j;
|
||||||
|
if (f > a + 1) { /* try a k-w bit table */
|
||||||
/* too few codes for k-w bit table */
|
/* too few codes for k-w bit table */
|
||||||
f -= a + 1; /* deduct codes from patterns left */
|
f -= a + 1; /* deduct codes from patterns left */
|
||||||
xp = c + k;
|
xp = c + k;
|
||||||
while (++j < z) { /* try smaller tables up to z bits */
|
while (++j < z) { /* try smaller tables up to z bits */
|
||||||
if ((f <<= 1) <= *++xp) {
|
f <<= 1;
|
||||||
|
if (f <= *++xp) {
|
||||||
break; /* enough codes to use up j bits */
|
break; /* enough codes to use up j bits */
|
||||||
}
|
}
|
||||||
f -= *xp; /* else deduct codes from patterns */
|
f -= *xp; /* else deduct codes from patterns */
|
||||||
@ -338,6 +348,8 @@ int huft_build(unsigned *b, const unsigned n,
|
|||||||
* tl, td: literal/length and distance decoder tables
|
* tl, td: literal/length and distance decoder tables
|
||||||
* bl, bd: number of bits decoded by tl[] and td[]
|
* bl, bd: number of bits decoded by tl[] and td[]
|
||||||
*/
|
*/
|
||||||
|
/* called with setup==1 once from inflate_block */
|
||||||
|
/* called once with setup==0 from inflate_get_next_window */
|
||||||
static int inflate_codes(huft_t * my_tl, huft_t * my_td, const unsigned my_bl, const unsigned my_bd, int setup)
|
static int inflate_codes(huft_t * my_tl, huft_t * my_td, const unsigned my_bl, const unsigned my_bd, int setup)
|
||||||
{
|
{
|
||||||
static unsigned e; /* table entry flag/number of extra bits */
|
static unsigned e; /* table entry flag/number of extra bits */
|
||||||
@ -371,7 +383,9 @@ static int inflate_codes(huft_t * my_tl, huft_t * my_td, const unsigned my_bl, c
|
|||||||
|
|
||||||
while (1) { /* do until end of block */
|
while (1) { /* do until end of block */
|
||||||
b = fill_bitbuffer(b, &k, bl);
|
b = fill_bitbuffer(b, &k, bl);
|
||||||
if ((e = (t = tl + ((unsigned) b & ml))->e) > 16)
|
t = tl + ((unsigned) b & ml);
|
||||||
|
e = t->e;
|
||||||
|
if (e > 16)
|
||||||
do {
|
do {
|
||||||
if (e == 99) {
|
if (e == 99) {
|
||||||
bb_error_msg_and_die("inflate_codes error 1");
|
bb_error_msg_and_die("inflate_codes error 1");
|
||||||
@ -380,8 +394,9 @@ static int inflate_codes(huft_t * my_tl, huft_t * my_td, const unsigned my_bl, c
|
|||||||
k -= t->b;
|
k -= t->b;
|
||||||
e -= 16;
|
e -= 16;
|
||||||
b = fill_bitbuffer(b, &k, e);
|
b = fill_bitbuffer(b, &k, e);
|
||||||
} while ((e =
|
t = t->v.t + ((unsigned) b & mask_bits[e]);
|
||||||
(t = t->v.t + ((unsigned) b & mask_bits[e]))->e) > 16);
|
e = t->e;
|
||||||
|
} while (e > 16);
|
||||||
b >>= t->b;
|
b >>= t->b;
|
||||||
k -= t->b;
|
k -= t->b;
|
||||||
if (e == 16) { /* then it's a literal */
|
if (e == 16) { /* then it's a literal */
|
||||||
@ -407,7 +422,9 @@ static int inflate_codes(huft_t * my_tl, huft_t * my_td, const unsigned my_bl, c
|
|||||||
|
|
||||||
/* decode distance of block to copy */
|
/* decode distance of block to copy */
|
||||||
b = fill_bitbuffer(b, &k, bd);
|
b = fill_bitbuffer(b, &k, bd);
|
||||||
if ((e = (t = td + ((unsigned) b & md))->e) > 16)
|
t = td + ((unsigned) b & md);
|
||||||
|
e = t->e;
|
||||||
|
if (e > 16)
|
||||||
do {
|
do {
|
||||||
if (e == 99)
|
if (e == 99)
|
||||||
bb_error_msg_and_die("inflate_codes error 2");
|
bb_error_msg_and_die("inflate_codes error 2");
|
||||||
@ -415,9 +432,9 @@ static int inflate_codes(huft_t * my_tl, huft_t * my_td, const unsigned my_bl, c
|
|||||||
k -= t->b;
|
k -= t->b;
|
||||||
e -= 16;
|
e -= 16;
|
||||||
b = fill_bitbuffer(b, &k, e);
|
b = fill_bitbuffer(b, &k, e);
|
||||||
} while ((e =
|
t = t->v.t + ((unsigned) b & mask_bits[e]);
|
||||||
(t =
|
e = t->e;
|
||||||
t->v.t + ((unsigned) b & mask_bits[e]))->e) > 16);
|
} while (e > 16);
|
||||||
b >>= t->b;
|
b >>= t->b;
|
||||||
k -= t->b;
|
k -= t->b;
|
||||||
b = fill_bitbuffer(b, &k, e);
|
b = fill_bitbuffer(b, &k, e);
|
||||||
@ -426,26 +443,30 @@ static int inflate_codes(huft_t * my_tl, huft_t * my_td, const unsigned my_bl, c
|
|||||||
k -= e;
|
k -= e;
|
||||||
|
|
||||||
/* do the copy */
|
/* do the copy */
|
||||||
do_copy: do {
|
do_copy:
|
||||||
n -= (e =
|
do {
|
||||||
(e =
|
/* Was: n -= (e = (e = gunzip_wsize - ((d &= gunzip_wsize - 1) > w ? d : w)) > n ? n : e); */
|
||||||
gunzip_wsize - ((d &= gunzip_wsize - 1) > w ? d : w)) > n ? n : e);
|
/* Who wrote THAT?? rewritten as: */
|
||||||
/* copy to new buffer to prevent possible overwrite */
|
d &= gunzip_wsize - 1;
|
||||||
|
e = gunzip_wsize - (d > w ? d : w);
|
||||||
|
if (e > n) e = n;
|
||||||
|
n -= e;
|
||||||
|
|
||||||
|
/* copy to new buffer to prevent possible overwrite */
|
||||||
if (w - d >= e) { /* (this test assumes unsigned comparison) */
|
if (w - d >= e) { /* (this test assumes unsigned comparison) */
|
||||||
memcpy(gunzip_window + w, gunzip_window + d, e);
|
memcpy(gunzip_window + w, gunzip_window + d, e);
|
||||||
w += e;
|
w += e;
|
||||||
d += e;
|
d += e;
|
||||||
} else {
|
} else {
|
||||||
/* do it slow to avoid memcpy() overlap */
|
/* do it slow to avoid memcpy() overlap */
|
||||||
/* !NOMEMCPY */
|
/* !NOMEMCPY */
|
||||||
do {
|
do {
|
||||||
gunzip_window[w++] = gunzip_window[d++];
|
gunzip_window[w++] = gunzip_window[d++];
|
||||||
} while (--e);
|
} while (--e);
|
||||||
}
|
}
|
||||||
if (w == gunzip_wsize) {
|
if (w == gunzip_wsize) {
|
||||||
gunzip_outbuf_count = (w);
|
gunzip_outbuf_count = (w);
|
||||||
if (n) resumeCopy = 1;
|
resumeCopy = (n != 0);
|
||||||
else resumeCopy = 0;
|
|
||||||
//flush_gunzip_window();
|
//flush_gunzip_window();
|
||||||
w = 0;
|
w = 0;
|
||||||
return 1;
|
return 1;
|
||||||
@ -469,9 +490,12 @@ do_copy: do {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* called once (setup==1) from inflate_block */
|
||||||
|
/* and once (setup==0) from inflate_get_next_window */
|
||||||
static int inflate_stored(int my_n, int my_b_stored, int my_k_stored, int setup)
|
static int inflate_stored(int my_n, int my_b_stored, int my_k_stored, int setup)
|
||||||
{
|
{
|
||||||
static unsigned n, b_stored, k_stored, w;
|
static unsigned n, b_stored, k_stored, w;
|
||||||
|
|
||||||
if (setup) {
|
if (setup) {
|
||||||
n = my_n;
|
n = my_n;
|
||||||
b_stored = my_b_stored;
|
b_stored = my_b_stored;
|
||||||
@ -509,7 +533,8 @@ static int inflate_stored(int my_n, int my_b_stored, int my_k_stored, int setup)
|
|||||||
*
|
*
|
||||||
* GLOBAL VARIABLES: bb, kk,
|
* GLOBAL VARIABLES: bb, kk,
|
||||||
*/
|
*/
|
||||||
// Return values: -1 = inflate_stored, -2 = inflate_codes
|
/* Return values: -1 = inflate_stored, -2 = inflate_codes */
|
||||||
|
/* One callsite in inflate_get_next_window */
|
||||||
static int inflate_block(int *e)
|
static int inflate_block(int *e)
|
||||||
{
|
{
|
||||||
unsigned t; /* block type */
|
unsigned t; /* block type */
|
||||||
@ -597,7 +622,8 @@ static int inflate_block(int *e)
|
|||||||
l[i] = 8;
|
l[i] = 8;
|
||||||
}
|
}
|
||||||
bl = 7;
|
bl = 7;
|
||||||
if ((i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl)) != 0) {
|
i = huft_build(l, 288, 257, cplens, cplext, &tl, &bl);
|
||||||
|
if (i != 0) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -606,7 +632,8 @@ static int inflate_block(int *e)
|
|||||||
l[i] = 5;
|
l[i] = 5;
|
||||||
}
|
}
|
||||||
bd = 5;
|
bd = 5;
|
||||||
if ((i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd)) > 1) {
|
i = huft_build(l, 30, 0, cpdist, cpdext, &td, &bd);
|
||||||
|
if (i > 1) {
|
||||||
huft_free(tl);
|
huft_free(tl);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@ -745,19 +772,21 @@ static int inflate_block(int *e)
|
|||||||
/* build the decoding tables for literal/length and distance codes */
|
/* build the decoding tables for literal/length and distance codes */
|
||||||
bl = lbits;
|
bl = lbits;
|
||||||
|
|
||||||
if ((i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl)) != 0) {
|
i = huft_build(ll, nl, 257, cplens, cplext, &tl, &bl);
|
||||||
|
if (i != 0) {
|
||||||
if (i == 1) {
|
if (i == 1) {
|
||||||
bb_error_msg_and_die("incomplete literal tree");
|
bb_error_msg_and_die("incomplete literal tree");
|
||||||
huft_free(tl);
|
/* huft_free(tl); */
|
||||||
}
|
}
|
||||||
return i; /* incomplete code set */
|
return i; /* incomplete code set */
|
||||||
}
|
}
|
||||||
|
|
||||||
bd = dbits;
|
bd = dbits;
|
||||||
if ((i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd)) != 0) {
|
i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &td, &bd);
|
||||||
|
if (i != 0) {
|
||||||
if (i == 1) {
|
if (i == 1) {
|
||||||
bb_error_msg_and_die("incomplete distance tree");
|
bb_error_msg_and_die("incomplete distance tree");
|
||||||
huft_free(td);
|
/* huft_free(td); */
|
||||||
}
|
}
|
||||||
huft_free(tl);
|
huft_free(tl);
|
||||||
return i; /* incomplete code set */
|
return i; /* incomplete code set */
|
||||||
@ -776,6 +805,7 @@ static int inflate_block(int *e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Two callsites, both in inflate_get_next_window */
|
||||||
static void calculate_gunzip_crc(void)
|
static void calculate_gunzip_crc(void)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
@ -785,6 +815,7 @@ static void calculate_gunzip_crc(void)
|
|||||||
gunzip_bytes_out += gunzip_outbuf_count;
|
gunzip_bytes_out += gunzip_outbuf_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* One callsite in inflate_unzip */
|
||||||
static int inflate_get_next_window(void)
|
static int inflate_get_next_window(void)
|
||||||
{
|
{
|
||||||
static int method = -1; // Method == -1 for stored, -2 for codes
|
static int method = -1; // Method == -1 for stored, -2 for codes
|
||||||
@ -823,7 +854,8 @@ static int inflate_get_next_window(void)
|
|||||||
/* Doesnt get here */
|
/* Doesnt get here */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialise bytebuffer, be careful not to overfill the buffer */
|
/* Initialize bytebuffer, be careful not to overfill the buffer */
|
||||||
|
/* Called from archival/unzip.c */
|
||||||
void inflate_init(unsigned bufsize)
|
void inflate_init(unsigned bufsize)
|
||||||
{
|
{
|
||||||
/* Set the bytebuffer size, default is same as gunzip_wsize */
|
/* Set the bytebuffer size, default is same as gunzip_wsize */
|
||||||
@ -832,11 +864,13 @@ void inflate_init(unsigned bufsize)
|
|||||||
bytebuffer_size = 0;
|
bytebuffer_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Called from archival/unzip.c */
|
||||||
void inflate_cleanup(void)
|
void inflate_cleanup(void)
|
||||||
{
|
{
|
||||||
free(bytebuffer);
|
free(bytebuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Called from inflate_gunzip() and archival/unzip.c */
|
||||||
USE_DESKTOP(long long) int
|
USE_DESKTOP(long long) int
|
||||||
inflate_unzip(int in, int out)
|
inflate_unzip(int in, int out)
|
||||||
{
|
{
|
||||||
@ -864,7 +898,7 @@ inflate_unzip(int in, int out)
|
|||||||
while (1) {
|
while (1) {
|
||||||
int ret = inflate_get_next_window();
|
int ret = inflate_get_next_window();
|
||||||
nwrote = full_write(out, gunzip_window, gunzip_outbuf_count);
|
nwrote = full_write(out, gunzip_window, gunzip_outbuf_count);
|
||||||
if (nwrote == -1) {
|
if (nwrote != gunzip_outbuf_count) {
|
||||||
bb_perror_msg("write");
|
bb_perror_msg("write");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -901,6 +935,7 @@ inflate_gunzip(int in, int out)
|
|||||||
count = bytebuffer_size - bytebuffer_offset;
|
count = bytebuffer_size - bytebuffer_offset;
|
||||||
if (count < 8) {
|
if (count < 8) {
|
||||||
xread(in, &bytebuffer[bytebuffer_size], 8 - count);
|
xread(in, &bytebuffer[bytebuffer_size], 8 - count);
|
||||||
|
//shouldn't we propagate error?
|
||||||
bytebuffer_size += 8 - count;
|
bytebuffer_size += 8 - count;
|
||||||
}
|
}
|
||||||
for (count = 0; count != 4; count++) {
|
for (count = 0; count != 4; count++) {
|
||||||
@ -917,7 +952,8 @@ inflate_gunzip(int in, int out)
|
|||||||
/* Validate decompression - size */
|
/* Validate decompression - size */
|
||||||
if (gunzip_bytes_out !=
|
if (gunzip_bytes_out !=
|
||||||
(bytebuffer[bytebuffer_offset] | (bytebuffer[bytebuffer_offset+1] << 8) |
|
(bytebuffer[bytebuffer_offset] | (bytebuffer[bytebuffer_offset+1] << 8) |
|
||||||
(bytebuffer[bytebuffer_offset+2] << 16) | (bytebuffer[bytebuffer_offset+3] << 24))) {
|
(bytebuffer[bytebuffer_offset+2] << 16) | (bytebuffer[bytebuffer_offset+3] << 24))
|
||||||
|
) {
|
||||||
bb_error_msg("incorrect length");
|
bb_error_msg("incorrect length");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user