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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
zlib.inflate filter removed by the error handler of its own notice
--EXTENSIONS--
zlib
--FILE--
<?php
$fp = fopen('php://memory', 'w+');
$filter = stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_WRITE);
set_error_handler(function (int $errno, string $errstr) use (&$filter) {
echo $errstr, "\n";
var_dump(stream_filter_remove($filter));
return true;
});
var_dump(fwrite($fp, "\xff\xff\xff\xff"));

$fp = fopen('php://memory', 'w+');
fwrite($fp, "\xff\xff\xff\xff");
rewind($fp);
$filter = stream_filter_append($fp, 'zlib.inflate', STREAM_FILTER_READ);
var_dump(fread($fp, 10));
echo "Done\n";
?>
--EXPECT--
fwrite(): zlib: data error
bool(true)
bool(false)
fread(): zlib: data error
bool(true)
bool(false)
Done
3 changes: 2 additions & 1 deletion ext/zlib/zlib_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,12 @@ static php_stream_filter_status_t php_zlib_inflate_filter(
exit_status = PSFS_PASS_ON;
} else if (status != Z_OK && status != Z_BUF_ERROR) {
/* Something bad happened */
php_error_docref(NULL, E_NOTICE, "zlib: %s", zError(status));
php_stream_bucket_delref(bucket);
/* reset these because despite the error the filter may be used again */
data->strm.next_in = data->inbuf;
data->strm.avail_in = 0;
/* Last: an error handler may remove this filter and free data. */
php_error_docref(NULL, E_NOTICE, "zlib: %s", zError(status));
return PSFS_ERR_FATAL;
}
desired -= data->strm.avail_in; /* desired becomes what we consumed this round through */
Expand Down
Loading