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 @@ -312,6 +312,8 @@ PHP NEWS
Lazizbek Ergashev)
. Fixed getimagesize() reporting wrapped dimensions for XBM images with
out-of-range width or height. (Ilia Alshanetsky)
. Fixed GH-25961 (getimagesize() exposing EOF as the channel count for a
truncated JPEG SOF). (Lu Jing)
. Fixed bug GH-25281 (Use-after-free when proc_open() pipe is closed from
its user filter). (Jakub Zelenka)

Expand Down
15 changes: 10 additions & 5 deletions ext/standard/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,16 @@ static struct gfxinfo *php_handle_jpeg (php_stream * stream, zval *info)
/* handle SOFn block */
result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
length = php_read2(stream);
result->bits = php_stream_getc(stream);
result->height = php_read2(stream);
result->width = php_read2(stream);
result->channels = php_stream_getc(stream);
if (!info || length < 8) { /* if we don't want an extanded info -> return */
unsigned char sof[6];
if (length < 8 || php_read_stream_all_chunks(stream, (char *) sof, sizeof(sof)) != sizeof(sof)) {

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.

Folding length < 8 into the failure check is a separate behavior change. The old code returned the size without extended info in that case, and a SOF declaring length 7 with a full payload now returns false instead of the dimensions. Please keep the short read as the only failure and the old if (!info || length < 8) early return.

efree(result);
return NULL;
}
result->bits = sof[0];
result->height = ((unsigned short) sof[1] << 8) | sof[2];
result->width = ((unsigned short) sof[3] << 8) | sof[4];
result->channels = sof[5];
if (!info) { /* if we don't want extended info -> return */
return result;
}
if (php_stream_seek(stream, length - 8, SEEK_CUR)) { /* file error after info */
Expand Down
10 changes: 10 additions & 0 deletions ext/standard/tests/image/gh25961.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
GH-25961: getimagesize() rejects a JPEG SOF with a missing component count
--FILE--
<?php
$jpeg = "\xFF\xD8\xFF\xC0" . pack('n', 8) . "\x08"
. pack('nn', 1, 1);
var_dump(getimagesizefromstring($jpeg));
?>
--EXPECT--
bool(false)
Loading