Skip to content

phar: cap decompression output against declared uncompressed_filesize#21806

Open
iliaal wants to merge 1 commit intophp:PHP-8.4from
iliaal:fix/phar-decompression-bounds
Open

phar: cap decompression output against declared uncompressed_filesize#21806
iliaal wants to merge 1 commit intophp:PHP-8.4from
iliaal:fix/phar-decompression-bounds

Conversation

@iliaal
Copy link
Copy Markdown
Contributor

@iliaal iliaal commented Apr 18, 2026

Prevents decompression amplification in phar_open_entry_fp().

The function decompressed entries by streaming compressed_filesize bytes through a filter into a tmpfile, then checked the output size after the full copy. A crafted phar whose compressed data expanded beyond uncompressed_filesize could write large amounts to disk before the check ran.

Replaces the single php_stream_copy_to_stream_ex() call with an 8 KiB chunked loop that flushes the decompression filter and checks the running output size after each chunk. Aborts when output exceeds uncompressed_filesize.

phar_open_entry_fp() decompressed entries by streaming
compressed_filesize bytes through a filter into a tmpfile, then
checked output size after the full copy. A crafted phar whose
compressed data expanded beyond uncompressed_filesize could write
large amounts to disk before the check ran.

Replace the single php_stream_copy_to_stream_ex() call with an 8 KiB
chunked loop that flushes the decompression filter and checks running
output size after each chunk. Abort when output exceeds
uncompressed_filesize.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant