Skip to content

Fix #79423: copy command is limited to size of file it can copy #5319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion main/streams/plain_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
}
Expand Down