From ee2b1575a7cca2bf362859d7c920cfabad9b9ec5 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Fri, 17 Apr 2020 16:05:40 +0200 Subject: [PATCH 1/2] 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. --- 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 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ext/zlib/tests/bug71417.phpt b/ext/zlib/tests/bug71417.phpt index cadd1e67359a0..66dc5ef9e04ab 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 inflate failed 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 inflate failed in %s on line %d read: bool(false) gzdecode(): Warning: gzdecode(): data error in %s on line %d + +Notice: fread(): zlib inflate failed 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 782e2396a7e6a..a1c71b9b661b9 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 inflate failed 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 7dd2ebb594e58..4f06fbbeabd0a 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 inflate failed 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 9026fcfedfe31..fc7e8081d4737 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 inflate failed"); php_stream_bucket_delref(bucket); /* reset these because despite the error the filter may be used again */ data->strm.next_in = data->inbuf; From 2f1d6bb95bd7fe0fee7177437ea798fb90dd6c1e Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 20 Apr 2020 13:27:35 +0200 Subject: [PATCH 2/2] Use zError() instead of generic error message We also fix failing test cases. --- ext/standard/tests/filters/filter_errors_zlib_inflate.phpt | 4 ++++ ext/zlib/tests/bug71417.phpt | 6 +++--- ext/zlib/tests/bug_52944.phpt | 2 +- ext/zlib/tests/zlib_filter_inflate2.phpt | 2 +- ext/zlib/zlib_filter.c | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ext/standard/tests/filters/filter_errors_zlib_inflate.phpt b/ext/standard/tests/filters/filter_errors_zlib_inflate.phpt index be7bdba3fb90e..608a8ad28dbd5 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 66dc5ef9e04ab..b601b4c725202 100644 --- a/ext/zlib/tests/bug71417.phpt +++ b/ext/zlib/tests/bug71417.phpt @@ -70,7 +70,7 @@ gzdecode(): Warning: gzdecode(): data error in %s on line %d -Notice: fread(): zlib inflate failed 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 @@ -80,11 +80,11 @@ gzdecode(): Warning: gzdecode(): data error in %s on line %d -Notice: fread(): zlib inflate failed 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 inflate failed 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 a1c71b9b661b9..e63dde2d29369 100644 --- a/ext/zlib/tests/bug_52944.phpt +++ b/ext/zlib/tests/bug_52944.phpt @@ -20,7 +20,7 @@ fclose($fp); echo "Done.\n"; ?> --EXPECTF-- -Notice: fread(): zlib inflate failed in %s on line %d +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 4f06fbbeabd0a..0f7718dbdf4d2 100644 --- a/ext/zlib/tests/zlib_filter_inflate2.phpt +++ b/ext/zlib/tests/zlib_filter_inflate2.phpt @@ -34,7 +34,7 @@ fclose($fp); @unlink(__DIR__ . '/test.txt.gz'); ?> --EXPECTF-- -Notice: fread(): zlib inflate failed in %s on line %d +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 fc7e8081d4737..cffa65f488df2 100644 --- a/ext/zlib/zlib_filter.c +++ b/ext/zlib/zlib_filter.c @@ -90,7 +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 inflate failed"); + 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;