Skip to content

Commit 52aa0d9

Browse files
committed
Fix bug #75708: getimagesize with "&$imageinfo" fails on StreamWrappers
Closes GH-12444
1 parent 83a242e commit 52aa0d9

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ PHP NEWS
3535
. Fix segfault and assertion failure with refcounted props and arrays.
3636
(nielsdos)
3737

38+
- Streams:
39+
. Fixed bug #75708 (getimagesize with "&$imageinfo" fails on StreamWrappers).
40+
(Jakub Zelenka)
41+
3842
- XSL:
3943
. Add missing module dependency. (nielsdos)
4044

ext/standard/image.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,20 @@ static int php_skip_variable(php_stream * stream)
425425
}
426426
/* }}} */
427427

428+
static size_t php_read_stream_all_chunks(php_stream *stream, char *buffer, size_t length)
429+
{
430+
size_t read_total = 0;
431+
do {
432+
ssize_t read_now = php_stream_read(stream, buffer, length - read_total);
433+
read_total += read_now;
434+
if (read_now < stream->chunk_size && read_total != length) {
435+
return 0;
436+
}
437+
} while (read_total < length);
438+
439+
return read_total;
440+
}
441+
428442
/* {{{ php_read_APP */
429443
static int php_read_APP(php_stream * stream, unsigned int marker, zval *info)
430444
{
@@ -441,7 +455,7 @@ static int php_read_APP(php_stream * stream, unsigned int marker, zval *info)
441455

442456
buffer = emalloc(length);
443457

444-
if (php_stream_read(stream, buffer, (size_t) length) != length) {
458+
if (php_read_stream_all_chunks(stream, buffer, length) != length) {
445459
efree(buffer);
446460
return 0;
447461
}

ext/standard/tests/image/bug75708.jpg

33.8 KB
Loading
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
--TEST--
2+
Bug #75708 (getimagesize with "&$imageinfo" fails on StreamWrappers)
3+
--FILE--
4+
<?php
5+
6+
class FSStreamWrapper {
7+
function stream_open($file, $mode) {
8+
$this->handle = fopen(str_replace('fs://', __DIR__ . '/', $file), $mode);
9+
return true;
10+
}
11+
function stream_read($count) {
12+
return fread($this->handle, $count);
13+
}
14+
function stream_eof() {
15+
return feof($this->handle);
16+
}
17+
function stream_seek($offset, $whence) {
18+
return fseek($this->handle, $offset, $whence) === 0;
19+
}
20+
function stream_stat() {
21+
return fstat($this->handle);
22+
}
23+
function url_stat($file) {
24+
return stat(str_replace('fs://', '', $file));
25+
}
26+
function stream_tell() {
27+
return ftell($this->handle);
28+
}
29+
function stream_close() {
30+
fclose($this->handle);
31+
}
32+
}
33+
34+
stream_register_wrapper('fs', 'FSStreamWrapper');
35+
36+
var_dump(getimagesize('fs://bug75708.jpg', $info));
37+
38+
?>
39+
--EXPECT--
40+
array(7) {
41+
[0]=>
42+
int(10)
43+
[1]=>
44+
int(10)
45+
[2]=>
46+
int(2)
47+
[3]=>
48+
string(22) "width="10" height="10""
49+
["bits"]=>
50+
int(8)
51+
["channels"]=>
52+
int(3)
53+
["mime"]=>
54+
string(10) "image/jpeg"
55+
}
56+

0 commit comments

Comments
 (0)