Repository navigation
Conversation
vpx_img_flip() computes (d_h - 1) * stride to relocate the plane pointers. d_h is unsigned, so flipping an image with d_h == 0 underflows to UINT_MAX and produces a wild plane pointer ~64 GiB away from the buffer. d_h == 0 is reachable through the public API: vpx_img_wrap() accepted a zero height and vpx_img_set_rect() accepted a zero-area viewport, neither of which can ever be encoded (the encoders require the image size to match the configured size, which is always >= 1). Reject zero widths/heights in img_alloc_helper() (covers both vpx_img_alloc() and vpx_img_wrap()) and zero-area viewports in vpx_img_set_rect().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
vpx_img_flip() computes (d_h - 1) * stride to relocate the
plane pointers. d_h is unsigned, so flipping an image with
d_h == 0 underflows to UINT_MAX and produces a wild plane
pointer ~64 GiB away from the buffer.
d_h == 0 is reachable through the public API: vpx_img_wrap()
accepted a zero height and vpx_img_set_rect() accepted a
zero-area viewport, neither of which can ever be encoded
(the encoders require the image size to match the configured
size, which is always >= 1).
This patch rejects zero widths/heights in img_alloc_helper()
(covers both vpx_img_alloc() and vpx_img_wrap()) and
zero-area viewports in vpx_img_set_rect().
PoC (before the fix): wrapping a zero-height image and calling
vpx_img_flip() displaced the plane pointers by 68719476720
bytes (~64 GiB). After the fix the calls return NULL / fail
gracefully. Reproduced under ASan+UBSan; the change passes
the vpx_image_test suite (12/12).