From: Yann Collet Date: Mon, 11 Apr 2016 14:25:56 +0000 (+0200) Subject: fixed round-trip corruption, reported by Oliver Lange X-Git-Tag: v0.6.0^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=582933fde5858bea7afff17064824f6855db37c7;p=thirdparty%2Fzstd.git fixed round-trip corruption, reported by Oliver Lange --- diff --git a/lib/zstd_compress.c b/lib/zstd_compress.c index 88ef685c9..48874673c 100644 --- a/lib/zstd_compress.c +++ b/lib/zstd_compress.c @@ -818,7 +818,7 @@ size_t ZSTD_compressSequences(ZSTD_CCtx* zc, FSE_encodeSymbol(&blockStream, &stateMatchLength, mlCode); /* 24 */ /* 24 */ if (MEM_32bits()) BIT_flushBits(&blockStream); /* (7)*/ FSE_encodeSymbol(&blockStream, &stateLitLength, llCode); /* 16 */ /* 33 */ - if (MEM_32bits() || (ofBits+mlBits+llBits > 64-7-(LLFSELog+MLFSELog+OffFSELog))) + if (MEM_32bits() || (ofBits+mlBits+llBits >= 64-7-(LLFSELog+MLFSELog+OffFSELog))) BIT_flushBits(&blockStream); /* (7)*/ BIT_addBits(&blockStream, llTable[n], llBits); if (MEM_32bits() && ((llBits+mlBits)>24)) BIT_flushBits(&blockStream); @@ -858,7 +858,7 @@ MEM_STATIC void ZSTD_storeSeq(seqStore_t* seqStorePtr, size_t litLength, const B static const BYTE* g_start = NULL; const U32 pos = (U32)(literals - g_start); if (g_start==NULL) g_start = literals; - if ((pos > 200000000) && (pos < 200900000)) + if ((pos > 5810300) && (pos < 5810500)) printf("Cpos %6u :%5u literals & match %3u bytes at distance %6u \n", pos, (U32)litLength, (U32)matchCode+MINMATCH, (U32)offsetCode); #endif diff --git a/lib/zstd_decompress.c b/lib/zstd_decompress.c index af61ee9d6..5d3f44224 100644 --- a/lib/zstd_decompress.c +++ b/lib/zstd_decompress.c @@ -786,6 +786,16 @@ static size_t ZSTD_decompressSequences( for ( ; (BIT_reloadDStream(&(seqState.DStream)) <= BIT_DStream_completed) && nbSeq ; ) { nbSeq--; ZSTD_decodeSequence(&sequence, &seqState); + +#if 0 /* debug */ + static BYTE* start = NULL; + if (start==NULL) start = op; + size_t pos = (size_t)(op-start); + if ((pos >= 5810037) && (pos < 5810400)) + printf("Dpos %6u :%5u literals & match %3u bytes at distance %6u \n", + pos, (U32)sequence.litLength, (U32)sequence.matchLength, (U32)sequence.offset); +#endif + { size_t const oneSeqSize = ZSTD_execSequence(op, oend, sequence, &litPtr, litLimit_8, base, vBase, dictEnd); if (ZSTD_isError(oneSeqSize)) return oneSeqSize; op += oneSeqSize;