Promote pixel offset multiplications to size_t in reformat.c#3073
Closed
uwezkhan wants to merge 1 commit intoAOMediaCodec:mainfrom
Closed
Promote pixel offset multiplications to size_t in reformat.c#3073uwezkhan wants to merge 1 commit intoAOMediaCodec:mainfrom
uwezkhan wants to merge 1 commit intoAOMediaCodec:mainfrom
Conversation
Contributor
|
This is a duplicate of #3072 ? Please close if so |
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.
This patch improves the safety of pixel offset calculations in src/reformat.c by ensuring that all byte offset multiplications are performed using size_t arithmetic.
In several places inside avifImageRGBToYUV and avifImageYUVAnyToRGBAnySlow, expressions such as:
i * rgbPixelBytes
uvI * yuvChannelBytes
i * 2
were evaluated using 32-bit integer arithmetic before being implicitly promoted to size_t for pointer arithmetic. Although current AV1 frame dimension limits prevent these expressions from overflowing in practice, relying on 32-bit intermediate arithmetic introduces unnecessary fragility.
This change explicitly casts loop indices to size_t before multiplication, for example:
(size_t)i * rgbPixelBytes
(size_t)uvI * yuvChannelBytes
This guarantees that offset computations are performed in the correct width type prior to pointer arithmetic. The update does not modify any control flow, logic, or behavior. It simply ensures arithmetic correctness and strengthens robustness in code that processes untrusted image data.
A total of 36 offset calculations were updated. No functional changes are expected.