Skip to content

Fix bug #75708: getimagesize with "&$imageinfo" fails on StreamWrappers #12444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 15 additions & 1 deletion ext/standard/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ static int php_skip_variable(php_stream * stream)
}
/* }}} */

static size_t php_read_stream_all_chunks(php_stream *stream, char *buffer, size_t length)
{
size_t read_total = 0;
do {
ssize_t read_now = php_stream_read(stream, buffer, length - read_total);
read_total += read_now;
if (read_now < stream->chunk_size && read_total != length) {
return 0;
}
} while (read_total < length);

return read_total;
}

/* {{{ php_read_APP */
static int php_read_APP(php_stream * stream, unsigned int marker, zval *info)
{
Expand All @@ -441,7 +455,7 @@ static int php_read_APP(php_stream * stream, unsigned int marker, zval *info)

buffer = emalloc(length);

if (php_stream_read(stream, buffer, (size_t) length) != length) {
if (php_read_stream_all_chunks(stream, buffer, length) != length) {
efree(buffer);
return 0;
}
Expand Down
Binary file added ext/standard/tests/image/bug75708.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions ext/standard/tests/image/bug75708.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
--TEST--
Bug #75708 (getimagesize with "&$imageinfo" fails on StreamWrappers)
--FILE--
<?php

class FSStreamWrapper {
function stream_open($file, $mode) {
$this->handle = fopen(str_replace('fs://', __DIR__ . '/', $file), $mode);
return true;
}
function stream_read($count) {
return fread($this->handle, $count);
}
function stream_eof() {
return feof($this->handle);
}
function stream_seek($offset, $whence) {
return fseek($this->handle, $offset, $whence) === 0;
}
function stream_stat() {
return fstat($this->handle);
}
function url_stat($file) {
return stat(str_replace('fs://', '', $file));
}
function stream_tell() {
return ftell($this->handle);
}
function stream_close() {
fclose($this->handle);
}
}

stream_register_wrapper('fs', 'FSStreamWrapper');

var_dump(getimagesize('fs://bug75708.jpg', $info));

?>
--EXPECT--
array(7) {
[0]=>
int(10)
[1]=>
int(10)
[2]=>
int(2)
[3]=>
string(22) "width="10" height="10""
["bits"]=>
int(8)
["channels"]=>
int(3)
["mime"]=>
string(10) "image/jpeg"
}