Fix chunk flag setup when compression fails in adaptive mode.
Prevent display of non-fatal errors during compression.
This commit is contained in:
parent
77db54e712
commit
5b1a13480b
4 changed files with 22 additions and 16 deletions
|
@ -135,7 +135,7 @@ lzma_deinit(void **data)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
lzerr(int err)
|
lzerr(int err, int cmp)
|
||||||
{
|
{
|
||||||
switch (err) {
|
switch (err) {
|
||||||
case SZ_ERROR_MEM:
|
case SZ_ERROR_MEM:
|
||||||
|
@ -154,7 +154,9 @@ lzerr(int err)
|
||||||
fprintf(stderr, "LZMA: More compressed input bytes expected\n");
|
fprintf(stderr, "LZMA: More compressed input bytes expected\n");
|
||||||
break;
|
break;
|
||||||
case SZ_ERROR_OUTPUT_EOF:
|
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;
|
break;
|
||||||
case SZ_ERROR_UNSUPPORTED:
|
case SZ_ERROR_UNSUPPORTED:
|
||||||
fprintf(stderr, "LZMA: Unsupported properties\n");
|
fprintf(stderr, "LZMA: Unsupported properties\n");
|
||||||
|
@ -192,7 +194,7 @@ lzma_compress(void *src, size_t srclen, void *dst,
|
||||||
CLzmaEncProps *props = (CLzmaEncProps *)data;
|
CLzmaEncProps *props = (CLzmaEncProps *)data;
|
||||||
|
|
||||||
if (*dstlen < LZMA_PROPS_SIZE) {
|
if (*dstlen < LZMA_PROPS_SIZE) {
|
||||||
lzerr(SZ_ERROR_DESTLEN);
|
lzerr(SZ_ERROR_DESTLEN, 1);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
props->level = level;
|
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);
|
props, _dst, &props_len, 0, NULL, &g_Alloc, &g_Alloc);
|
||||||
|
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
lzerr(res);
|
lzerr(res, 1);
|
||||||
return (-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,
|
if ((res = LzmaDecode((uchar_t *)dst, dstlen, _src, &_srclen,
|
||||||
src, LZMA_PROPS_SIZE, LZMA_FINISH_ANY,
|
src, LZMA_PROPS_SIZE, LZMA_FINISH_ANY,
|
||||||
&status, &g_Alloc)) != SZ_OK) {
|
&status, &g_Alloc)) != SZ_OK) {
|
||||||
lzerr(res);
|
lzerr(res, 0);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
|
1
main.c
1
main.c
|
@ -1108,6 +1108,7 @@ plain_compress:
|
||||||
memcpy(compressed_chunk, tdat->uncompressed_chunk, tdat->rbytes);
|
memcpy(compressed_chunk, tdat->uncompressed_chunk, tdat->rbytes);
|
||||||
type = UNCOMPRESSED;
|
type = UNCOMPRESSED;
|
||||||
tdat->len_cmp = tdat->rbytes;
|
tdat->len_cmp = tdat->rbytes;
|
||||||
|
if (rv < 0) rv = COMPRESS_NONE;
|
||||||
} else {
|
} else {
|
||||||
type = COMPRESSED;
|
type = COMPRESSED;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ extern "C" {
|
||||||
* lower 3 bits in higher nibble indicate chunk compression algorithm
|
* lower 3 bits in higher nibble indicate chunk compression algorithm
|
||||||
* in adaptive modes.
|
* in adaptive modes.
|
||||||
*/
|
*/
|
||||||
|
#define COMPRESS_NONE 0
|
||||||
#define COMPRESS_LZMA 1
|
#define COMPRESS_LZMA 1
|
||||||
#define COMPRESS_BZIP2 2
|
#define COMPRESS_BZIP2 2
|
||||||
#define COMPRESS_PPMD 3
|
#define COMPRESS_PPMD 3
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
*/
|
*/
|
||||||
#define SINGLE_CALL_MAX (2147483648UL)
|
#define SINGLE_CALL_MAX (2147483648UL)
|
||||||
|
|
||||||
static void zerr(int ret);
|
static void zerr(int ret, int cmp);
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
slab_alloc_ui(void *p, unsigned int items, unsigned int size) {
|
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;
|
if (*level > 9) *level = 9;
|
||||||
ret = deflateInit(zs, *level);
|
ret = deflateInit(zs, *level);
|
||||||
if (ret != Z_OK) {
|
if (ret != Z_OK) {
|
||||||
zerr(ret);
|
zerr(ret, 0);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ zlib_deinit(void **data)
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void zerr(int ret)
|
void zerr(int ret, int cmp)
|
||||||
{
|
{
|
||||||
switch (ret) {
|
switch (ret) {
|
||||||
case Z_ERRNO:
|
case Z_ERRNO:
|
||||||
|
@ -110,7 +110,9 @@ void zerr(int ret)
|
||||||
fprintf(stderr, "Zlib: Version mismatch!\n");
|
fprintf(stderr, "Zlib: Version mismatch!\n");
|
||||||
break;
|
break;
|
||||||
case Z_BUF_ERROR:
|
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;
|
break;
|
||||||
case Z_NEED_DICT:
|
case Z_NEED_DICT:
|
||||||
fprintf(stderr, "Zlib: Need present dictionary.\n");
|
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);
|
ret = deflate(zs, Z_NO_FLUSH);
|
||||||
if (ret != Z_OK) {
|
if (ret != Z_OK) {
|
||||||
deflateReset(zs);
|
deflateReset(zs);
|
||||||
zerr(ret);
|
zerr(ret, 1);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -162,9 +164,9 @@ zlib_compress(void *src, size_t srclen, void *dst, size_t *dstlen,
|
||||||
if (ret != Z_STREAM_END) {
|
if (ret != Z_STREAM_END) {
|
||||||
deflateReset(zs);
|
deflateReset(zs);
|
||||||
if (ret == Z_OK)
|
if (ret == Z_OK)
|
||||||
zerr(Z_BUF_ERROR);
|
zerr(Z_BUF_ERROR, 1);
|
||||||
else
|
else
|
||||||
zerr(ret);
|
zerr(ret, 1);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -177,7 +179,7 @@ zlib_compress(void *src, size_t srclen, void *dst, size_t *dstlen,
|
||||||
*dstlen = *dstlen - _dstlen;
|
*dstlen = *dstlen - _dstlen;
|
||||||
ret = deflateReset(zs);
|
ret = deflateReset(zs);
|
||||||
if (ret != Z_OK) {
|
if (ret != Z_OK) {
|
||||||
zerr(ret);
|
zerr(ret, 1);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
@ -200,7 +202,7 @@ zlib_decompress(void *src, size_t srclen, void *dst, size_t *dstlen,
|
||||||
zs.opaque = NULL;
|
zs.opaque = NULL;
|
||||||
|
|
||||||
if ((err = inflateInit(&zs)) != Z_OK) {
|
if ((err = inflateInit(&zs)) != Z_OK) {
|
||||||
zerr(err);
|
zerr(err, 0);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,7 +225,7 @@ zlib_decompress(void *src, size_t srclen, void *dst, size_t *dstlen,
|
||||||
|
|
||||||
err = inflate(&zs, Z_NO_FLUSH);
|
err = inflate(&zs, Z_NO_FLUSH);
|
||||||
if (err != Z_OK && err != Z_STREAM_END) {
|
if (err != Z_OK && err != Z_STREAM_END) {
|
||||||
zerr(err);
|
zerr(err, 0);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,7 +236,7 @@ zlib_decompress(void *src, size_t srclen, void *dst, size_t *dstlen,
|
||||||
|
|
||||||
if (err == Z_STREAM_END) {
|
if (err == Z_STREAM_END) {
|
||||||
if (_srclen > 0) {
|
if (_srclen > 0) {
|
||||||
zerr(Z_DATA_ERROR);
|
zerr(Z_DATA_ERROR, 0);
|
||||||
return (-1);
|
return (-1);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue