Allow ZSTD_selectBlockCompressor() to Return NULL
Return an error rather than segfaulting.
This commit is contained in:
@@ -3280,7 +3280,9 @@ static size_t ZSTD_buildSeqStore(ZSTD_CCtx* zc, const void* src, size_t srcSize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Fallback to software matchfinder */
|
/* Fallback to software matchfinder */
|
||||||
{ ZSTD_blockCompressor const blockCompressor = ZSTD_selectBlockCompressor(zc->appliedParams.cParams.strategy,
|
{ ZSTD_blockCompressor const blockCompressor =
|
||||||
|
ZSTD_selectBlockCompressor(
|
||||||
|
zc->appliedParams.cParams.strategy,
|
||||||
zc->appliedParams.useRowMatchFinder,
|
zc->appliedParams.useRowMatchFinder,
|
||||||
dictMode);
|
dictMode);
|
||||||
ms->ldmSeqStore = NULL;
|
ms->ldmSeqStore = NULL;
|
||||||
@@ -3289,13 +3291,16 @@ static size_t ZSTD_buildSeqStore(ZSTD_CCtx* zc, const void* src, size_t srcSize)
|
|||||||
"External sequence producer returned error code %lu. Falling back to internal parser.",
|
"External sequence producer returned error code %lu. Falling back to internal parser.",
|
||||||
(unsigned long)nbExternalSeqs
|
(unsigned long)nbExternalSeqs
|
||||||
);
|
);
|
||||||
|
RETURN_ERROR_IF(blockCompressor == NULL, parameter_combination_unsupported, "Got NULL block compressor!");
|
||||||
lastLLSize = blockCompressor(ms, &zc->seqStore, zc->blockState.nextCBlock->rep, src, srcSize);
|
lastLLSize = blockCompressor(ms, &zc->seqStore, zc->blockState.nextCBlock->rep, src, srcSize);
|
||||||
} }
|
} }
|
||||||
} else { /* not long range mode and no external matchfinder */
|
} else { /* not long range mode and no external matchfinder */
|
||||||
ZSTD_blockCompressor const blockCompressor = ZSTD_selectBlockCompressor(zc->appliedParams.cParams.strategy,
|
ZSTD_blockCompressor const blockCompressor = ZSTD_selectBlockCompressor(
|
||||||
|
zc->appliedParams.cParams.strategy,
|
||||||
zc->appliedParams.useRowMatchFinder,
|
zc->appliedParams.useRowMatchFinder,
|
||||||
dictMode);
|
dictMode);
|
||||||
ms->ldmSeqStore = NULL;
|
ms->ldmSeqStore = NULL;
|
||||||
|
RETURN_ERROR_IF(blockCompressor == NULL, parameter_combination_unsupported, "Got NULL block compressor!");
|
||||||
lastLLSize = blockCompressor(ms, &zc->seqStore, zc->blockState.nextCBlock->rep, src, srcSize);
|
lastLLSize = blockCompressor(ms, &zc->seqStore, zc->blockState.nextCBlock->rep, src, srcSize);
|
||||||
}
|
}
|
||||||
{ const BYTE* const lastLiterals = (const BYTE*)src + srcSize - lastLLSize;
|
{ const BYTE* const lastLiterals = (const BYTE*)src + srcSize - lastLLSize;
|
||||||
|
|||||||
@@ -672,6 +672,8 @@ size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
|
|||||||
/* Input positions */
|
/* Input positions */
|
||||||
BYTE const* ip = istart;
|
BYTE const* ip = istart;
|
||||||
|
|
||||||
|
RETURN_ERROR_IF(blockCompressor == NULL, parameter_combination_unsupported, "Got NULL block compressor!");
|
||||||
|
|
||||||
DEBUGLOG(5, "ZSTD_ldm_blockCompress: srcSize=%zu", srcSize);
|
DEBUGLOG(5, "ZSTD_ldm_blockCompress: srcSize=%zu", srcSize);
|
||||||
/* If using opt parser, use LDMs only as candidates rather than always accepting them */
|
/* If using opt parser, use LDMs only as candidates rather than always accepting them */
|
||||||
if (cParams->strategy >= ZSTD_btopt) {
|
if (cParams->strategy >= ZSTD_btopt) {
|
||||||
|
|||||||
Reference in New Issue
Block a user