[php-src] PR #21381: Fixed GH-21376: gzfile and readgzfile no longer detect corrupted gzip…

From: Date: Sat, 07 Mar 2026 21:34:32 +0000
Subject: [php-src] PR #21381: Fixed GH-21376: gzfile and readgzfile no longer detect corrupted gzip…
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-35129@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/21381 Author: GabrielCordeiroBarrosoTeles Fixes #21376 ## Summary From PHP 8.5.3, gzfile() and readgzfile() no longer treat corrupted gzip data as an error. They may return decompressed data (garbage) instead of an empty array and -1 respectively, as in previous versions. This change restores the previous behaviour when the zlib stream reports a data or stream error. ## Changes 1. **ext/zlib/zlib_fopen_wrapper.c** After each successful gzread() call, the wrapper now checks gzerror(). If the error is Z_DATA_ERROR or Z_STREAM_ERROR, the read is treated as failed (return -1), so callers receive error semantics instead of invalid data. 2. **ext/zlib/zlib.c** readgzfile() now stores the return value of php_stream_passthru() in an ssize_t and returns it with RETURN_LONG((zend_long) size). This ensures that a stream error (-1) is returned to PHP as -1 instead of being converted to a large positive value when stored in a size_t. 3. **ext/zlib/tests/bug21376_corrupt_gz.phpt** New test that uses a minimal invalid gzip file and asserts that gzfile() returns an empty array and readgzfile() returns -1. 4. **NEWS** Entry added for this fix under the Zlib section. ## Testing - run-tests.php ext/zlib/tests/bug21376_corrupt_gz.phpt — PASS - run-tests.php ext/zlib/ — 143 tests passed, 0 failed ### Regression test run (screenshot below) *Local run of the new test inside Docker (Ubuntu 24.04, PHP 8.6.0-dev from this tree). The test creates a minimal invalid gzip file, calls gzfile() and readgzfile() with @ to suppress warnings, and asserts empty array and -1 as expected. Result: 1 test, 1 passed, 0 failed.* <img width="802" height="718" alt="Captura de Tela 2026-03-07 às 18 34 00" src="https://github.com/user-attachments/assets/dae9716e-32a1-4354-bac1-4652c94dacf7" />

« previous php.git-pulls (#35129) next »