Skip to content

Comments

fix: prevent uint32_t overflow in avifSetTileConfiguration tile area#3052

Open
uwezkhan wants to merge 2 commits intoAOMediaCodec:mainfrom
uwezkhan:fix/integer-overflow-tile-area-calculation
Open

fix: prevent uint32_t overflow in avifSetTileConfiguration tile area#3052
uwezkhan wants to merge 2 commits intoAOMediaCodec:mainfrom
uwezkhan:fix/integer-overflow-tile-area-calculation

Conversation

@uwezkhan
Copy link

fix: prevent uint32_t overflow in avifSetTileConfiguration tile area

When computing the tile count, width * height was performed as a
uint32_t multiplication. For images with dimensions whose product
exceeds UINT32_MAX (e.g. 100000x50000), this silently wraps around,
producing an incorrect tile count and potentially corrupt tile layout.

Fix by widening to uint64_t before multiplying, and clamping to
kMaxTiles using AVIF_MIN before downcasting back to uint32_t.
The existing bounds checks are preserved as a safety net.

Fixes: integer overflow in avifSetTileConfiguration (src/write.c)

@uwezkhan
Copy link
Author

Thanks for the clarification. I’ve updated the implementation to use uint64_t for imageArea, safely cast the result back to uint32_t, and verified that the caller enforces width and height ≤ 65536.

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