Skip to content

phar: cap decompression output against declared uncompressed_filesize#44

Closed
iliaal wants to merge 1 commit intoPHP-8.4from
fix/phar-decompression-bounds
Closed

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

Conversation

@iliaal
Copy link
Copy Markdown
Owner

@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.

@iliaal iliaal force-pushed the fix/phar-decompression-bounds branch 3 times, most recently from 6e73717 to 9ebd95b Compare April 18, 2026 16:55
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.
@iliaal iliaal force-pushed the fix/phar-decompression-bounds branch from 9ebd95b to facb875 Compare April 18, 2026 17:13
@iliaal
Copy link
Copy Markdown
Owner Author

iliaal commented Apr 18, 2026

Promoted to php#21806.

@iliaal iliaal closed this Apr 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant