Repository navigation
Fix GH-25961: Reject truncated JPEG SOF headers - #25982
Open
jlu-lujing wants to merge 1 commit into
Open
jlu-lujing wants to merge 1 commit into
jlu-lujing wants to merge 1 commit into
Conversation
Read the fixed-size SOF fields together and fail when fewer than six bytes are available. This prevents EOF from being stored as the channel count and rejects malformed JPEG headers instead of exposing bogus metadata.
iliaal
reviewed
Dec 1, 2026
| result->channels = php_stream_getc(stream); | ||
| if (!info || length < 8) { /* if we don't want an extanded info -> return */ | ||
| unsigned char sof[6]; | ||
| if (length < 8 || php_read_stream_all_chunks(stream, (char *) sof, sizeof(sof)) != sizeof(sof)) { |
Member
There was a problem hiding this comment.
Folding length < 8 into the failure check is a separate behavior change. The old code returned the size without extended info in that case, and a SOF declaring length 7 with a full payload now returns false instead of the dimensions. Please keep the short read as the only failure and the old if (!info || length < 8) early return.
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.
A truncated JPEG SOF segment currently leaves
php_stream_getc()EOF in the unsigned channel field, sogetimagesize()andgetimagesizefromstring()publishUINT_MAXchannels. Read the fixed six-byte SOF payload together, validate the declared segment length, and return failure when any byte is missing.The regression uses the minimal truncated header from the report. The whole image test directory passes with the change.
Tests:
ext/standard/tests/image: 33 passed, 8 skipped due to optional extensions omitted from the minimal build, 0 failed.