Prevent heap buffer overflow from Y4M dimension overflow #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a verified memory-corruption vulnerability in the Y4M input parser caused by unsafe signed integer arithmetic when computing frame buffer sizes from attacker-controlled header dimensions. The fix enforces strict dimension validation and converts all size computations to checked
size_tarithmetic to prevent heap buffer overflows.Severity
S0 – heap buffer overflow reachable via crafted input.
Affected Components
y4m_input_open()y4m_parse_tags()y4m_input_fetch_frame()Vulnerability Description
Y4M header tags, notably
W(width) andH(height), are attacker-controlled. Previously, these values were parsed into signedintfields and used inintarithmetic when computing frame buffer sizes such asdst_buf_read_sz, particularly for high-bit-depth formats (e.g.C420p10,C420p12).For sufficiently large dimensions, signed integer multiplication could overflow, producing undefined behavior and negative intermediates. When later converted to
size_t, these values became very large positive sizes. The frame read path would then attempt to read that many bytes into a heap buffer allocated using a different, non-overflowed size computation, resulting in a heap buffer overflow.Fix Description
WandHtags and rejects invalid, zero, negative, or overflow-prone values.size_tarithmetic.dst_buf_read_sznever exceeds the allocated destination buffer size.aux_buf_read_sznever exceedsaux_buf_sz.vpx_malloc/vpx_freefor consistent bounded allocation behavior.y4m_input_fetch_frame()by validating size calculations and casts.Before vs After
Before:
Large or malformed
W/Hvalues could trigger signed integer overflow, leading to incorrect read sizes and heap buffer overflows during frame reads.After:
Invalid or overflow-inducing dimensions are rejected early, and all derived sizes are computed using checked arithmetic and validated against allocations, preventing memory corruption.
Testing
vpxencagainst valid Y4M inputs across supported chroma types and bit depths, and fuzzing Y4M headers focused onW,H, and chroma tag combinations.