Skip to content

Fix GH-25960: JPEG 2000 Csiz is accepted without component descriptors - #25985

Open
lazerg wants to merge 1 commit into
php:masterfrom
lazerg:fix/gh-25960
Open

lazerg wants to merge 1 commit into
php:masterfrom
lazerg:fix/gh-25960

Conversation

@lazerg

@lazerg lazerg commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

php_handle_jpc() loops over Csiz component descriptors with unchecked php_stream_getc() calls, so a codestream cut off before those bytes still returns an image with Csiz channels. Each 3-byte descriptor is now read in one go and a short read makes getimagesize() return false.

Fixes #25960

@iliaal iliaal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes what getimagesize() returns for a truncated header that has been accepted for years, with no crash or memory issue behind it, so please retarget to master.

. str_repeat("\0", 24)
. pack('n', 3);
var_dump(getimagesizefromstring($jpc));
var_dump(getimagesizefromstring($jpc . "\x07\x01\x01\x07\x01"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a complete header with different bit depths per component, e.g. "\x07\x01\x01\x0B\x01\x01\x07\x01\x01" (expected bits 12, channels 3). That pins the 3-byte stride and the highest-depth selection, which the two rejection cases don't exercise.

@lazerg

lazerg commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Retargeted to master and added the mixed bit depth case in d364d4b.

@iliaal iliaal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash into one commit and add a NEWS entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getimagesize(): JPEG 2000 Csiz is accepted without component descriptors

2 participants