diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index 82c24f32..73ed7e1a 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -114,6 +114,7 @@ static void ZSTD_initDCtx_internal(ZSTD_DCtx* dctx) dctx->oversizedDuration = 0; dctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid()); dctx->outBufferMode = ZSTD_obm_buffered; + dctx->forceIgnoreChecksum = ZSTD_d_validateChecksum; #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION dctx->dictContentEndForFuzzing = NULL; #endif @@ -661,7 +662,7 @@ static size_t ZSTD_decompressFrame(ZSTD_DCtx* dctx, } if (ZSTD_isError(decodedSize)) return decodedSize; - if (dctx->fParams.checksumFlag) + if (dctx->fParams.checksumFlag && !dctx->forceIgnoreChecksum) XXH64_update(&dctx->xxhState, op, decodedSize); if (decodedSize != 0) op += decodedSize; @@ -675,7 +676,7 @@ static size_t ZSTD_decompressFrame(ZSTD_DCtx* dctx, RETURN_ERROR_IF((U64)(op-ostart) != dctx->fParams.frameContentSize, corruption_detected, ""); } - if (dctx->fParams.checksumFlag) { /* Frame content checksum verification */ + if (dctx->fParams.checksumFlag && !dctx->forceIgnoreChecksum) { /* Frame content checksum verification */ U32 const checkCalc = (U32)XXH64_digest(&dctx->xxhState); U32 checkRead; RETURN_ERROR_IF(remainingSrcSize<4, checksum_wrong, ""); @@ -1399,7 +1400,7 @@ size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format) size_t ZSTD_DCtx_setForceSkipChecksum(ZSTD_DCtx* dctx, ZSTD_format_e format) { - return ZSTD_DCtx_setParameter(dctx, ZSTD_d_forceSkipChecksum, format); + return ZSTD_DCtx_setParameter(dctx, ZSTD_d_forceIgnoreChecksum, format); } ZSTD_bounds ZSTD_dParam_getBounds(ZSTD_dParameter dParam) @@ -1463,7 +1464,7 @@ size_t ZSTD_DCtx_setParameter(ZSTD_DCtx* dctx, ZSTD_dParameter dParam, int value return 0; case ZSTD_d_forceIgnoreChecksum: CHECK_DBOUNDS(ZSTD_d_forceIgnoreChecksum, value); - dctx->forceIgnoreChecksum = (ZSTD_ignoreChecksumMode_e)value; + dctx->forceIgnoreChecksum = (ZSTD_forceIgnoreChecksum_e)value; default:; } RETURN_ERROR(parameter_unsupported, ""); diff --git a/lib/decompress/zstd_decompress_internal.h b/lib/decompress/zstd_decompress_internal.h index 0481ce64..6f1dda20 100644 --- a/lib/decompress/zstd_decompress_internal.h +++ b/lib/decompress/zstd_decompress_internal.h @@ -103,7 +103,7 @@ typedef enum { typedef enum { ZSTD_d_validateChecksum = 0, ZSTD_d_ignoreChecksum = 1 -} ZSTD_ignoreChecksumMode_e; +} ZSTD_forceIgnoreChecksum_e; struct ZSTD_DCtx_s { @@ -127,7 +127,7 @@ struct ZSTD_DCtx_s XXH64_state_t xxhState; size_t headerSize; ZSTD_format_e format; - ZSTD_ignoreChecksumMode_e forceIgnoreChecksum; /* if enabled, will ignore checksums in compressed frame */ + ZSTD_forceIgnoreChecksum_e forceIgnoreChecksum; /* if == 1, will ignore checksums in compressed frame */ const BYTE* litPtr; ZSTD_customMem customMem; size_t litSize; diff --git a/tests/fuzzer.c b/tests/fuzzer.c index 8ac2864f..cb68ca5d 100644 --- a/tests/fuzzer.c +++ b/tests/fuzzer.c @@ -2354,6 +2354,9 @@ static int basicUnitTests(U32 const seed, double compressibility) { size_t const sr = ZSTD_DCtx_setParameter(dctx, ZSTD_d_format, (ZSTD_format_e)888); if (!ZSTD_isError(sr)) goto _output_error; } + { size_t const sr = ZSTD_DCtx_setParameter(dctx, ZSTD_d_forceIgnoreChecksum, (ZSTD_forceIgnoreChecksum_e)888); + if (!ZSTD_isError(sr)) goto _output_error; + } DISPLAYLEVEL(3, "OK \n"); ZSTD_freeDCtx(dctx);