[php-src] PR #17775: Fix zlib support for large files

From: Date: Wed, 12 Feb 2025 21:50:07 +0000
Subject: [php-src] PR #17775: Fix zlib support for large files
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-30740@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/17775 Author: nielsdos gzread() and gzwrite() have effectively a 4GiB limit at the moment because the APIs of the zlib library use unsigned ints. For example, this means that the count argument of gzread() and gzwrite() & co effectively are modulo 2**32. Fix this by adding a loop to handle all bytes. As for automated testing, I didn't find an easy way to write a phpt for this that wouldn't use a lot of memory or requires a large file. For instance, the gzread() test that I manually ran requires a 4MiB input file (and I can't shrink it because zlib has a max window size). Here are the testing instructions, run on 64-bit: To test for gzwrite(): ```php $f = gzopen("out.txt.gz", "w"); gzwrite($f, str_repeat('a', 4*1024*1024*1024+64)); // 4GiB + 64 bytes ``` Then use zcat out.txt.gz|wc -c to check that all bytes were written (should be 4294967360). To test for gzread(): Create a file containing all a's for example that is 4GiB + 64 bytes. Then compress it into out.txt.gz using the gzip command. Then run: ```php $f = gzopen("out.txt.gz", "r"); $str = gzread($f, 4*1024*1024*1024+64); var_dump(strlen($str)); // 4294967360 var_dump(substr($str, -3)); // string (3) "aaa" ``` For automated testing we would first need https://github.com/php/php-src/pull/14895 and then generate a file dynamically using gzwrite() and then check it with gzread() I suppose.

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