Fix out-of-bounds read in motion compensation (plm_video_process_macroblock)#77
Open
hardw00t wants to merge 1 commit into
Open
Fix out-of-bounds read in motion compensation (plm_video_process_macroblock)#77hardw00t wants to merge 1 commit into
hardw00t wants to merge 1 commit into
Conversation
The bounds check only validated the base indices si/di, but the half-pel prediction reads s[si+1], s[si+dw] and s[si+dw+1] and the block loop spans a block_size x block_size region. For si near max_address with an odd (half-pel) motion component the source read can run up to one row (dw) past the frame plane; when the reference plane is the last plane in the shared frames_data allocation this reads out of bounds. Bound the actual deepest source and destination offsets against the plane size instead of only the base indices. Found with libFuzzer + ASan.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
plm_video_process_macroblock()bounds-checks only the base source/destinationindices
si/diagainstmax_address, but the half-pel prediction cases dereferences[si + 1],s[si + dw]ands[si + dw + 1], andPLM_BLOCK_SETiterates a fullblock_size × block_sizeregion. The deepest source byte actually read is:For
sinearmax_addresswith an odd (half-pel) motion component this reaches up to onerow (
dw) past the end of the plane. Since all three frames share a singlePLM_MALLOC(frame_data_size * 3)chunk with no padding, when the reference plane is the lastplane the read runs off the end of the allocation — an out-of-bounds read on crafted input.
Motion vectors from
plm_video_decode_motion_vector()are wrapped to±(fscale<<4)but notclamped to the frame geometry, so a malformed stream can place the prediction source at the edge.
Destination writes (
d[di]) stay in bounds, so this is a read-only overflow — impact is apotential crash (read into an unmapped page) and, since the out-of-bounds bytes are averaged
into decoded pixels, a limited information-leak into the output frame.
Fix
Bound the actual deepest source and destination offsets against the plane size, not just the
base indices:
Testing
plm_create_with_memory→
plm_decode_video).heap-buffer-overflowinplm_video_process_macroblockno longer overflows (the macroblock is treated as corrupt andskipped), and valid MPEG1 streams still decode identically.
-Wall -Wextra.I have a minimal reproducer that I'm happy to share privately if useful — just let me know the
best channel; I kept it out of this public PR.