From 3d1b730c11a4e37884d25bf8af0d5726834986c4 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 20 Apr 2020 13:27:35 +0200 Subject: [PATCH] Fix #71417: fread() does not report zlib.inflate errors If the zlib.inflate filter fails to decompress the stream, we raise a notice instead of failing silently. --- NEWS | 3 +++ .../tests/filters/filter_errors_zlib_inflate.phpt | 4 ++++ ext/zlib/tests/bug71417.phpt | 8 +++++++- ext/zlib/tests/bug_52944.phpt | 4 +++- ext/zlib/tests/zlib_filter_inflate2.phpt | 3 ++- ext/zlib/zlib_filter.c | 1 + 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 5e6ff58f39..e39f3587ad 100644 --- a/NEWS +++ b/NEWS @@ -168,4 +168,7 @@ PHP NEWS . Add ZipArchive::isCompressionMethodSupported() and ZipArchive::isEncryptionMethodSupported() method (libzip 1.7.0). (Remi) +- Zlib: + . Fixed bug #71417 (fread() does not report zlib.inflate errors). (cmb) + <<< NOTE: Insert NEWS from last stable release here prior to actual release! >>> diff --git a/ext/standard/tests/filters/filter_errors_zlib_inflate.phpt b/ext/standard/tests/filters/filter_errors_zlib_inflate.phpt index be7bdba3fb..608a8ad28d 100644 --- a/ext/standard/tests/filters/filter_errors_zlib_inflate.phpt +++ b/ext/standard/tests/filters/filter_errors_zlib_inflate.phpt @@ -10,5 +10,9 @@ filter_errors_test('zlib.inflate', gzencode('42')); --EXPECTF-- test filtering of buffered data +Notice: stream_filter_append(): zlib: data error in %s on line %d + Warning: stream_filter_append(): Filter failed to process pre-buffered data in %s test filtering of non buffered data + +Notice: stream_get_contents(): zlib: data error in %s on line %d diff --git a/ext/zlib/tests/bug71417.phpt b/ext/zlib/tests/bug71417.phpt index cadd1e6735..b601b4c725 100644 --- a/ext/zlib/tests/bug71417.phpt +++ b/ext/zlib/tests/bug71417.phpt @@ -1,5 +1,5 @@ --TEST-- -Bug #71417: fread() does not detect decoding errors from filter zlib.inflate +Bug #71417: fread() does not report zlib.inflate errors --SKIPIF-- --FILE-- @@ -69,6 +69,8 @@ test(4); gzdecode(): Warning: gzdecode(): data error in %s on line %d + +Notice: fread(): zlib: data error in %s on line %d read: bool(false) gzdecode(): Warning: gzdecode(): data error in %s on line %d @@ -77,8 +79,12 @@ read: string(32) "The quick brown fox jumps over t" gzdecode(): Warning: gzdecode(): data error in %s on line %d + +Notice: fread(): zlib: data error in %s on line %d read: bool(false) gzdecode(): Warning: gzdecode(): data error in %s on line %d + +Notice: fread(): zlib: data error in %s on line %d read: bool(false) diff --git a/ext/zlib/tests/bug_52944.phpt b/ext/zlib/tests/bug_52944.phpt index 782e2396a7..e63dde2d29 100644 --- a/ext/zlib/tests/bug_52944.phpt +++ b/ext/zlib/tests/bug_52944.phpt @@ -18,7 +18,9 @@ var_dump(fread($fp,1)); var_dump(fread($fp,1)); fclose($fp); echo "Done.\n"; ---EXPECT-- +?> +--EXPECTF-- +Notice: fread(): zlib: data error in %s on line %d bool(false) string(0) "" Done. diff --git a/ext/zlib/tests/zlib_filter_inflate2.phpt b/ext/zlib/tests/zlib_filter_inflate2.phpt index 7dd2ebb594..0f7718dbdf 100644 --- a/ext/zlib/tests/zlib_filter_inflate2.phpt +++ b/ext/zlib/tests/zlib_filter_inflate2.phpt @@ -33,7 +33,8 @@ fclose($fp); ---EXPECT-- +--EXPECTF-- +Notice: fread(): zlib: data error in %s on line %d 1 2 This is quite the thing ain't it diff --git a/ext/zlib/zlib_filter.c b/ext/zlib/zlib_filter.c index 9026fcfedf..cffa65f488 100644 --- a/ext/zlib/zlib_filter.c +++ b/ext/zlib/zlib_filter.c @@ -90,6 +90,7 @@ static php_stream_filter_status_t php_zlib_inflate_filter( exit_status = PSFS_PASS_ON; } else if (status != Z_OK) { /* 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; -- 2.40.0