Skip to content

Promote pixel offset multiplications to size_t in reformat.c#3073

Closed
uwezkhan wants to merge 1 commit intoAOMediaCodec:mainfrom
uwezkhan:fix/size_t-offset-arithmetic-reformat
Closed

Promote pixel offset multiplications to size_t in reformat.c#3073
uwezkhan wants to merge 1 commit intoAOMediaCodec:mainfrom
uwezkhan:fix/size_t-offset-arithmetic-reformat

Conversation

@uwezkhan
Copy link
Contributor

@uwezkhan uwezkhan commented Mar 1, 2026

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.

@vrabaud
Copy link
Contributor

vrabaud commented Mar 2, 2026

This is a duplicate of #3072 ? Please close if so

@uwezkhan uwezkhan closed this Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants