[php-src] Issue #25053: Phar truncates entries of 4 GiB or more without error/warning

From: Date: Fri, 30 Oct 2026 11:38:23 +0000
Subject: [php-src] Issue #25053: Phar truncates entries of 4 GiB or more without error/warning
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-253936@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/25053 Author: haampie ### Description Adding a file of 4 GiB or more to a phar, tar or zip archive succeeds without any warning, but the archive stores the size and file truncated to 2^32 bytes. The following code: ```php <?php $dir = sys_get_temp_dir() . '/phar-4g'; @mkdir($dir); $src = "$dir/big"; $f = fopen($src, 'w'); ftruncate($f, 2**32 + 1); // sparse file of 4 GiB + 1 byte fclose($f); @unlink("$dir/out.tar"); $tar = new PharData("$dir/out.tar"); $tar->addFile($src, 'big'); var_dump(filesize("$dir/out.tar")); var_dump((new PharData("$dir/out.tar"))['big']->getSize()); ``` Resulted in this output: ``` int(2048) int(1) ``` I would expect it to either raise an exception (unsupported feature) or an archive with the 4 GiB + 1 bytes. The same happens with Phar::ZIP and with the phar format, and with buildFromDirectory() instead of addFile(). In every case the entry ends up 1 byte long. The cause is that phar_entry_info stores the sizes as uint32_t: https://github.com/php/php-src/blob/8ab2340b8e20e5845f35069f41212a18142f57cc/ext/phar/phar_internal.h#L196 and the lengths are assigned to them without a check ### PHP Version ### Operating System macOS 15.7 (arm64) ### PHP Version ```plain PHP 8.7.0-dev master at 8ab2340b8e20 ``` ### Operating System _No response_

« previous php.bugs (#253936) next »