From 40603ffb240507c93ceeeb79106f6364a9691798 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 23 Oct 2015 12:23:09 +0100 Subject: [PATCH 1/5] =?UTF-8?q?fixed=20issue=20#49,=20reported=20by=20Hann?= =?UTF-8?q?o=20B=C3=B6ck=20(@hannob)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/huff0.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/huff0.c b/lib/huff0.c index 2200e5017..74c7a7be0 100644 --- a/lib/huff0.c +++ b/lib/huff0.c @@ -602,6 +602,7 @@ static size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats, /* get last non-null symbol weight (implied, total must be 2^n) */ tableLog = BIT_highbit32(weightTotal) + 1; + if (tableLog > HUF_ABSOLUTEMAX_TABLELOG) return ERROR(corruption_detected); { U32 total = 1 << tableLog; U32 rest = total - weightTotal; From 3e8fbabfa8b16fa605038c68c8fac7fe29f4c78a Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 23 Oct 2015 14:30:30 +0100 Subject: [PATCH 2/5] =?UTF-8?q?fixed=20issue=20#50,=20reported=20by=20Hann?= =?UTF-8?q?o=20B=C3=B6ck=20(@hannob)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/zstd.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/zstd.c b/lib/zstd.c index 37c67144b..b70e96843 100644 --- a/lib/zstd.c +++ b/lib/zstd.c @@ -1031,7 +1031,7 @@ struct ZSTD_DCtx_s const BYTE* litPtr; size_t litBufSize; size_t litSize; - BYTE litBuffer[BLOCKSIZE]; + BYTE litBuffer[BLOCKSIZE + 8 /* margin for wildcopy */]; }; /* typedef'd to ZSTD_Dctx within "zstd_static.h" */ @@ -1098,17 +1098,25 @@ size_t ZSTD_decodeLiteralsBlock(void* ctx, default: case 0: { - size_t nbLiterals = BLOCKSIZE; - const size_t readSize = ZSTD_decompressLiterals(dctx->litBuffer, &nbLiterals, src, srcSize); + size_t litSize = BLOCKSIZE; + const size_t readSize = ZSTD_decompressLiterals(dctx->litBuffer, &litSize, src, srcSize); dctx->litPtr = dctx->litBuffer; dctx->litBufSize = BLOCKSIZE; - dctx->litSize = nbLiterals; + dctx->litSize = litSize; return readSize; /* works if it's an error too */ } case IS_RAW: { const size_t litSize = (MEM_readLE32(istart) & 0xFFFFFF) >> 2; /* no buffer issue : srcSize >= MIN_CBLOCK_SIZE */ - if (litSize > srcSize-3) return ERROR(corruption_detected); + if (litSize > srcSize-11) /* risk of reading too far with wildcopy */ + { + if (litSize > srcSize-3) return ERROR(corruption_detected); + memcpy(dctx->litBuffer, istart, litSize); + dctx->litBufSize = BLOCKSIZE; + dctx->litSize = litSize; + return litSize+3; + } + /* direct reference into compressed stream */ dctx->litPtr = istart+3; dctx->litBufSize = srcSize-3; dctx->litSize = litSize; @@ -1328,10 +1336,10 @@ static size_t ZSTD_execSequence(BYTE* op, BYTE* const oend_8 = oend-8; const BYTE* const litEnd = *litPtr + sequence.litLength; - /* check */ + /* checks */ if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall); /* last match must start at a minimum distance of 8 from oend */ if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */ - if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */ + if (litEnd > litLimit-8) return ERROR(corruption_detected); /* overRead beyond lit buffer */ /* copy Literals */ ZSTD_wildcopy(op, *litPtr, sequence.litLength); /* note : oLitEnd <= oend-8 : no risk of overwrite beyond oend */ From 64e491e688289a755518ef2b7613910809d9fb83 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 28 Oct 2015 01:35:05 +0100 Subject: [PATCH 3/5] Fixed issue #52 (faulty binary generation with Visual Studio 2013 & 2015 in release mode (compiler bug)), reported and fixed by Christophe Chevalier (@KrzysFR) --- lib/huff0.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/huff0.c b/lib/huff0.c index 74c7a7be0..72b12bdfb 100644 --- a/lib/huff0.c +++ b/lib/huff0.c @@ -1017,24 +1017,29 @@ size_t HUF_readDTableX4 (U32* DTable, const void* src, size_t srcSize) rankStart[0] = 0; /* forget 0w symbols; this is beginning of weight(1) */ } - /* Build rankVal */ + /* Build rankVal */ { const U32 minBits = tableLog+1 - maxW; U32 nextRankVal = 0; U32 w, consumed; const int rescale = (memLog-tableLog) - 1; /* tableLog <= memLog */ + U32* rankVal0 = rankVal[0]; for (w=1; w<=maxW; w++) { U32 current = nextRankVal; nextRankVal += rankStats[w] << (w+rescale); - rankVal[0][w] = current; + rankVal0[w] = current; + } + for (consumed = minBits; consumed <= memLog - minBits; consumed++) + { + U32* rankValPtr = rankVal[consumed]; + for (w = 1; w <= maxW; w++) + { + rankValPtr[w] = rankVal0[w] >> consumed; + } } - for (consumed=minBits; consumed <= memLog-minBits; consumed++) - for (w=1; w<=maxW; w++) - rankVal[consumed][w] = rankVal[0][w] >> consumed; } - HUF_fillDTableX4(dt, memLog, sortedSymbol, sizeOfSort, rankStart0, rankVal, maxW, @@ -1384,21 +1389,27 @@ size_t HUF_readDTableX6 (U32* DTable, const void* src, size_t srcSize) rankStart[0] = 0; /* forget 0w symbols; this is beginning of weight(1) */ } - /* Build rankVal */ + /* Build rankVal */ { const U32 minBits = tableLog+1 - maxW; U32 nextRankVal = 0; U32 w, consumed; const int rescale = (memLog-tableLog) - 1; /* tableLog <= memLog */ + U32* rankVal0 = rankVal[0]; for (w=1; w<=maxW; w++) { U32 current = nextRankVal; nextRankVal += rankStats[w] << (w+rescale); - rankVal[0][w] = current; + rankVal0[w] = current; + } + for (consumed = minBits; consumed <= memLog - minBits; consumed++) + { + U32* rankValPtr = rankVal[consumed]; + for (w = 1; w <= maxW; w++) + { + rankValPtr[w] = rankVal0[w] >> consumed; + } } - for (consumed=minBits; consumed <= memLog-minBits; consumed++) - for (w=1; w<=maxW; w++) - rankVal[consumed][w] = rankVal[0][w] >> consumed; } From 08cbf3dbbf6575f5340fca4ba2b040f2d0f198c8 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Wed, 28 Oct 2015 01:41:46 +0100 Subject: [PATCH 4/5] Updated NEWS --- Makefile | 2 +- NEWS | 6 ++++++ lib/Makefile | 2 +- lib/zstd.h | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index a5e6cf8b0..5cc83da78 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ # ################################################################ # Version number -export VERSION := 0.2.0 +export VERSION := 0.2.2 PRGDIR = programs ZSTDDIR = lib diff --git a/NEWS b/NEWS index b09b624f5..8388dfceb 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +v0.2.2 +Fix : Visual Studio 2013 & 2015 release compilation, by Christophe Chevalier + +v0.2.2 +Fix : Read errors, advanced fuzzer tests, by Hanno Böck + v0.2.0 **Breaking format change** Faster decompression speed diff --git a/lib/Makefile b/lib/Makefile index e5afb9742..75d44c4a5 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -32,11 +32,11 @@ # ################################################################ # Version numbers -VERSION?= 0.1.2 LIBVER_MAJOR=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < zstd.h` LIBVER_MINOR=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < zstd.h` LIBVER_PATCH=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < zstd.h` LIBVER = $(LIBVER_MAJOR).$(LIBVER_MINOR).$(LIBVER_PATCH) +VERSION?= $(LIBVER) DESTDIR?= PREFIX ?= /usr/local diff --git a/lib/zstd.h b/lib/zstd.h index 3978776ce..cba2cae26 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -47,7 +47,7 @@ extern "C" { ***************************************/ #define ZSTD_VERSION_MAJOR 0 /* for breaking interface changes */ #define ZSTD_VERSION_MINOR 2 /* for new (non-breaking) interface capabilities */ -#define ZSTD_VERSION_RELEASE 0 /* for tweaks, bug-fixes, or development */ +#define ZSTD_VERSION_RELEASE 2 /* for tweaks, bug-fixes, or development */ #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE) unsigned ZSTD_versionNumber (void); From 601ba27b396a2a0c438d4d9bf2144a39cfd5d8f8 Mon Sep 17 00:00:00 2001 From: Tobias Ibounig Date: Wed, 28 Oct 2015 14:40:28 +0100 Subject: [PATCH 5/5] Fix typo in NEWS Fix version typo in NEWS --- NEWS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 8388dfceb..4c4c30019 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,7 @@ v0.2.2 Fix : Visual Studio 2013 & 2015 release compilation, by Christophe Chevalier -v0.2.2 +v0.2.1 Fix : Read errors, advanced fuzzer tests, by Hanno Böck v0.2.0