Skip to content

Fix #48725: Support for flushing in zlib stream #3320

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 2 commits 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
29 changes: 29 additions & 0 deletions ext/standard/tests/streams/bug48725_generic.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
--TEST--
Bug #48725 (Support for flushing in zlib stream, more generic issue)
--FILE--
<?php
class DebugClosingFilter extends php_user_filter {
public function filter($in, $out, &$consumed, $closing) {
if ($closing) {
echo "Closing" . PHP_EOL;
}
while ($bucket = stream_bucket_make_writeable($in)) {
$consumed += $bucket->datalen;
stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
}

stream_filter_register('debug.closing', 'DebugClosingFilter');

$stream = fopen('data://text/plain;base64,' . base64_encode('Foo bar baz'), 'r');
stream_filter_append($stream, 'debug.closing', STREAM_FILTER_READ);
$stream_contents = stream_get_contents($stream);
print $stream_contents . PHP_EOL;
?>
===DONE===
--EXPECT--
Closing
Foo bar baz
===DONE===
14 changes: 14 additions & 0 deletions ext/zlib/tests/bug48725.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Bug #48725 (Support for flushing in zlib stream)
--SKIPIF--
<?php if (!extension_loaded("zlib")) print "skip"; ?>
--FILE--
<?php
$stream = fopen('data://text/plain;base64,' . base64_encode('Foo bar baz'), 'r');
stream_filter_append($stream, 'zlib.deflate', STREAM_FILTER_READ);
print bin2hex(stream_get_contents($stream)) . PHP_EOL;
?>
===DONE===
--EXPECT--
73cbcf57484a2c02e22a00
===DONE===
4 changes: 2 additions & 2 deletions main/streams/streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ PHPAPI void _php_stream_fill_read_buffer(php_stream *stream, size_t size)
if (stream->readfilters.head) {
char *chunk_buf;
int err_flag = 0;
size_t justread = 0;
php_stream_bucket_brigade brig_in = { NULL, NULL }, brig_out = { NULL, NULL };
php_stream_bucket_brigade *brig_inp = &brig_in, *brig_outp = &brig_out, *brig_swap;

Expand All @@ -538,8 +539,7 @@ PHPAPI void _php_stream_fill_read_buffer(php_stream *stream, size_t size)
/* allocate a buffer for reading chunks */
chunk_buf = emalloc(stream->chunk_size);

while (!stream->eof && !err_flag && (stream->writepos - stream->readpos < (zend_off_t)size)) {
size_t justread = 0;
while ((justread != 0 || !stream->eof) && !err_flag && (stream->writepos - stream->readpos < (zend_off_t)size)) {
int flags;
php_stream_bucket *bucket;
php_stream_filter_status_t status = PSFS_ERR_FATAL;
Expand Down