Security: zstd decompression may allocate ZSTD_CONTENTSIZE_UNKNOWN bytes #159
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
data_decompress()insrc/shared/compression.c:46-103usesZSTD_getFrameContentSize()to determine the decompression buffer size. This function can returnZSTD_CONTENTSIZE_UNKNOWN(0xFFFFFFFFFFFFFFFF) for frames that do not store the original size. The code only checksZSTD_isError()and then immediately casts the result tosize_tformalloc():If
dst_sizeisZSTD_CONTENTSIZE_UNKNOWN, the condition is true (dst_size > 0and not an error), causing an allocation ofSIZE_MAXbytes and an immediate OOM.Reproduction scenario
Craft a valid zstd frame with the content-size flag unset and send it to the server. The decompressor will attempt to allocate a buffer of
SIZE_MAX.Suggested fix
ZSTD_CONTENTSIZE_UNKNOWNandZSTD_CONTENTSIZE_ERRORand fall back to streaming growth with a small initial buffer.Severity
High
Category
security
This issue was automatically generated by the issue-creator agent.