Skip to content

Commit 4fde88b

Browse files
committed
Mark stream as eof if stream filter fails fatally
1 parent 681e015 commit 4fde88b

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

ext/bz2/bug71263.phpt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Bug #71263: fread() does not detects decoding errors from filter bzip2.decompres
33
--FILE--
44
<?php
55

6-
// This bug is only partially fixed.
6+
// This bug is only partially fixed. fread() returns false on the first call
7+
// but does not fail on the second.
78

89
function test($case) {
910
$plain = "The quick brown fox jumps over the lazy dog.";
@@ -32,10 +33,11 @@ function test($case) {
3233

3334
$r = fopen($fn, "r");
3435
stream_filter_append($r, 'bzip2.decompress', STREAM_FILTER_READ);
35-
while (!feof($r)) {
36-
$s = fread($r, 100);
37-
echo "read: "; var_dump($s);
38-
}
36+
$s = fread($r, 100);
37+
echo "read: "; var_dump($s);
38+
echo "eof: ", feof($r), "\n";
39+
$s = fread($r, 100);
40+
echo "read: "; var_dump($s);
3941
fclose($r);
4042
unlink($fn);
4143
}
@@ -47,9 +49,13 @@ test(3);
4749
--EXPECT--
4850
Compressed len = 81
4951
read: bool(false)
50-
read: string(43) "bthes ohe rpujumr.bthes ohe rpujumr.bthes o"
52+
eof: 1
53+
read: string(0) ""
5154
Compressed len = 81
5255
read: string(0) ""
56+
eof: 1
57+
read: string(0) ""
5358
Compressed len = 81
5459
read: bool(false)
55-
read: string(44) "The quick brown fox jumps over the lazy dog."
60+
eof: 1
61+
read: string(0) ""

main/streams/streams.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ PHPAPI int _php_stream_fill_read_buffer(php_stream *stream, size_t size)
614614
case PSFS_ERR_FATAL:
615615
/* some fatal error. Theoretically, the stream is borked, so all
616616
* further reads should fail. */
617+
stream->eof = 1;
617618
efree(chunk_buf);
618619
return FAILURE;
619620
}

0 commit comments

Comments
 (0)