Skip to content

Commit 0677b26

Browse files
authored
Merge pull request #2980 from terrelln/opt-oss-fuzz-fix
[opt] Fix oss-fuzz bug in optimal parser
2 parents 844c53e + 4d8a213 commit 0677b26

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/compress/zstd_opt.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,16 @@ static U32 ZSTD_rawLiteralsCost(const BYTE* const literals, U32 const litLength,
269269
* cost of literalLength symbol */
270270
static U32 ZSTD_litLengthPrice(U32 const litLength, const optState_t* const optPtr, int optLevel)
271271
{
272-
if (optPtr->priceType == zop_predef) return WEIGHT(litLength, optLevel);
272+
assert(litLength <= ZSTD_BLOCKSIZE_MAX);
273+
if (optPtr->priceType == zop_predef)
274+
return WEIGHT(litLength, optLevel);
275+
/* We can't compute the litLength price for sizes >= ZSTD_BLOCKSIZE_MAX
276+
* because it isn't representable in the zstd format. So instead just
277+
* call it 1 bit more than ZSTD_BLOCKSIZE_MAX - 1. In this case the block
278+
* would be all literals.
279+
*/
280+
if (litLength == ZSTD_BLOCKSIZE_MAX)
281+
return BITCOST_MULTIPLIER + ZSTD_litLengthPrice(ZSTD_BLOCKSIZE_MAX - 1, optPtr, optLevel);
273282

274283
/* dynamic statistics */
275284
{ U32 const llCode = ZSTD_LLcode(litLength);

0 commit comments

Comments
 (0)