Update fs codes for upstream bugfix
# define swow_ssize_t ssize_t
#endif // PHP_VERSION_ID < 70400
-// from main/streams/plain_wrapper.c @ 7aba6de1d02e445ce4a6088c2af4ce327bd67bd6
+// from main/streams/plain_wrapper.c @ aff365871aec54c9a556d7667f131b8638d20194
#include "php.h"
#include "php_globals.h"
@@ -1570,7 +1570,7 @@ static int swow_stdiop_fs_set_option(php_stream *stream, int option, int value,
{
php_stream_mmap_range *range = (php_stream_mmap_range*)ptrparam;
HANDLE hfile = (HANDLE)_get_osfhandle(fd);
- DWORD prot, acc, loffs = 0, delta = 0;
+ DWORD prot, acc, loffs = 0, hoffs = 0, delta = 0;
LARGE_INTEGER file_size;
switch (value) {
@@ -1638,8 +1638,11 @@ static int swow_stdiop_fs_set_option(php_stream *stream, int option, int value,
GetSystemInfo(&info);
gran = info.dwAllocationGranularity;
- loffs = ((DWORD)range->offset / gran) * gran;
- delta = (DWORD)range->offset - loffs;
+ ZEND_ASSERT(gran != 0 && (gran & (gran - 1)) == 0);
+ size_t rounded_offset = (range->offset / gran) * gran;
+ delta = range->offset - rounded_offset;
+ loffs = (DWORD)rounded_offset;
+ hoffs = (DWORD)(rounded_offset >> 32);
}
/* MapViewOfFile()ing zero bytes would map to the end of the file; match *nix behavior instead */
@@ -1647,7 +1650,7 @@ static int swow_stdiop_fs_set_option(php_stream *stream, int option, int value,
return PHP_STREAM_OPTION_RETURN_ERR;
}
- data->last_mapped_addr = MapViewOfFile(data->file_mapping, acc, 0, loffs, range->length + delta);
+ data->last_mapped_addr = MapViewOfFile(data->file_mapping, acc, hoffs, loffs, range->length + delta);
if (data->last_mapped_addr) {
/* give them back the address of the start offset they requested */
