[php-src] Issue #24170: bzip2.decompress stream wrapper truncates valid bz2 files from pbzip2
| From: | ftzdomino | Date: | Wed, 07 Oct 2026 00:25:23 +0000 |
| Subject: | [php-src] Issue #24170: bzip2.decompress stream wrapper truncates valid bz2 files from pbzip2 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-252927@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/24170
Author: ftzdomino
### Description
pbzip2 slices a file into 900000 byte blocks and then concatenates the streams. The default PHP
behavior for using libbzip2 stops after the first concatenated stream without warning. This results
in silently truncated reads.
The following code:
```php
<?php
$f = tempnam(sys_get_temp_dir(), 'bz');
file_put_contents($f, bzcompress(str_repeat('a', 900000)) . bzcompress('tail'));
// two streams
echo strlen(file_get_contents("compress.bzip2://$f")), "\n"; // 900000 if
truncated, 900004 if not
$fp = fopen($f, 'rb');
stream_filter_append($fp, 'bzip2.decompress', STREAM_FILTER_READ,
['concatenated' => true]);
echo strlen(stream_get_contents($fp)), "\n"; // 900004
```
Resulted in this output:
```
900000
900004
```
But I expected this output instead:
```
900004
900004
```
### PHP Version
```plain
PHP 8.5.11 (cli) (built: Sep 24 2026 14:38:36) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.5.11, Copyright (c) Zend Technologies
with Zend OPcache v8.5.11, Copyright (c), by Zend Technologies
```
### Operating System
Debian 12.15