Skip to content

Fix GH-25961: Reject truncated JPEG SOF headers - #25982

Open
jlu-lujing wants to merge 1 commit into
php:PHP-8.4from
jlu-lujing:gh-25961-truncated-jpeg-sof
Open

jlu-lujing wants to merge 1 commit into
php:PHP-8.4from
jlu-lujing:gh-25961-truncated-jpeg-sof

Conversation

@jlu-lujing

Copy link
Copy Markdown

A truncated JPEG SOF segment currently leaves php_stream_getc() EOF in the unsigned channel field, so getimagesize() and getimagesizefromstring() publish UINT_MAX channels. 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:

  • New PHPT fails before the change and passes after it.
  • ext/standard/tests/image: 33 passed, 8 skipped due to optional extensions omitted from the minimal build, 0 failed.

OpenAI Codex assisted with investigating the JPEG parser, preparing the focused code and regression test, and drafting this description. I reviewed and verified the resulting change locally.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

1 participant