Skip to content

Declare rgbPixelBytes and grayPixelBytes as size_t#3184

Open
wantehchang wants to merge 1 commit intoAOMediaCodec:mainfrom
wantehchang:fix-pr-3072
Open

Declare rgbPixelBytes and grayPixelBytes as size_t#3184
wantehchang wants to merge 1 commit intoAOMediaCodec:mainfrom
wantehchang:fix-pr-3072

Conversation

@wantehchang
Copy link
Copy Markdown
Member

In avifImageRGBToYUV(), declare the local variables rgbPixelBytes and grayPixelBytes as size_t and replace the constant 2 with sizeof(uint16_t) so that multiplications with them are performed in the size_t type and avoid integer overflows.

Based on the changes to avifImageRGBToYUV() in the first two commits in the pull request #3072.

@wantehchang wantehchang requested a review from vrabaud May 1, 2026 00:54
In avifImageRGBToYUV(), declare the local variables rgbPixelBytes and
grayPixelBytes as size_t and replace the constant 2 with
sizeof(uint16_t) so that multiplications with them are performed in the
size_t type and avoid integer overflows.

Based on the changes to avifImageRGBToYUV() in the first two commits in
the pull request AOMediaCodec#3072.

Co-authored-by: uwezkhan06 <uwezkhan055@gmail.com>
Comment thread src/reformat.c
struct YUVBlock yuvBlock[2][2];
float rgbPixel[3];
const uint32_t rgbPixelBytes = state.rgb.pixelBytes;
const size_t rgbPixelBytes = state.rgb.pixelBytes;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Vincent: This PR is no longer necessary now that pull request #3072 has been updated to declare the index variables i, j, uvI, uvJ as size_t. But I think it is still good to declare rgbPixelBytes and grayPixelBytes as size_t because the related *RowBytes variables are declared as size_t.

Comment thread src/reformat.c

if (state.yuv.channelBytes > 1) {
uint16_t * pY = (uint16_t *)&yPlane[(i * 2) + (j * yRowBytes)];
uint16_t * pY = (uint16_t *)&yPlane[(i * sizeof(uint16_t)) + (j * yRowBytes)];
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

However, if you think changing 2 to sizeof(uint16_t) is too verbose, I can revert these changes.

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.

1 participant