Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fuzz] Superblock fuzz issues #1891

Merged
merged 15 commits into from
Dec 10, 2019
Merged
19 changes: 14 additions & 5 deletions lib/compress/zstd_compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -2480,8 +2480,11 @@ static size_t ZSTD_compressBlock_targetCBlockSize(ZSTD_CCtx* zc,
* enough for SuperBlock compression.
* In such case, fall back to normal compression. This is possible because
* targetCBlockSize is best effort not a guarantee. */
if (cSize != ERROR(dstSize_tooSmall)) return cSize;
else {
if (cSize == ERROR(dstSize_tooSmall) || (dstCapacity - cSize) < 4) {
/* We check (dstCapacity - cSize) < 4 above because we have to make sure
* to leave enough room for the checksum that will eventually get added in
* the epilogue. Otherwise, we're just going to throw the dstSize_tooSmall
* error there instead of here */
BYTE* const ostart = (BYTE*)dst;
/* If ZSTD_noCompressSuperBlock fails with dstSize_tooSmall,
* compress normally.
Expand All @@ -2493,12 +2496,18 @@ static size_t ZSTD_compressBlock_targetCBlockSize(ZSTD_CCtx* zc,
srcSize,
zc->entropyWorkspace, HUF_WORKSPACE_SIZE /* statically allocated in resetCCtx */,
zc->bmi2);
if (!ZSTD_isError(cSize) && cSize != 0) {

bimbashrestha marked this conversation as resolved.
Show resolved Hide resolved
if (cSize == 0) {
/* If compressSequences didn't work, we just output a regular
* uncompressed block */
cSize = ZSTD_noCompressBlock(dst, dstCapacity, src, srcSize, lastBlock);
FORWARD_IF_ERROR(cSize);
} else {
U32 const cBlockHeader24 = lastBlock + (((U32)bt_compressed)<<1) + (U32)(cSize << 3);
MEM_writeLE24(ostart, cBlockHeader24);
cSize += ZSTD_blockHeaderSize;
bimbashrestha marked this conversation as resolved.
Show resolved Hide resolved
}
}
} else return cSize;
bimbashrestha marked this conversation as resolved.
Show resolved Hide resolved
}

if (!ZSTD_isError(cSize) && cSize != 0) {
bimbashrestha marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -2853,7 +2862,7 @@ static size_t ZSTD_checkDictNCount(short* normalizedCounter, unsigned dictMaxSym

size_t ZSTD_loadCEntropy(ZSTD_compressedBlockState_t* bs, void* workspace,
short* offcodeNCount, unsigned* offcodeMaxValue,
const void* const dict, size_t dictSize)
const void* const dict, size_t dictSize)
{
const BYTE* dictPtr = (const BYTE*)dict; /* skip magic num and dict ID */
const BYTE* const dictEnd = dictPtr + dictSize;
Expand Down