Skip to content

Commit 64865c6

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Fix #81092: fflush before stream_filter_remove corrupts stream
2 parents 2184422 + 902ec69 commit 64865c6

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

0 commit comments

Comments
 (0)