From: Yann Collet Date: Fri, 19 Jan 2018 20:41:56 +0000 (-0800) Subject: zstdmt: fixed corruption issue in ZSTDMT_endStream() X-Git-Tag: v1.3.4~1^2~67^2~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc696234539e5741ced8a1c663c3343ddaf59e10;p=thirdparty%2Fzstd.git zstdmt: fixed corruption issue in ZSTDMT_endStream() when invoked directly. --- diff --git a/lib/compress/zstdmt_compress.c b/lib/compress/zstdmt_compress.c index 68f974d7b..303bc1f71 100644 --- a/lib/compress/zstdmt_compress.c +++ b/lib/compress/zstdmt_compress.c @@ -1249,7 +1249,7 @@ static size_t ZSTDMT_flushStream_internal(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* ou size_t const srcSize = mtctx->inBuff.filled - mtctx->prefixSize; DEBUGLOG(5, "ZSTDMT_flushStream_internal"); - if ( ((srcSize > 0) || (endFrame && !mtctx->frameEnded)) + if ( (mtctx->jobReady || (srcSize > 0) || (endFrame && !mtctx->frameEnded)) && (mtctx->nextJobID <= mtctx->doneJobID + mtctx->jobIDMask) ) { DEBUGLOG(5, "ZSTDMT_flushStream_internal : create a new job"); CHECK_F( ZSTDMT_createCompressionJob(mtctx, srcSize, endFrame) ); diff --git a/tests/zstreamtest.c b/tests/zstreamtest.c index c26cb3295..b21611abc 100644 --- a/tests/zstreamtest.c +++ b/tests/zstreamtest.c @@ -864,10 +864,16 @@ static size_t findDiff(const void* buf1, const void* buf2, size_t max) if (b1[u] != b2[u]) break; } DISPLAY("Error at position %u / %u \n", (U32)u, (U32)max); - DISPLAY(" %02X %02X %02X :%02X: %02X %02X %02X %02X %02X \n", - b1[u-3], b1[u-2], b1[u-1], b1[u-0], b1[u+1], b1[u+2], b1[u+3], b1[u+4], b1[u+5]); - DISPLAY(" %02X %02X %02X :%02X: %02X %02X %02X %02X %02X \n", - b2[u-3], b2[u-2], b2[u-1], b2[u-0], b2[u+1], b2[u+2], b2[u+3], b2[u+4], b2[u+5]); + if (u>=3) + DISPLAY(" %02X %02X %02X ", + b1[u-3], b1[u-2], b1[u-1]); + DISPLAY(" :%02X: %02X %02X %02X %02X %02X \n", + b1[u], b1[u+1], b1[u+2], b1[u+3], b1[u+4], b1[u+5]); + if (u>=3) + DISPLAY(" %02X %02X %02X ", + b2[u-3], b2[u-2], b2[u-1]); + DISPLAY(" :%02X: %02X %02X %02X %02X %02X \n", + b2[u], b2[u+1], b2[u+2], b2[u+3], b2[u+4], b2[u+5]); return u; }