From 19c844594e40d79cea016b54f9ab3a367440b4c9 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 21 Sep 2020 13:57:05 +0200 Subject: Fix mmap copying Instead of attempting to map large files into memory at once, we map chunks of at most `PHP_STREAM_MMAP_MAX` bytes, and repeat that until we hit the point where `php_stream_seek()` fails (see bug 54902), and copy the rest of the file by reading and writing small chunks. We also fix the mapping behavior for zero bytes on Windows, which did not error (as with `mmap()`), but would have mapped the remaining file. --- main/streams/php_stream_mmap.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'main/streams/php_stream_mmap.h') diff --git a/main/streams/php_stream_mmap.h b/main/streams/php_stream_mmap.h index 132f3214c1..40288cc27f 100644 --- a/main/streams/php_stream_mmap.h +++ b/main/streams/php_stream_mmap.h @@ -58,6 +58,8 @@ typedef struct { #define PHP_STREAM_MMAP_ALL 0 +#define PHP_STREAM_MMAP_MAX (512 * 1024 * 1024) + #define php_stream_mmap_supported(stream) (_php_stream_set_option((stream), PHP_STREAM_OPTION_MMAP_API, PHP_STREAM_MMAP_SUPPORTED, NULL) == 0 ? 1 : 0) /* Returns 1 if the stream in its current state can be memory mapped, -- cgit v1.2.1