Skip to content

Commit 4000780

Browse files
committed
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.
1 parent 730fdc7 commit 4000780

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 7.3.24
44

5+
- Core:
6+
. Fixed bug #79423 (copy command is limited to size of file it can copy).
7+
(cmb)
8+
59
- MySQLnd:
610
. Fixed bug #80115 (mysqlnd.debug doesn't recognize absolute paths with
711
slashes). (cmb)

main/streams/plain_wrapper.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
749749
php_stream_mmap_range *range = (php_stream_mmap_range*)ptrparam;
750750
HANDLE hfile = (HANDLE)_get_osfhandle(fd);
751751
DWORD prot, acc, loffs = 0, delta = 0;
752+
LARGE_INTEGER file_size;
752753

753754
switch (value) {
754755
case PHP_STREAM_MMAP_SUPPORTED:
@@ -785,7 +786,22 @@ static int php_stdiop_set_option(php_stream *stream, int option, int value, void
785786
return PHP_STREAM_OPTION_RETURN_ERR;
786787
}
787788

788-
size = GetFileSize(hfile, NULL);
789+
if (!GetFileSizeEx(hfile, &file_size)) {
790+
CloseHandle(data->file_mapping);
791+
data->file_mapping = NULL;
792+
return PHP_STREAM_OPTION_RETURN_ERR;
793+
}
794+
# if defined(_WIN64)
795+
size = file_size.QuadPart;
796+
# else
797+
if (file_size.HighPart) {
798+
CloseHandle(data->file_mapping);
799+
data->file_mapping = NULL;
800+
return PHP_STREAM_OPTION_RETURN_ERR;
801+
} else {
802+
size = file_size.LowPart;
803+
}
804+
# endif
789805
if (range->offset > size) {
790806
range->offset = size;
791807
}

0 commit comments

Comments
 (0)