summaryrefslogtreecommitdiff
path: root/main/streams/plain_wrapper.c
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-09-21 13:57:05 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2020-09-21 16:07:57 +0200
commit19c844594e40d79cea016b54f9ab3a367440b4c9 (patch)
treedee764e2934dae24b4f0389b64585aaa49442901 /main/streams/plain_wrapper.c
parentd1feeed7f33bda43f92dd2b5fba9547b4cc3fe33 (diff)
downloadphp-git-19c844594e40d79cea016b54f9ab3a367440b4c9.tar.gz
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.
Diffstat (limited to 'main/streams/plain_wrapper.c')
-rw-r--r--main/streams/plain_wrapper.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index 50ca925dea..298950cf9e 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -826,6 +826,11 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
delta = (DWORD)range->offset - loffs;
}
+ /* MapViewOfFile()ing zero bytes would map to the end of the file; match *nix behavior instead */
+ if (range->length + delta == 0) {
+ return PHP_STREAM_OPTION_RETURN_ERR;
+ }
+
data->last_mapped_addr = MapViewOfFile(data->file_mapping, acc, 0, loffs, range->length + delta);
if (data->last_mapped_addr) {