summaryrefslogtreecommitdiff
path: root/main/streams
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-09-09 19:21:41 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2020-09-22 13:15:07 +0200
commit4000780b3d0bbba2d94f65602e602c3892d9775b (patch)
tree5616d28bb711b58b132faba79d4e7353c661f9c3 /main/streams
parent730fdc77a74ce4816cfb10181357e3eee92e2d3b (diff)
downloadphp-git-4000780b3d0bbba2d94f65602e602c3892d9775b.tar.gz
Fix #79423: copy command is limited to size of file it can copy
Passing `NULL` as `lpFileSizeHigh` to `GetFileSize()` gives wrong results for files larger than 0xFFFFFFFF bytes. We fix this by using `GetFileSizeEx()`, and let the mapping fail, if the file size is too large for the architecture. Closes GH-5319.
Diffstat (limited to 'main/streams')
-rw-r--r--main/streams/plain_wrapper.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/main/streams/plain_wrapper.c b/main/streams/plain_wrapper.c
index 2b81912857..d00a6efe29 100644
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@ -749,6 +749,7 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
php_stream_mmap_range *range = (php_stream_mmap_range*)ptrparam;
HANDLE hfile = (HANDLE)_get_osfhandle(fd);
DWORD prot, acc, loffs = 0, delta = 0;
+ LARGE_INTEGER file_size;
switch (value) {
case PHP_STREAM_MMAP_SUPPORTED:
@@ -785,7 +786,22 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
return PHP_STREAM_OPTION_RETURN_ERR;
}
- size = GetFileSize(hfile, NULL);
+ if (!GetFileSizeEx(hfile, &file_size)) {
+ CloseHandle(data->file_mapping);
+ data->file_mapping = NULL;
+ return PHP_STREAM_OPTION_RETURN_ERR;
+ }
+# if defined(_WIN64)
+ size = file_size.QuadPart;
+# else
+ if (file_size.HighPart) {
+ CloseHandle(data->file_mapping);
+ data->file_mapping = NULL;
+ return PHP_STREAM_OPTION_RETURN_ERR;
+ } else {
+ size = file_size.LowPart;
+ }
+# endif
if (range->offset > size) {
range->offset = size;
}