Skip to content

[4.x] Accept gzip and bzip2 files whose content is empty or "0" - #60

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-gzip-bzip2-empty-content
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-gzip-bzip2-empty-content

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

Gzip::extract() and Bzip2::extract() checked the decompressed data with empty($buffer). empty() is also true for '' and "0", so valid archives of an empty file or of a file containing just 0 threw RuntimeException('Unable to decompress data') (gzencode(''), gzencode('0'), bzcompress('0'), …). In the other direction, bzdecompress() returns a negative error code (e.g. -5) for some corrupt input; empty() did not catch that, so the error code was written to the destination file as text.

The check is now $buffer === false for gzinflate() and !is_string($buffer) for bzdecompress().

Testing Instructions

New tests in GzipTest and Bzip2Test:

  • testExtractFalsyContent (data provider: empty file, file with 0) fails on 4.x-dev with "Unable to decompress data" and passes with this PR.
  • testExtractCorruptData: for bzip2, 4.x-dev writes -5 into the destination instead of throwing; with this PR it throws and writes nothing. The gzip variant guards the existing behaviour.

vendor/bin/phpunit, phpcs on src/ and PHPStan are clean.

Documentation Changes Required

None. The docs do not describe this edge case; the change makes these archives behave like any other.

🤖 Generated with Claude Code

Gzip and Bzip2 treated an empty() decompression result as failure, so
valid archives of an empty file or of a file containing "0" threw
"Unable to decompress data". bzdecompress() also returns a negative
error code for some corrupt input, which empty() did not catch, so the
code was written to the destination as text.

Check for false (gzinflate) and for a non-string result (bzdecompress)
instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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