ext/gd: fix out-of-bounds write reading font header on short reads#22380
Closed
iliaal wants to merge 1 commit into
Closed
ext/gd: fix out-of-bounds write reading font header on short reads#22380iliaal 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.
devnexen
approved these changes
Jun 21, 2026
Member
|
The new test fails in nightly on PPC64. Can you please have a look? https://github.com/php/php-src/actions/runs/27996485653/job/82859805119 |
Contributor
Author
|
Test bug, not a code bug. The header was packed with |
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() indexes the header copy 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) writes hdr_size-b bytes past the emalloc(sizeof(gdFont)) buffer. Byte-index the destination to match the body read a few lines below. #15231 rewrites the same loop to read into a sized buffer and would also resolve this, but it has been idle since March, so this is the minimal targeted fix.