Skip to content

Commit 1700ab7

Browse files
committed
Remember that a stream filter failed
So that further reads also fail.
1 parent 4fde88b commit 1700ab7

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

ext/bz2/bug71263.phpt

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

6-
// This bug is only partially fixed. fread() returns false on the first call
7-
// but does not fail on the second.
6+
// Possibly errors should be thrown.
87

98
function test($case) {
109
$plain = "The quick brown fox jumps over the lazy dog.";
@@ -50,12 +49,12 @@ test(3);
5049
Compressed len = 81
5150
read: bool(false)
5251
eof: 1
53-
read: string(0) ""
52+
read: bool(false)
5453
Compressed len = 81
5554
read: string(0) ""
5655
eof: 1
5756
read: string(0) ""
5857
Compressed len = 81
5958
read: bool(false)
6059
eof: 1
61-
read: string(0) ""
60+
read: bool(false)

main/php_streams.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ struct _php_stream {
204204
* PHP_STREAM_FCLOSE_XXX as appropriate */
205205
uint8_t fclose_stdiocast:2;
206206

207+
uint8_t filter_errored:1; /* Stream filter failed fatally */
208+
207209
uint8_t fgetss_state; /* for fgetss to handle multiline tags */
208210

209211
char mode[16]; /* "rwb" etc. ala stdio */

main/streams/streams.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,10 @@ PHPAPI int _php_stream_fill_read_buffer(php_stream *stream, size_t size)
538538
main/streams/filter.c::_php_stream_filter_append */
539539
stream->writepos = stream->readpos = 0;
540540

541+
if (stream->filter_errored) {
542+
return FAILURE;
543+
}
544+
541545
/* allocate a buffer for reading chunks */
542546
chunk_buf = emalloc(stream->chunk_size);
543547

@@ -615,6 +619,7 @@ PHPAPI int _php_stream_fill_read_buffer(php_stream *stream, size_t size)
615619
/* some fatal error. Theoretically, the stream is borked, so all
616620
* further reads should fail. */
617621
stream->eof = 1;
622+
stream->filter_errored = 1;
618623
efree(chunk_buf);
619624
return FAILURE;
620625
}

0 commit comments

Comments
 (0)