ext/gd: fix out-of-bounds write reading font header on short reads#101
Closed
iliaal wants to merge 1 commit into
Closed
ext/gd: fix out-of-bounds write reading font header on short reads#101iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
imageloadfont() read the font header with `(char*)&font[b]`, which scales the byte counter b by sizeof(gdFont) rather than advancing one byte, so a short php_stream_read() (deliverable by a user stream wrapper) makes the loop write hdr_size-b bytes past the emalloc(sizeof(gdFont)) buffer. Index the destination by bytes, matching the body read a few lines below.
Owner
Author
|
Submitted upstream as php#22380. |
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.
imageloadfont() indexed the header read destination as
(char*)&font[b], which scales the byte counter by sizeof(gdFont) instead of advancing one byte, so a short php_stream_read (a user stream wrapper is enough) writes hdr_size-b bytes past the emalloc(sizeof(gdFont)) buffer. The added test drips a valid 1x1 font one byte per read: on stock the load fails and USE_ZEND_ALLOC=0 valgrind reports an invalid write at gd.c:559, with the fix it loads and valgrind is clean.