refactored fuzzer tests for sequence compression api
add explicit delimiter mode to libfuzzer test
This commit is contained in:
@@ -27,7 +27,7 @@ const char* ERR_getErrorString(ERR_enum code)
|
||||
case PREFIX(version_unsupported): return "Version not supported";
|
||||
case PREFIX(frameParameter_unsupported): return "Unsupported frame parameter";
|
||||
case PREFIX(frameParameter_windowTooLarge): return "Frame requires too much memory for decoding";
|
||||
case PREFIX(corruption_detected): return "Input corruption detected";
|
||||
case PREFIX(corruption_detected): return "Data corruption detected";
|
||||
case PREFIX(checksum_wrong): return "Restored data doesn't match checksum";
|
||||
case PREFIX(parameter_unsupported): return "Unsupported parameter";
|
||||
case PREFIX(parameter_outOfBound): return "Parameter is out of bound";
|
||||
|
||||
@@ -2598,7 +2598,7 @@ ZSTD_entropyCompressSeqStore_internal(seqStore_t* seqStorePtr,
|
||||
entropyWorkspace = count + (MaxSeq + 1);
|
||||
entropyWkspSize -= (MaxSeq + 1) * sizeof(*count);
|
||||
|
||||
DEBUGLOG(4, "ZSTD_entropyCompressSeqStore_internal (nbSeq=%zu)", nbSeq);
|
||||
DEBUGLOG(5, "ZSTD_entropyCompressSeqStore_internal (nbSeq=%zu)", nbSeq);
|
||||
ZSTD_STATIC_ASSERT(HUF_WORKSPACE_SIZE >= (1<<MAX(MLFSELog,LLFSELog)));
|
||||
assert(entropyWkspSize >= HUF_WORKSPACE_SIZE);
|
||||
|
||||
@@ -2642,11 +2642,10 @@ ZSTD_entropyCompressSeqStore_internal(seqStore_t* seqStorePtr,
|
||||
ZSTD_memcpy(&nextEntropy->fse, &prevEntropy->fse, sizeof(prevEntropy->fse));
|
||||
return (size_t)(op - ostart);
|
||||
}
|
||||
{
|
||||
ZSTD_symbolEncodingTypeStats_t stats;
|
||||
BYTE* seqHead = op++;
|
||||
{ BYTE* seqHead = op++;
|
||||
/* build stats for sequences */
|
||||
stats = ZSTD_buildSequencesStatistics(seqStorePtr, nbSeq,
|
||||
const ZSTD_symbolEncodingTypeStats_t stats =
|
||||
ZSTD_buildSequencesStatistics(seqStorePtr, nbSeq,
|
||||
&prevEntropy->fse, &nextEntropy->fse,
|
||||
op, oend,
|
||||
strategy, count,
|
||||
@@ -5997,16 +5996,17 @@ static ZSTD_sequenceCopier ZSTD_selectSequenceCopier(ZSTD_sequenceFormat_e mode)
|
||||
return sequenceCopier;
|
||||
}
|
||||
|
||||
/* Discover the size of next by searching for the block delimiter.
|
||||
* Note that a block delimiter must exist in this mode,
|
||||
/* Discover the size of next block by searching for the delimiter.
|
||||
* Note that a block delimiter **must** exist in this mode,
|
||||
* otherwise it's an input error.
|
||||
* The value retrieved will be later compared to ensure it remains within bounds */
|
||||
* The block size retrieved will be later compared to ensure it remains within bounds */
|
||||
static size_t
|
||||
blockSize_explicitDelimiter(const ZSTD_Sequence* inSeqs, size_t inSeqsSize, ZSTD_sequencePosition seqPos)
|
||||
{
|
||||
int end = 0;
|
||||
size_t blockSize = 0;
|
||||
size_t spos = seqPos.idx;
|
||||
DEBUGLOG(6, "blockSize_explicitDelimiter : seq %zu / %zu", spos, inSeqsSize);
|
||||
assert(spos <= inSeqsSize);
|
||||
while (spos < inSeqsSize) {
|
||||
end = (inSeqs[spos].offset == 0);
|
||||
@@ -6085,10 +6085,10 @@ ZSTD_compressSequences_internal(ZSTD_CCtx* cctx,
|
||||
cctx->blockSize, remaining,
|
||||
inSeqs, inSeqsSize, seqPos);
|
||||
U32 const lastBlock = (blockSize == remaining);
|
||||
assert(blockSize <= remaining);
|
||||
FORWARD_IF_ERROR(blockSize, "Error while trying to determine block size");
|
||||
assert(blockSize <= remaining);
|
||||
ZSTD_resetSeqStore(&cctx->seqStore);
|
||||
DEBUGLOG(4, "Working on new block. Blocksize: %zu", blockSize);
|
||||
DEBUGLOG(5, "Working on new block. Blocksize: %zu", blockSize);
|
||||
|
||||
additionalByteAdjustment = sequenceCopier(cctx, &seqPos, inSeqs, inSeqsSize, ip, blockSize);
|
||||
FORWARD_IF_ERROR(additionalByteAdjustment, "Bad sequence copy");
|
||||
@@ -6098,7 +6098,7 @@ ZSTD_compressSequences_internal(ZSTD_CCtx* cctx,
|
||||
if (blockSize < MIN_CBLOCK_SIZE+ZSTD_blockHeaderSize+1) {
|
||||
cBlockSize = ZSTD_noCompressBlock(op, dstCapacity, ip, blockSize, lastBlock);
|
||||
FORWARD_IF_ERROR(cBlockSize, "Nocompress block failed");
|
||||
DEBUGLOG(4, "Block too small, writing out nocompress block: cSize: %zu", cBlockSize);
|
||||
DEBUGLOG(5, "Block too small, writing out nocompress block: cSize: %zu", cBlockSize);
|
||||
cSize += cBlockSize;
|
||||
ip += blockSize;
|
||||
op += cBlockSize;
|
||||
@@ -6115,7 +6115,7 @@ ZSTD_compressSequences_internal(ZSTD_CCtx* cctx,
|
||||
cctx->entropyWorkspace, ENTROPY_WORKSPACE_SIZE /* statically allocated in resetCCtx */,
|
||||
cctx->bmi2);
|
||||
FORWARD_IF_ERROR(compressedSeqsSize, "Compressing sequences of block failed");
|
||||
DEBUGLOG(4, "Compressed sequences size: %zu", compressedSeqsSize);
|
||||
DEBUGLOG(5, "Compressed sequences size: %zu", compressedSeqsSize);
|
||||
|
||||
if (!cctx->isFirstBlock &&
|
||||
ZSTD_maybeRLE(&cctx->seqStore) &&
|
||||
@@ -6131,11 +6131,11 @@ ZSTD_compressSequences_internal(ZSTD_CCtx* cctx,
|
||||
/* ZSTD_noCompressBlock writes the block header as well */
|
||||
cBlockSize = ZSTD_noCompressBlock(op, dstCapacity, ip, blockSize, lastBlock);
|
||||
FORWARD_IF_ERROR(cBlockSize, "Nocompress block failed");
|
||||
DEBUGLOG(4, "Writing out nocompress block, size: %zu", cBlockSize);
|
||||
DEBUGLOG(5, "Writing out nocompress block, size: %zu", cBlockSize);
|
||||
} else if (compressedSeqsSize == 1) {
|
||||
cBlockSize = ZSTD_rleCompressBlock(op, dstCapacity, *ip, blockSize, lastBlock);
|
||||
FORWARD_IF_ERROR(cBlockSize, "RLE compress block failed");
|
||||
DEBUGLOG(4, "Writing out RLE block, size: %zu", cBlockSize);
|
||||
DEBUGLOG(5, "Writing out RLE block, size: %zu", cBlockSize);
|
||||
} else {
|
||||
U32 cBlockHeader;
|
||||
/* Error checking and repcodes update */
|
||||
@@ -6147,11 +6147,11 @@ ZSTD_compressSequences_internal(ZSTD_CCtx* cctx,
|
||||
cBlockHeader = lastBlock + (((U32)bt_compressed)<<1) + (U32)(compressedSeqsSize << 3);
|
||||
MEM_writeLE24(op, cBlockHeader);
|
||||
cBlockSize = ZSTD_blockHeaderSize + compressedSeqsSize;
|
||||
DEBUGLOG(4, "Writing out compressed block, size: %zu", cBlockSize);
|
||||
DEBUGLOG(5, "Writing out compressed block, size: %zu", cBlockSize);
|
||||
}
|
||||
|
||||
cSize += cBlockSize;
|
||||
DEBUGLOG(4, "cSize running total: %zu", cSize);
|
||||
DEBUGLOG(5, "cSize running total: %zu", cSize);
|
||||
|
||||
if (lastBlock) {
|
||||
break;
|
||||
@@ -6164,6 +6164,7 @@ ZSTD_compressSequences_internal(ZSTD_CCtx* cctx,
|
||||
}
|
||||
}
|
||||
|
||||
DEBUGLOG(4, "cSize final total: %zu", cSize);
|
||||
return cSize;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user