Commit 55c1cde6838 for php
commit 55c1cde6838d4a685cc4dec6365ab04a18281ed6
Author: Lazizbek Ergashev <lazerg2@gmail.com>
Date: Tue Dec 1 20:47:28 2026 +0500
Fix GH-25960: JPEG 2000 Csiz is accepted without component descriptors (#25985)
diff --git a/NEWS b/NEWS
index 9ac857515fc..f15a60cedeb 100644
--- a/NEWS
+++ b/NEWS
@@ -251,6 +251,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 7544f8556cd..2b137a34cb2 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 00000000000..460f0156b89
--- /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--
+<?php
+$jpc = "\xFF\x4F\xFF\x51"
+ . pack('nn', 47, 0)
+ . pack('NN', 1, 1)
+ . str_repeat("\0", 24)
+ . pack('n', 3);
+var_dump(getimagesizefromstring($jpc));
+var_dump(getimagesizefromstring($jpc . "\x07\x01\x01\x07\x01"));
+$info = getimagesizefromstring($jpc . "\x07\x01\x01\x0B\x01\x01\x07\x01\x01");
+var_dump($info['bits'], $info['channels']);
+?>
+--EXPECT--
+bool(false)
+bool(false)
+int(12)
+int(3)