Fix chunk flag setup when compression fails in adaptive mode.

Prevent display of non-fatal errors during compression.
This commit is contained in:
Moinak Ghosh 2012-11-09 21:07:23 +05:30
parent 77db54e712
commit 5b1a13480b
4 changed files with 22 additions and 16 deletions

View file

@ -135,7 +135,7 @@ lzma_deinit(void **data)
}
static void
lzerr(int err)
lzerr(int err, int cmp)
{
switch (err) {
case SZ_ERROR_MEM:
@ -154,7 +154,9 @@ lzerr(int err)
fprintf(stderr, "LZMA: More compressed input bytes expected\n");
break;
case SZ_ERROR_OUTPUT_EOF:
fprintf(stderr, "LZMA: Output buffer overflow\n");
/* This error is non-fatal during compression */
if (!cmp)
fprintf(stderr, "LZMA: Output buffer overflow\n");
break;
case SZ_ERROR_UNSUPPORTED:
fprintf(stderr, "LZMA: Unsupported properties\n");
@ -192,7 +194,7 @@ lzma_compress(void *src, size_t srclen, void *dst,
CLzmaEncProps *props = (CLzmaEncProps *)data;
if (*dstlen < LZMA_PROPS_SIZE) {
lzerr(SZ_ERROR_DESTLEN);
lzerr(SZ_ERROR_DESTLEN, 1);
return (-1);
}
props->level = level;
@ -203,7 +205,7 @@ lzma_compress(void *src, size_t srclen, void *dst,
props, _dst, &props_len, 0, NULL, &g_Alloc, &g_Alloc);
if (res != 0) {
lzerr(res);
lzerr(res, 1);
return (-1);
}
@ -226,7 +228,7 @@ lzma_decompress(void *src, size_t srclen, void *dst,
if ((res = LzmaDecode((uchar_t *)dst, dstlen, _src, &_srclen,
src, LZMA_PROPS_SIZE, LZMA_FINISH_ANY,
&status, &g_Alloc)) != SZ_OK) {
lzerr(res);
lzerr(res, 0);
return (-1);
}
return (0);

1
main.c
View file

@ -1108,6 +1108,7 @@ plain_compress:
memcpy(compressed_chunk, tdat->uncompressed_chunk, tdat->rbytes);
type = UNCOMPRESSED;
tdat->len_cmp = tdat->rbytes;
if (rv < 0) rv = COMPRESS_NONE;
} else {
type = COMPRESSED;
}

View file

@ -69,6 +69,7 @@ extern "C" {
* lower 3 bits in higher nibble indicate chunk compression algorithm
* in adaptive modes.
*/
#define COMPRESS_NONE 0
#define COMPRESS_LZMA 1
#define COMPRESS_BZIP2 2
#define COMPRESS_PPMD 3

View file

@ -34,7 +34,7 @@
*/
#define SINGLE_CALL_MAX (2147483648UL)
static void zerr(int ret);
static void zerr(int ret, int cmp);
static void *
slab_alloc_ui(void *p, unsigned int items, unsigned int size) {
@ -67,7 +67,7 @@ zlib_init(void **data, int *level, int nthreads, ssize_t chunksize)
if (*level > 9) *level = 9;
ret = deflateInit(zs, *level);
if (ret != Z_OK) {
zerr(ret);
zerr(ret, 0);
return (-1);
}
@ -91,7 +91,7 @@ zlib_deinit(void **data)
}
static
void zerr(int ret)
void zerr(int ret, int cmp)
{
switch (ret) {
case Z_ERRNO:
@ -110,7 +110,9 @@ void zerr(int ret)
fprintf(stderr, "Zlib: Version mismatch!\n");
break;
case Z_BUF_ERROR:
fprintf(stderr, "Zlib: Buffer error decompression failed.\n");
/* This error is non-fatal during compression. */
if (!cmp)
fprintf(stderr, "Zlib: Buffer error decompression failed.\n");
break;
case Z_NEED_DICT:
fprintf(stderr, "Zlib: Need present dictionary.\n");
@ -154,7 +156,7 @@ zlib_compress(void *src, size_t srclen, void *dst, size_t *dstlen,
ret = deflate(zs, Z_NO_FLUSH);
if (ret != Z_OK) {
deflateReset(zs);
zerr(ret);
zerr(ret, 1);
return (-1);
}
} else {
@ -162,9 +164,9 @@ zlib_compress(void *src, size_t srclen, void *dst, size_t *dstlen,
if (ret != Z_STREAM_END) {
deflateReset(zs);
if (ret == Z_OK)
zerr(Z_BUF_ERROR);
zerr(Z_BUF_ERROR, 1);
else
zerr(ret);
zerr(ret, 1);
return (-1);
}
}
@ -177,7 +179,7 @@ zlib_compress(void *src, size_t srclen, void *dst, size_t *dstlen,
*dstlen = *dstlen - _dstlen;
ret = deflateReset(zs);
if (ret != Z_OK) {
zerr(ret);
zerr(ret, 1);
return (-1);
}
return (0);
@ -200,7 +202,7 @@ zlib_decompress(void *src, size_t srclen, void *dst, size_t *dstlen,
zs.opaque = NULL;
if ((err = inflateInit(&zs)) != Z_OK) {
zerr(err);
zerr(err, 0);
return (-1);
}
@ -223,7 +225,7 @@ zlib_decompress(void *src, size_t srclen, void *dst, size_t *dstlen,
err = inflate(&zs, Z_NO_FLUSH);
if (err != Z_OK && err != Z_STREAM_END) {
zerr(err);
zerr(err, 0);
return (-1);
}
@ -234,7 +236,7 @@ zlib_decompress(void *src, size_t srclen, void *dst, size_t *dstlen,
if (err == Z_STREAM_END) {
if (_srclen > 0) {
zerr(Z_DATA_ERROR);
zerr(Z_DATA_ERROR, 0);
return (-1);
} else {
break;