fix: prevent uint32_t overflow in avifSetTileConfiguration tile area#3052
Conversation
…ame, and encoding structures.
|
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. |
|
uwezkhan: You wrote:
Could you tell me where the caller of I can't seem to find that code. I just wrote PR #3061 to do that. |
|
I verified with the following patch that the caller of |
| uint32_t imageArea = width * height; | ||
| uint32_t tiles = (imageArea + kMinTileArea - 1) / kMinTileArea; | ||
| // AV1 requires width <= 65536 and height <= 65536, so their product fits | ||
| // in uint64_t and the resulting tile count fits in uint32_t. |
There was a problem hiding this comment.
I merged PR #3061, so the caller now validates width <= 65536 and height <= 65536.
Note: For the purpose of this function, we could also clamp width and height to 65536 within this function. Then we don't need the caller to validate that.
fix: prevent uint32_t overflow in avifSetTileConfiguration tile area
When computing the tile count,
width * heightwas performed as auint32_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)