-
Notifications
You must be signed in to change notification settings - Fork 286
Fix unchecked integer overflow in encoder UV plane allocation #3233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -911,13 +911,19 @@ static avifResult avmCodecEncodeImage(avifCodec * codec, | |
| // monochrome. Manually set UV planes to 0.5. | ||
|
|
||
| // avmImage is always 420 when we're monochrome | ||
| if (image->width == UINT32_MAX || image->height == UINT32_MAX) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we should allow As Yannis suggested, we can cast Another approach is to replace
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just realized that by the time we reach here,
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there the same frame dimension limits in AV2? In general it could be |
||
| return AVIF_RESULT_INVALID_ARGUMENT; | ||
| } | ||
| uint32_t monoUVWidth = (image->width + 1) >> 1; | ||
| uint32_t monoUVHeight = (image->height + 1) >> 1; | ||
|
|
||
| // Allocate the U plane if necessary. | ||
| if (!avmImageAllocated) { | ||
| uint32_t channelSize = avifImageUsesU16(image) ? 2 : 1; | ||
| uint32_t monoUVRowBytes = channelSize * monoUVWidth; | ||
| if (monoUVHeight > SIZE_MAX / monoUVRowBytes) { | ||
| return AVIF_RESULT_INVALID_ARGUMENT; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should also delete this if statement because: |
||
| size_t monoUVSize = (size_t)monoUVHeight * monoUVRowBytes; | ||
|
|
||
| monoUVPlane = avifAlloc(monoUVSize); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -282,8 +282,14 @@ static avifResult svtCodecEncodeImage(avifCodec * codec, | |
|
|
||
| #if SVT_AV1_CHECK_VERSION(1, 8, 0) | ||
| // Simulate 4:2:0 UV planes. SVT-AV1 does not support 4:0:0 samples. | ||
| if (image->width == UINT32_MAX || image->height == UINT32_MAX) { | ||
| goto cleanup; | ||
| } | ||
| const uint32_t uvWidth = (image->width + y_shift) >> y_shift; | ||
| const uint32_t uvRowBytes = uvWidth * bytesPerPixel; | ||
| if (uvHeight > SIZE_MAX / uvRowBytes) { | ||
| goto cleanup; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| const size_t uvSize = (size_t)uvRowBytes * uvHeight; | ||
| if (uvSize > UINT32_MAX / 2) { | ||
| goto cleanup; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert the change to this file. This has been addressed by PR #3210.