read: add bounds checks during extent merge to prevent buffer overflow#3004
Open
Naveed8951 wants to merge 2 commits intoAOMediaCodec:mainfrom
Open
read: add bounds checks during extent merge to prevent buffer overflow#3004Naveed8951 wants to merge 2 commits intoAOMediaCodec:mainfrom
Naveed8951 wants to merge 2 commits intoAOMediaCodec:mainfrom
Conversation
Validate write offsets and per-extent copy sizes before memcpy when merging item extents to avoid out-of-bounds writes triggered by malformed or malicious AVIF metadata. Reject invalid extents with AVIF_RESULT_BMFF_PARSE_FAILED.
wantehchang
reviewed
Feb 6, 2026
src/read.c
Outdated
| AVIF_ASSERT_OR_RETURN(front); | ||
| // Validate that the write will not exceed the allocated buffer | ||
| if ((size_t)(front - item->mergedExtents.data) > item->mergedExtents.size || | ||
| bytesToRead > item->mergedExtents.size - (size_t)(front - item->mergedExtents.data)) { |
Collaborator
There was a problem hiding this comment.
At this point we have already validated all the sizes and offsets. These two conditions cannot be true if our code is correct. So this check is an assertion. We can consider adding this assertion because the code is quite complicated, but the error code should be AVIF_RESULT_INTERNAL_ERROR, not AVIF_RESULT_BMFF_PARSE_FAILED.
The expression (size_t)(front - item->mergedExtents.data) occurs three times. I suggest saving the result of this expression in a local variable to simplify the code.
Contributor
Author
|
Updated to return AVIF_RESULT_INTERNAL_ERROR and stored the write offset in a local variable as suggested. |
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.
Validate write offsets and per-extent copy sizes before memcpy when merging item extents to avoid out-of-bounds writes triggered by malformed or malicious AVIF metadata.
Reject invalid extents with AVIF_RESULT_BMFF_PARSE_FAILED.