[php-src] PR #23902: Fix gzfile() truncating lines with NUL bytes and splitting long lines
| From: | lacatoire | Date: | Fri, 25 Sep 2026 08:23:07 +0000 |
| Subject: | [php-src] PR #23902: Fix gzfile() truncating lines with NUL bytes and splitting long lines | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-38798@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/23902
Author: lacatoire
gzfile() reads each line into a fixed 8192-byte buffer with php_stream_gets() and stores it with
add_index_string(), which recomputes the length with strlen(). This causes two bugs:
- A NUL byte in the line silently truncates everything after it.
- Lines longer than 8190 bytes are split into multiple array entries.
file() already avoids both issues by using php_stream_get_line() with a NULL/0 buffer (dynamically
sized) and add_index_stringl() (explicit length). This applies the same approach to gzfile().
Reproducer:
\
\\`php
<?php
\$data = "before\0after\nline2\n";
file_put_contents('n.gz', gzencode(\$data));
var_dump(array_map('bin2hex', gzfile('n.gz'))); // drops everything from \0
onward
\\\`
A regression test is included covering NUL preservation (checked against gzgets() output) and a
20001-byte line staying as a single array entry.