Skip to content

Comments

Fix potential integer overflow in rowBytes multiplications#3053

Open
rootvector2 wants to merge 2 commits intoAOMediaCodec:mainfrom
rootvector2:fix/rowbytes-integer-overflow-audit
Open

Fix potential integer overflow in rowBytes multiplications#3053
rootvector2 wants to merge 2 commits intoAOMediaCodec:mainfrom
rootvector2:fix/rowbytes-integer-overflow-audit

Conversation

@rootvector2
Copy link
Contributor

Cast the first operand to (size_t) before multiplying two uint32_t values involving rowBytes, alphaRowBytes, or yuvRowBytes to prevent unsigned integer wrap-around on large images.

Cast the first operand to (size_t) before multiplying two uint32_t
values involving rowBytes, alphaRowBytes, or yuvRowBytes to prevent
unsigned integer wrap-around on large images.
Copy link
Contributor

@y-guyon y-guyon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

src/reformat.c Outdated
assert(src->format != AVIF_RGB_FORMAT_RGB_565 || src->depth == 8);

const uint8_t * const srcPixel = &src->pixels[y * src->rowBytes + x * info->pixelBytes];
const uint8_t * const srcPixel = &src->pixels[(size_t)y * src->rowBytes + x * info->pixelBytes];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be (size_t)x too I guess

@rootvector2
Copy link
Contributor Author

I've updated the arithmetic to ensure all intermediate multiplications are performed in size_t and added explicit overflow checks before allocation in codec_svt.c.

In reformat.c, both x and y are now promoted to size_t before multiplication to avoid any intermediate 32-bit overflow.

This keeps the calculations fully in the size_t domain and prevents potential wraparound prior to allocation or pointer offset computation.

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