From 4a2b0eb2de1c0e03dac1cff1594c548a8f470508 Mon Sep 17 00:00:00 2001 From: lazerg Date: Tue, 1 Dec 2026 18:28:08 +0500 Subject: [PATCH] Fix GH-25960: JPEG 2000 Csiz is accepted without component descriptors --- NEWS | 2 ++ ext/standard/image.c | 13 ++++++++----- ext/standard/tests/image/gh25960.phpt | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 ext/standard/tests/image/gh25960.phpt diff --git a/NEWS b/NEWS index 36ab60a871e0..fa2e18983a29 100644 --- a/NEWS +++ b/NEWS @@ -249,6 +249,8 @@ PHP NEWS searching for a string. (Alexander Danilov) . Improved performance of str_replace() when the search string is longer than one byte and the replacement has a different length. (Weilin Du) + . Fixed bug GH-25960 (getimagesize() accepts a JPEG 2000 header with missing + component descriptors). (kid-lxy) - URI: . Fix casing of enum cases in UriHostType and UrlHostType to match the RFC diff --git a/ext/standard/image.c b/ext/standard/image.c index 7544f8556cd2..2b137a34cb2d 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -585,6 +585,7 @@ static struct php_gfxinfo *php_handle_jpc(php_stream * stream) struct php_gfxinfo *result = NULL; int highest_bit_depth, bit_depth; unsigned char first_marker_id; + unsigned char component[3]; unsigned int i; /* JPEG 2000 components can be vastly different from one another. @@ -633,14 +634,16 @@ static struct php_gfxinfo *php_handle_jpc(php_stream * stream) /* Collect bit depth info */ highest_bit_depth = 0; for (i = 0; i < result->channels; i++) { - bit_depth = php_stream_getc(stream); /* Ssiz[i] */ - bit_depth++; + /* Ssiz[i], XRsiz[i], YRsiz[i] */ + if (php_stream_read(stream, (char *) component, sizeof(component)) != sizeof(component)) { + efree(result); + return NULL; + } + + bit_depth = component[0] + 1; if (bit_depth > highest_bit_depth) { highest_bit_depth = bit_depth; } - - php_stream_getc(stream); /* XRsiz[i] */ - php_stream_getc(stream); /* YRsiz[i] */ } result->bits = highest_bit_depth; diff --git a/ext/standard/tests/image/gh25960.phpt b/ext/standard/tests/image/gh25960.phpt new file mode 100644 index 000000000000..460f0156b894 --- /dev/null +++ b/ext/standard/tests/image/gh25960.phpt @@ -0,0 +1,21 @@ +--TEST-- +GH-25960 (getimagesize(): JPEG 2000 Csiz is accepted without component descriptors) +--CREDITS-- +kid-lxy +--FILE-- + +--EXPECT-- +bool(false) +bool(false) +int(12) +int(3)