-
Notifications
You must be signed in to change notification settings - Fork 44
Fix heap buffer overflow in libopenapv encoder #212
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -37,23 +37,31 @@ | |
| #if ENABLE_ENCODER | ||
| /////////////////////////////////////////////////////////////////////////////// | ||
| #define BSW_FLUSH_4BYTE(bs) { \ | ||
|
Collaborator
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. This function is called anywhere. It will be removed. |
||
| *(bs)->cur++ = ((bs)->code >> 24) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 16) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 8) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code) & 0xFF; \ | ||
| if ((bs)->cur + 4 <= (bs)->end) { \ | ||
| *(bs)->cur++ = ((bs)->code >> 24) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 16) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 8) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code) & 0xFF; \ | ||
| } else { \ | ||
| (bs)->cur += 4; \ | ||
| } \ | ||
| (bs)->code = 0; \ | ||
| (bs)->leftbits = 32; \ | ||
| } | ||
|
|
||
| #define BSW_FLUSH_8BYTE(bs) { \ | ||
|
Collaborator
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. This function is called anywhere. It will be removed
Contributor
Author
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. It is called in BSW_WRITE_64BITS and BSW_WRITE_64BITS is called in oapve_vlc_ac_coef and oapve_vlc_ac_coef is called in enc_tile_comp, or am I missing something?
Collaborator
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. Again, one branch in vlc loop code, it makes noticeable speed-down.
Collaborator
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'd like to suggest to merge this PR without BSW_WRITE_XX changes. |
||
| *(bs)->cur++ = ((bs)->code >> 56) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 48) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 40) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 32) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 24) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 16) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 8) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code) & 0xFF; \ | ||
| if ((bs)->cur + 8 <= (bs)->end) { \ | ||
| *(bs)->cur++ = ((bs)->code >> 56) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 48) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 40) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 32) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 24) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 16) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code >> 8) & 0xFF; \ | ||
| *(bs)->cur++ = ((bs)->code) & 0xFF; \ | ||
| } else { \ | ||
| (bs)->cur += 8; \ | ||
| } \ | ||
| (bs)->code = 0; \ | ||
| (bs)->leftbits = 64; \ | ||
| } | ||
|
|
||
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.
this function is for encoding process, so that the tile[i].bs_size has correct number.
If the address is located in outside of available bitstream buffer, enc_tile() returns error.
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.
the check at enc_tile() happens after enc_tile_comp where the buffer overrun can happen.
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.
Also, each individual tile buffer (tile[i].bs_size) may be fit, but when assembling all encoded tiles into common "bs" we need to check if the sum of tiles doesn't exceed the common "bs" size. I.e. those are different checks.
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.
LGTM