Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions ext/standard/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions ext/standard/tests/image/gh25960.phpt
Original file line number Diff line number Diff line change
@@ -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)
Loading