aboutsummaryrefslogtreecommitdiff
path: root/archival/libunarchive
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-06-26 20:27:42 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-06-26 20:27:42 +0000
commit5fb79535eee16cada7748ceb38130b81e24c21b8 (patch)
tree34117dfa958e483c886e2fb26781c14b30c75308 /archival/libunarchive
parentf5d8c90d73777d912ddffea9dd7c537c3a1a43a5 (diff)
downloadbusybox-w32-5fb79535eee16cada7748ceb38130b81e24c21b8.tar.gz
busybox-w32-5fb79535eee16cada7748ceb38130b81e24c21b8.tar.bz2
busybox-w32-5fb79535eee16cada7748ceb38130b81e24c21b8.zip
bunzip2: fix an uncompression error. Add the example to testsuite.
Diffstat (limited to 'archival/libunarchive')
-rw-r--r--archival/libunarchive/decompress_bunzip2.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/archival/libunarchive/decompress_bunzip2.c b/archival/libunarchive/decompress_bunzip2.c
index 6da09fc1b..f5050449a 100644
--- a/archival/libunarchive/decompress_bunzip2.c
+++ b/archival/libunarchive/decompress_bunzip2.c
@@ -143,10 +143,12 @@ static unsigned get_bits(bunzip_data *bd, int bits_wanted)
143static int get_next_block(bunzip_data *bd) 143static int get_next_block(bunzip_data *bd)
144{ 144{
145 struct group_data *hufGroup; 145 struct group_data *hufGroup;
146 int dbufCount, nextSym, dbufSize, groupCount, *base, *limit, selector, 146 int dbufCount, nextSym, dbufSize, groupCount, *base, selector,
147 i, j, k, t, runPos, symCount, symTotal, nSelectors, byteCount[256]; 147 i, j, k, t, runPos, symCount, symTotal, nSelectors, byteCount[256];
148 unsigned char uc, symToByte[256], mtfSymbol[256], *selectors; 148 unsigned char uc, symToByte[256], mtfSymbol[256], *selectors;
149 unsigned *dbuf, origPtr; 149 /* limit was int* but was changed to unsigned* - grep for '[x]'
150 * in comment to see where it is important. -- vda */
151 unsigned *dbuf, *limit, origPtr;
150 152
151 dbuf = bd->dbuf; 153 dbuf = bd->dbuf;
152 dbufSize = bd->dbufSize; 154 dbufSize = bd->dbufSize;
@@ -288,7 +290,7 @@ static int get_next_block(bunzip_data *bd)
288 entry. We do this again when using them (during symbol decoding).*/ 290 entry. We do this again when using them (during symbol decoding).*/
289 291
290 base = hufGroup->base - 1; 292 base = hufGroup->base - 1;
291 limit = hufGroup->limit - 1; 293 limit = (unsigned*)hufGroup->limit - 1;
292 294
293 /* Calculate permute[]. Concurently, initialize temp[] and limit[]. */ 295 /* Calculate permute[]. Concurently, initialize temp[] and limit[]. */
294 296
@@ -326,6 +328,7 @@ static int get_next_block(bunzip_data *bd)
326 base[i+1] = pp - t; 328 base[i+1] = pp - t;
327 } 329 }
328 limit[maxLen+1] = INT_MAX; /* Sentinel value for reading next sym. */ 330 limit[maxLen+1] = INT_MAX; /* Sentinel value for reading next sym. */
331 /* [x] was observed to occasionally have -1 here: -- vda */
329 limit[maxLen] = pp + temp[maxLen] - 1; 332 limit[maxLen] = pp + temp[maxLen] - 1;
330 base[minLen] = 0; 333 base[minLen] = 0;
331 } 334 }
@@ -353,7 +356,7 @@ static int get_next_block(bunzip_data *bd)
353 if (selector >= nSelectors) return RETVAL_DATA_ERROR; 356 if (selector >= nSelectors) return RETVAL_DATA_ERROR;
354 hufGroup = bd->groups + selectors[selector++]; 357 hufGroup = bd->groups + selectors[selector++];
355 base = hufGroup->base - 1; 358 base = hufGroup->base - 1;
356 limit = hufGroup->limit - 1; 359 limit = (unsigned*)hufGroup->limit - 1;
357 continue_this_group: 360 continue_this_group:
358 361
359 /* Read next Huffman-coded symbol. */ 362 /* Read next Huffman-coded symbol. */
@@ -384,7 +387,7 @@ static int get_next_block(bunzip_data *bd)
384 /* Figure how how many bits are in next symbol and unget extras */ 387 /* Figure how how many bits are in next symbol and unget extras */
385 388
386 i = hufGroup->minLen; 389 i = hufGroup->minLen;
387 while (j > limit[i]) ++i; 390 while ((unsigned)j > limit[i]) ++i;
388 bd->inbufBitCount += (hufGroup->maxLen - i); 391 bd->inbufBitCount += (hufGroup->maxLen - i);
389 392
390 /* Huffman decode value to get nextSym (with bounds checking) */ 393 /* Huffman decode value to get nextSym (with bounds checking) */
@@ -507,7 +510,7 @@ static int get_next_block(bunzip_data *bd)
507 if (dbufCount) { 510 if (dbufCount) {
508 if ((int)origPtr >= dbufCount) return RETVAL_DATA_ERROR; 511 if ((int)origPtr >= dbufCount) return RETVAL_DATA_ERROR;
509 bd->writePos = dbuf[origPtr]; 512 bd->writePos = dbuf[origPtr];
510 bd->writeCurrent = (unsigned char)(bd->writePos & 0xff); 513 bd->writeCurrent = (unsigned char)(bd->writePos & 0xff);
511 bd->writePos >>= 8; 514 bd->writePos >>= 8;
512 bd->writeRunCountdown = 5; 515 bd->writeRunCountdown = 5;
513 } 516 }