From: senhuang42 Date: Sat, 22 Aug 2020 20:05:40 +0000 (-0400) Subject: Added CLI tests for --no-check, fixed ignore checksum logic X-Git-Tag: v1.4.7~94^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3f5f9658a46efd6619e50cae857fa3903c32059;p=thirdparty%2Fzstd.git Added CLI tests for --no-check, fixed ignore checksum logic --- diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index 21e724d7e..6999966a3 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -447,7 +447,7 @@ static size_t ZSTD_decodeFrameHeader(ZSTD_DCtx* dctx, const void* src, size_t he RETURN_ERROR_IF(dctx->fParams.dictID && (dctx->dictID != dctx->fParams.dictID), dictionary_wrong, ""); #endif - if (dctx->fParams.checksumFlag) XXH64_reset(&dctx->xxhState, 0); + if (dctx->fParams.checksumFlag && !dctx->forceIgnoreChecksum) XXH64_reset(&dctx->xxhState, 0); return 0; } @@ -1010,10 +1010,13 @@ size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, c case ZSTDds_checkChecksum: assert(srcSize == 4); /* guaranteed by dctx->expected */ - { U32 const h32 = (U32)XXH64_digest(&dctx->xxhState); - U32 const check32 = MEM_readLE32(src); - DEBUGLOG(4, "ZSTD_decompressContinue: checksum : calculated %08X :: %08X read", (unsigned)h32, (unsigned)check32); - RETURN_ERROR_IF(check32 != h32, checksum_wrong, ""); + { + if (!dctx->forceIgnoreChecksum) { + U32 const h32 = (U32)XXH64_digest(&dctx->xxhState); + U32 const check32 = MEM_readLE32(src); + DEBUGLOG(4, "ZSTD_decompressContinue: checksum : calculated %08X :: %08X read", (unsigned)h32, (unsigned)check32); + RETURN_ERROR_IF(check32 != h32, checksum_wrong, ""); + } dctx->expected = 0; dctx->stage = ZSTDds_getFrameHeaderSize; return 0; diff --git a/programs/fileio.c b/programs/fileio.c index 5349bc6b1..38f59a737 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -1755,7 +1755,7 @@ static dRess_t FIO_createDResources(FIO_prefs_t* const prefs, const char* dictFi EXM_THROW(60, "Error: %s : can't create ZSTD_DStream", strerror(errno)); CHECK( ZSTD_DCtx_setMaxWindowSize(ress.dctx, prefs->memLimit) ); if (!prefs->checksumFlag) - CHECK( ZSTD_DCtx_setForceIgnoreChecksum(ress.dctx, 1 /* ZSTD_d_ignoreChecksum */)); + CHECK( ZSTD_DCtx_setForceIgnoreChecksum(ress.dctx, ZSTD_d_ignoreChecksum)); ress.srcBufferSize = ZSTD_DStreamInSize(); ress.srcBuffer = malloc(ress.srcBufferSize); ress.dstBufferSize = ZSTD_DStreamOutSize(); diff --git a/tests/playTests.sh b/tests/playTests.sh index b7bfa76cd..3d099efb2 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -260,6 +260,11 @@ zstd tmp -c --compress-literals --fast=1 | zstd -t zstd tmp -c --compress-literals -19 | zstd -t zstd -b --fast=1 -i0e1 tmp --compress-literals zstd -b --fast=1 -i0e1 tmp --no-compress-literals +println "test: --no-check for decompression" +zstd -f tmp --check +zstd -f tmp -o tmp1.zst --no-check +zstd -d -f tmp.zst --no-check +zstd -d -f tmp1.zst --no-check println "\n===> zstdgrep tests" ln -sf "$ZSTD_BIN" zstdcat