FIX: guard against integer overflow in FT2Image dimensions#31860
Open
arshsmith wants to merge 1 commit into
Open
FIX: guard against integer overflow in FT2Image dimensions#31860arshsmith wants to merge 1 commit into
arshsmith wants to merge 1 commit into
Conversation
FT2Image(width, height) sized its buffer with calloc(width * height, 1), where width and height are unsigned long. The multiplication could overflow (e.g. 2**16 * 2**16 on a 32-bit long, or 2**32 * 2**32 on a 64-bit long), making calloc allocate a buffer far smaller than m_width * m_height while the stored dimensions stayed huge. draw_rect_filled then clamps to those stored dimensions and writes past the end of the under-sized buffer -- a heap buffer overflow. The calloc return value was also never checked for NULL. Reject dimensions whose product overflows unsigned long (raising OverflowError) and raise on allocation failure (MemoryError). Normal dimensions are unaffected. FT2Image is no longer used on any internal rendering path, so this only hardens the public (deprecated) class.
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.
FT2Image(width, height)allocated its buffer withcalloc(width * height, 1), wherewidth/heightareunsigned long.The multiplication can overflow (e.g.
2**16 * 2**16on a 32-bitlong,or
2**32 * 2**32on a 64-bitlong), socallocallocates a buffer farsmaller than
m_width * m_heightwhile the stored dimensions remain huge.draw_rect_filledthen clamps coordinates to those stored dimensions andwrites past the end of the under-sized buffer — a heap buffer overflow.
The
callocreturn value was also never checked forNULL.