php-src/ext/zlib
Niels Dossche 5aaf7b4937
Fix zlib support for large files
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"
```

Closes GH-17775.
2025-02-14 23:09:57 +01:00
..
tests Fix memory leak when encoding check fails 2025-02-13 19:10:17 +01:00
config.w32 Sync leading and final newlines in source code files 2018-10-14 12:56:38 +02:00
config0.m4 Normalize comments in *nix build system m4 files 2019-05-12 18:43:03 +02:00
CREDITS
php_zlib.def Export gzfwrite() 2021-04-26 12:09:31 +02:00
php_zlib.h Update http->https in license (#6945) 2021-05-06 12:16:35 +02:00
zlib.c Fix memory leak when encoding check fails 2025-02-13 19:10:17 +01:00
zlib.stub.php Fix GH-17745: zlib extension incorrectly handles object arguments 2025-02-11 21:52:53 +01:00
zlib_arginfo.h Fix GH-17745: zlib extension incorrectly handles object arguments 2025-02-11 21:52:53 +01:00
zlib_filter.c Merge branch 'PHP-8.0' into PHP-8.1 2022-06-25 07:39:55 +01:00
zlib_fopen_wrapper.c Fix zlib support for large files 2025-02-14 23:09:57 +01:00