diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2020-12-08 11:49:14 +0100 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2020-12-08 11:49:28 +0100 |
commit | d6ae0f010ec6bc4713dc9fe79e79947c2404a8dd (patch) | |
tree | 2963778368adb89c953b06387f37acc460da0df9 /ext | |
parent | c3734f9ae182640ba6cc2fbd5724166b1b3d1275 (diff) | |
parent | 65f5573bc82108bbaf2727ffa11575f3292d736f (diff) | |
download | php-git-d6ae0f010ec6bc4713dc9fe79e79947c2404a8dd.tar.gz |
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
Fix #77069: stream filter loses final block of data
Diffstat (limited to 'ext')
-rw-r--r-- | ext/standard/tests/streams/bug77069.phpt | 57 | ||||
-rw-r--r-- | ext/standard/tests/streams/bug77080.phpt | 16 | ||||
-rw-r--r-- | ext/standard/tests/streams/bug79984.phpt | 57 | ||||
-rw-r--r-- | ext/zlib/tests/bug48725_2.phpt | 15 | ||||
-rw-r--r-- | ext/zlib/zlib_filter.c | 2 |
5 files changed, 146 insertions, 1 deletions
diff --git a/ext/standard/tests/streams/bug77069.phpt b/ext/standard/tests/streams/bug77069.phpt new file mode 100644 index 0000000000..ec78ac25c5 --- /dev/null +++ b/ext/standard/tests/streams/bug77069.phpt @@ -0,0 +1,57 @@ +--TEST-- +Bug #77069 (stream filter loses final block of data) +--FILE-- +<?php +class MyFilter extends php_user_filter { + private $data = ''; + + public function filter($in, $out, &$consumed, $closing) { + $return = PSFS_FEED_ME; + + // While input data is available, continue to read it. + while ($bucket_in = stream_bucket_make_writeable($in)) { + $this->data .= $bucket_in->data; + $consumed += $bucket_in->datalen; + + // Process whole lines. + while (preg_match('/(.*?)[\r\n]+(.*)/s', $this->data, $match) === 1) { + list(, $data, $this->data) = $match; + // Send this record output. + $data = strrev($data) . PHP_EOL; + $bucket_out = stream_bucket_new($this->stream, $data); + $return = PSFS_PASS_ON; + stream_bucket_append($out, $bucket_out); + } + } + + // Process the final line. + if ($closing && $this->data !== '') { + $data = strrev($this->data) . PHP_EOL; + $bucket_out = stream_bucket_new($this->stream, $data); + $return = PSFS_PASS_ON; + stream_bucket_append($out, $bucket_out); + } + + return $return; + } +} + +stream_filter_register('my-filter', 'MyFilter'); + +$input = "Line one\nLine two\nLine three"; + +$stream = fopen('data://text/plain,' . $input, 'r'); +stream_filter_append($stream, 'my-filter'); + +$output = ''; +while (!feof($stream)) { + $output .= fread($stream, 16); +} +fclose($stream); + +echo $output; +?> +--EXPECT-- +eno eniL +owt eniL +eerht eniL diff --git a/ext/standard/tests/streams/bug77080.phpt b/ext/standard/tests/streams/bug77080.phpt new file mode 100644 index 0000000000..feb20656d6 --- /dev/null +++ b/ext/standard/tests/streams/bug77080.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #77080 (Deflate not working) +--SKIPIF-- +<?php +if (!extension_loaded('zlib')) die('skip zlib extension not available'); +?> +--FILE-- +<?php +$string = str_repeat("0123456789", 100); +$stream = fopen('data://text/plain,' . $string,'r'); +stream_filter_append($stream, 'zlib.deflate', STREAM_FILTER_READ, 6); +$compressed = stream_get_contents($stream); +var_dump(gzinflate($compressed) === $string); +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/streams/bug79984.phpt b/ext/standard/tests/streams/bug79984.phpt new file mode 100644 index 0000000000..7126458fff --- /dev/null +++ b/ext/standard/tests/streams/bug79984.phpt @@ -0,0 +1,57 @@ +--TEST-- +Bug #79984 (Stream filter is not called with closing arg) +--FILE-- +<?php + +class F extends php_user_filter +{ + public function onCreate() + { + echo 'filter onCreate' . PHP_EOL; + return true; + } + + public function onClose() + { + echo 'filter onClose' . PHP_EOL; + } + + public function filter($in, $out, &$consumed, $closing) + { + while ($bucket = stream_bucket_make_writeable($in)) { + $bucket->data = strtoupper($bucket->data); + $consumed += $bucket->datalen; + stream_bucket_append($out, $bucket); + } + echo 'filtered ' . ($consumed ? $consumed : 0) . ' bytes'; + if ($closing) { + echo ' and closing.'; + } else { + echo '.'; + } + if (feof($this->stream)) { + echo ' Stream has reached end-of-file.'; + } + echo PHP_EOL; + return PSFS_PASS_ON; + } +} + +stream_filter_register('f', 'F'); + +$str = str_repeat('a', 8320); + +$f2 = fopen('php://temp', 'r+b'); +fwrite($f2, $str); +fseek($f2, 0, SEEK_SET); +stream_filter_append($f2, 'f', STREAM_FILTER_READ); +var_dump(strlen(stream_get_contents($f2))); +fclose($f2); + +?> +--EXPECT-- +filter onCreate +filtered 8192 bytes. +filtered 128 bytes and closing. +int(8320) +filter onClose diff --git a/ext/zlib/tests/bug48725_2.phpt b/ext/zlib/tests/bug48725_2.phpt new file mode 100644 index 0000000000..168afd8d3d --- /dev/null +++ b/ext/zlib/tests/bug48725_2.phpt @@ -0,0 +1,15 @@ +--TEST-- +Bug #48725 (Support for flushing in zlib stream) +--SKIPIF-- +<?php +if (!extension_loaded('zlib')) die('skip zlib extension not available'); +?> +--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)); +?> +--EXPECT-- +72cbcf57484a2c02e22a00000000ffff0300 diff --git a/ext/zlib/zlib_filter.c b/ext/zlib/zlib_filter.c index cffa65f488..0ed0c2713a 100644 --- a/ext/zlib/zlib_filter.c +++ b/ext/zlib/zlib_filter.c @@ -88,7 +88,7 @@ static php_stream_filter_status_t php_zlib_inflate_filter( inflateEnd(&(data->strm)); data->finished = '\1'; exit_status = PSFS_PASS_ON; - } else if (status != Z_OK) { + } 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); |