gzfile and readgzfile no longer identify corrupted gzip data
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
Using this (invalid) gzip file: corrupt.txt.gz for testing below.
Just for completion: this is what happens using zcat/gzip - it can't decode it and thinks it's encrypted. It's not, it's just garbage.
$ zcat corrupt.txt.gz gzip: corrupt.txt.gz is encrypted -- not supported
The following code:
<?php
var_dump(gzfile("corrupt.txt.gz"));
Resulted in this output:
array(2) {
[0]=>
string(8) "x�� U"
[1]=>
string(6) "I-.��"
}
But I expected this output instead:
array(0) {
}
Running the same code with PHP < 8.5.3 (including 8.5.2) will result in the expected empty array.
The same issue exists when using readgzfile(): all older versions will return -1 while 8.5.3 returns binary data.
PHP Version
PHP 8.5.3 (cli) (built: Feb 12 2026 16:29:14) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.5.3, Copyright (c) Zend Technologies
with Xdebug v3.5.1, Copyright (c) 2002-2026, by Derick Rethans
with Zend OPcache v8.5.3, Copyright (c), by Zend Technologies
Operating System
ArchLinux
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied corrupt.txt.gz case with gzfile() and readgzfile() on PHP 8.5.2 and 8.5.3. Trace the gzip handling used by these functions and compare the corrupted-data result with the expected empty array and -1 return values; done means both functions reject the invalid stream as before.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100