From f9215b53fba24648f5647eabd3cbfb40d93e6cde Mon Sep 17 00:00:00 2001 From: Moinak Ghosh Date: Fri, 3 Aug 2012 23:19:38 +0530 Subject: [PATCH] Fix buffer size calculation when decompressing LZ4, Zlib and Bzip2 compressed chunks. Slight SSE optimization in LZ4HC. --- bzip2_compress.c | 2 +- lz4/lz4hc.c | 25 +++++++++++++++++++++++++ lz4_compress.c | 6 ++---- main.c | 2 +- zlib_compress.c | 2 +- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/bzip2_compress.c b/bzip2_compress.c index b5bf39a..fbb8f54 100644 --- a/bzip2_compress.c +++ b/bzip2_compress.c @@ -206,7 +206,7 @@ bzip2_decompress(void *src, size_t srclen, void *dst, size_t *dstlen, } /* normal termination */ - *dstlen = _dstlen; + *dstlen = *dstlen - _dstlen; BZ2_bzDecompressEnd(&bzs); return (0); } diff --git a/lz4/lz4hc.c b/lz4/lz4hc.c index 74499ac..fbb046c 100644 --- a/lz4/lz4hc.c +++ b/lz4/lz4hc.c @@ -102,6 +102,9 @@ //************************************** #include // calloc, free #include // memset, memcpy +#ifdef __USE_SSE_INTRIN__ +#include +#endif #include "lz4hc.h" #define ALLOCATOR(s) calloc(1,s) @@ -358,6 +361,17 @@ inline static int LZ4HC_InsertAndFindBestMatch (LZ4HC_Data_Structure* hc4, const const BYTE* reft = ref+MINMATCH; const BYTE* ipt = ip+MINMATCH; +#ifdef __USE_SSE_INTRIN__ + while (iptlevel == 1) { rv = LZ4_compress(src, dst, _srclen); - } else if (lzdat->level == 2) { rv = LZ4_compress(src, dst, _srclen); if (rv == 0) { @@ -127,15 +126,14 @@ lz4_decompress(void *src, size_t srclen, void *dst, size_t *dstlen, sz1 = ntohl(*((int *)src)); rv = LZ4_uncompress(src + sizeof (int), dst, sz1); - if (rv == 0) { + if (rv != sz1) { return (-1); } memcpy(src, dst, sz1); rv = LZ4_uncompress(src, dst, _dstlen); } - if (rv == 0) { + if (rv != srclen) { return (-1); } - *dstlen = rv; return (0); } diff --git a/main.c b/main.c index 6974740..259ab01 100644 --- a/main.c +++ b/main.c @@ -149,7 +149,7 @@ show_compression_stats(uint64_t chunksize) /* * This routine is called in multiple threads. Calls the decompression handler * as encoded in the file header. For adaptive mode the handler adapt_decompress() - * in turns looks at the chunk header and call the actualy decompression + * in turns looks at the chunk header and calls the actual decompression * routine. */ static void * diff --git a/zlib_compress.c b/zlib_compress.c index 382b612..147edeb 100644 --- a/zlib_compress.c +++ b/zlib_compress.c @@ -225,7 +225,7 @@ zlib_decompress(void *src, size_t srclen, void *dst, size_t *dstlen, } } - *dstlen = _dstlen; + *dstlen = *dstlen - _dstlen; inflateEnd(&zs); return (0); }