Skip to content

Commit 3d1b730

Browse files
committed
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.
1 parent 661c0ac commit 3d1b730

File tree

6 files changed

+20
-3
lines changed

6 files changed

+20
-3
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,7 @@ PHP NEWS
168168
. Add ZipArchive::isCompressionMethodSupported() and
169169
ZipArchive::isEncryptionMethodSupported() method (libzip 1.7.0). (Remi)
170170

171+
- Zlib:
172+
. Fixed bug #71417 (fread() does not report zlib.inflate errors). (cmb)
173+
171174
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>

ext/standard/tests/filters/filter_errors_zlib_inflate.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ filter_errors_test('zlib.inflate', gzencode('42'));
1010
--EXPECTF--
1111
test filtering of buffered data
1212

13+
Notice: stream_filter_append(): zlib: data error in %s on line %d
14+
1315
Warning: stream_filter_append(): Filter failed to process pre-buffered data in %s
1416
test filtering of non buffered data
17+
18+
Notice: stream_get_contents(): zlib: data error in %s on line %d

ext/zlib/tests/bug71417.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Bug #71417: fread() does not detect decoding errors from filter zlib.inflate
2+
Bug #71417: fread() does not report zlib.inflate errors
33
--SKIPIF--
44
<?php if (!extension_loaded('zlib')) die ('skip zlib extension not available in this build'); ?>
55
--FILE--
@@ -69,6 +69,8 @@ test(4);
6969
gzdecode():
7070
Warning: gzdecode(): data error in %s on line %d
7171

72+
73+
Notice: fread(): zlib: data error in %s on line %d
7274
read: bool(false)
7375
gzdecode():
7476
Warning: gzdecode(): data error in %s on line %d
@@ -77,8 +79,12 @@ read: string(32) "The quick brown fox jumps over t"
7779
gzdecode():
7880
Warning: gzdecode(): data error in %s on line %d
7981

82+
83+
Notice: fread(): zlib: data error in %s on line %d
8084
read: bool(false)
8185
gzdecode():
8286
Warning: gzdecode(): data error in %s on line %d
8387

88+
89+
Notice: fread(): zlib: data error in %s on line %d
8490
read: bool(false)

ext/zlib/tests/bug_52944.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ var_dump(fread($fp,1));
1818
var_dump(fread($fp,1));
1919
fclose($fp);
2020
echo "Done.\n";
21-
--EXPECT--
21+
?>
22+
--EXPECTF--
23+
Notice: fread(): zlib: data error in %s on line %d
2224
bool(false)
2325
string(0) ""
2426
Done.

ext/zlib/tests/zlib_filter_inflate2.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ fclose($fp);
3333
<?php
3434
@unlink(__DIR__ . '/test.txt.gz');
3535
?>
36-
--EXPECT--
36+
--EXPECTF--
37+
Notice: fread(): zlib: data error in %s on line %d
3738
1
3839
2
3940
This is quite the thing ain't it

ext/zlib/zlib_filter.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ static php_stream_filter_status_t php_zlib_inflate_filter(
9090
exit_status = PSFS_PASS_ON;
9191
} else if (status != Z_OK) {
9292
/* Something bad happened */
93+
php_error_docref(NULL, E_NOTICE, "zlib: %s", zError(status));
9394
php_stream_bucket_delref(bucket);
9495
/* reset these because despite the error the filter may be used again */
9596
data->strm.next_in = data->inbuf;

0 commit comments

Comments
 (0)