RETURN_ERROR_IF((U64)(op-ostart) != dctx->fParams.frameContentSize,
corruption_detected, "");
}
- 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, "");
- checkRead = MEM_readLE32(ip);
- RETURN_ERROR_IF(checkRead != checkCalc, checksum_wrong, "");
+ if (dctx->fParams.checksumFlag) { /* Frame content checksum verification */
+ if (!dctx->forceIgnoreChecksum) {
+ U32 const checkCalc = (U32)XXH64_digest(&dctx->xxhState);
+ U32 checkRead;
+ RETURN_ERROR_IF(remainingSrcSize<4, checksum_wrong, "");
+ checkRead = MEM_readLE32(ip);
+ RETURN_ERROR_IF(checkRead != checkCalc, checksum_wrong, "");
+ }
ip += 4;
remainingSrcSize -= 4;
}
RETURN_ERROR_IF(rSize > dctx->fParams.blockSizeMax, corruption_detected, "Decompressed Block Size Exceeds Maximum");
DEBUGLOG(5, "ZSTD_decompressContinue: decoded size from block : %u", (unsigned)rSize);
dctx->decodedSize += rSize;
- if (dctx->fParams.checksumFlag) XXH64_update(&dctx->xxhState, dst, rSize);
+ if (dctx->fParams.checksumFlag && !dctx->forceIgnoreChecksum) XXH64_update(&dctx->xxhState, dst, rSize);
dctx->previousDstEnd = (char*)dst + rSize;
/* Stay on the same stage until we are finished streaming the block. */
return ZSTD_DCtx_setParameter(dctx, ZSTD_d_format, format);
}
-size_t ZSTD_DCtx_setForceIgnoreChecksum(ZSTD_DCtx* dctx, ZSTD_forceIgnoreChecksum_e shouldIgnore)
+size_t ZSTD_DCtx_setForceIgnoreChecksum(ZSTD_DCtx* dctx, ZSTD_forceIgnoreChecksum_e value)
{
- return ZSTD_DCtx_setParameter(dctx, ZSTD_d_forceIgnoreChecksum, shouldIgnore);
+ return ZSTD_DCtx_setParameter(dctx, ZSTD_d_forceIgnoreChecksum, value);
}
ZSTD_bounds ZSTD_dParam_getBounds(ZSTD_dParameter dParam)
/*! ZSTD_DCtx_setForceIgnoreChecksum() :
* Instruct the decoder context to ignore checksums in compressed frame.
* @return : 0, or an error code (which can be tested using ZSTD_isError()). */
-ZSTDLIB_API size_t ZSTD_DCtx_setForceIgnoreChecksum(ZSTD_DCtx* dctx, ZSTD_forceIgnoreChecksum_e format);
+ZSTDLIB_API size_t ZSTD_DCtx_setForceIgnoreChecksum(ZSTD_DCtx* dctx, ZSTD_forceIgnoreChecksum_e value);
/*! ZSTD_decompressStream_simpleArgs() :
* Same as ZSTD_decompressStream(),
if (ZSTD_getErrorCode(r) != ZSTD_error_dstSize_tooSmall) goto _output_error; }
DISPLAYLEVEL(3, "OK \n");
+ DISPLAYLEVEL(3, "test%3i : decompress with corrupted checksum : ", testNb++);
+ { /* create compressed buffer with checksumming enabled */
+ ZSTD_CCtx* const cctx = ZSTD_createCCtx();
+ CHECK_Z( ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 1) );
+ CHECK_VAR(cSize, ZSTD_compress2(cctx,
+ compressedBuffer, compressedBufferSize,
+ CNBuffer, CNBuffSize) );
+ ZSTD_freeCCtx(cctx);
+ }
+ { /* copy the compressed buffer and corrupt the checksum */
+ char* corruptedChecksumCompressedBuffer = (char*)malloc(cSize);
+ if (!corruptedChecksumCompressedBuffer) {
+ DISPLAY("Not enough memory, aborting\n");
+ testResult = 1;
+ goto _end;
+ }
+
+ memcpy(corruptedChecksumCompressedBuffer, compressedBuffer, cSize);
+ corruptedChecksumCompressedBuffer[cSize-1] += 1;
+ size_t r = ZSTD_decompress(decodedBuffer, CNBuffSize, corruptedChecksumCompressedBuffer, cSize);
+ if (!ZSTD_isError(r)) goto _output_error;
+ if (ZSTD_getErrorCode(r) != ZSTD_error_checksum_wrong) goto _output_error;
+
+ ZSTD_DCtx* dctx = ZSTD_createDCtx(); assert(dctx != NULL);
+ CHECK_Z(ZSTD_DCtx_setForceIgnoreChecksum(dctx, ZSTD_d_ignoreChecksum));
+ r = ZSTD_decompressDCtx(dctx, decodedBuffer, CNBuffSize, corruptedChecksumCompressedBuffer, cSize);
+ if (ZSTD_isError(r)) goto _output_error;
+
+ ZSTD_freeDCtx(dctx);
+ free(corruptedChecksumCompressedBuffer);
+ }
+ DISPLAYLEVEL(3, "OK \n");
+
+
DISPLAYLEVEL(3, "test%3i : ZSTD_decompressBound test with content size missing : ", testNb++);
{ /* create compressed buffer with content size missing */
ZSTD_CCtx* const cctx = ZSTD_createCCtx();