Skip to content

Commit 902ec69

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #81092: fflush before stream_filter_remove corrupts stream
2 parents d29f15c + a1738d8 commit 902ec69

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ PHP NEWS
1212
. Fixed bug #81070 (Integer underflow in memory limit comparison).
1313
(Peter van Dommelen)
1414

15+
- Bzip2:
16+
. Fixed bug #81092 (fflush before stream_filter_remove corrupts stream).
17+
(cmb)
18+
1519
- OCI8:
1620
. Fixed bug #81088 (error in regression test for oci_fetch_object() and
1721
oci_fetch_array()). (Máté)

ext/bz2/bz2_filter.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ static php_stream_filter_status_t php_bz2_compress_filter(
267267

268268
if (flags & PSFS_FLAG_FLUSH_CLOSE || ((flags & PSFS_FLAG_FLUSH_INC) && !data->is_flushed)) {
269269
/* Spit it out! */
270-
status = BZ_FINISH_OK;
271-
while (status == BZ_FINISH_OK) {
270+
do {
272271
status = BZ2_bzCompress(&(data->strm), (flags & PSFS_FLAG_FLUSH_CLOSE ? BZ_FINISH : BZ_FLUSH));
273272
data->is_flushed = 1;
274273
if (data->strm.avail_out < data->outbuf_len) {
@@ -280,7 +279,7 @@ static php_stream_filter_status_t php_bz2_compress_filter(
280279
data->strm.next_out = data->outbuf;
281280
exit_status = PSFS_PASS_ON;
282281
}
283-
}
282+
} while (status == (flags & PSFS_FLAG_FLUSH_CLOSE ? BZ_FINISH_OK : BZ_FLUSH_OK));
284283
}
285284

286285
if (bytes_consumed) {

ext/bz2/tests/bug81092.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #81092 (fflush before stream_filter_remove corrupts stream)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('bz2')) die('skip bz2 extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$stream = fopen(__DIR__ . "/81092.bz2", 'wb+');
10+
$filter = stream_filter_append($stream, 'bzip2.compress', STREAM_FILTER_WRITE, ['blocks' => 9, 'work' => 0]);
11+
fwrite($stream, random_bytes(8192));
12+
fflush($stream);
13+
stream_filter_remove($filter);
14+
15+
var_dump(strlen(bzdecompress(file_get_contents(__DIR__ . "/81092.bz2"))));
16+
?>
17+
--CLEAN--
18+
<?php
19+
@unlink(__DIR__ . "/81092.bz2");
20+
?>
21+
--EXPECT--
22+
int(8192)

0 commit comments

Comments
 (0)