Module: wine Branch: master Commit: 24f7869e9385a6b6a4f2e555163deefcda109dc4 URL: https://gitlab.winehq.org/wine/wine/-/commit/24f7869e9385a6b6a4f2e555163deef...
Author: Alexandre Julliard julliard@winehq.org Date: Fri Dec 15 10:11:22 2023 +0100
server: Enforce a mapping size limit instead of relying on the Unix file system.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=55667
---
dlls/kernel32/tests/file.c | 13 ++++++++----- server/mapping.c | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/dlls/kernel32/tests/file.c b/dlls/kernel32/tests/file.c index 0493f90e30d..17cfe24d50a 100644 --- a/dlls/kernel32/tests/file.c +++ b/dlls/kernel32/tests/file.c @@ -3105,6 +3105,7 @@ static void test_MapFile(void) { HANDLE handle; HANDLE hmap; + UINT err;
ok(test_Mapfile_createtemp(&handle), "Couldn't create test file.\n");
@@ -3123,15 +3124,17 @@ static void test_MapFile(void)
ok(test_Mapfile_createtemp(&handle), "Couldn't create test file.\n");
+ SetLastError( 0xdeadbeef ); hmap = CreateFileMappingA( handle, NULL, PAGE_READWRITE, 0, 0, NULL ); + err = GetLastError(); ok( hmap == NULL, "mapped zero size file\n"); - ok( GetLastError() == ERROR_FILE_INVALID, "not ERROR_FILE_INVALID\n"); - - hmap = CreateFileMappingA( handle, NULL, PAGE_READWRITE, 0x80000, 0, NULL ); - ok( hmap == NULL, "mapping should fail\n"); + ok( err == ERROR_FILE_INVALID, "got %u\n", err );
- hmap = CreateFileMappingA( handle, NULL, PAGE_READWRITE, 0x80000, 0x10000, NULL ); + SetLastError( 0xdeadbeef ); + hmap = CreateFileMappingA( handle, NULL, PAGE_READWRITE, 0x8000000, 0x10000, NULL ); + err = GetLastError(); ok( hmap == NULL, "mapping should fail\n"); + ok( err == ERROR_NOT_ENOUGH_MEMORY || err == ERROR_INVALID_PARAMETER, "got %u\n", err );
/* On XP you can now map again, on Win 95 you cannot. */
diff --git a/server/mapping.c b/server/mapping.c index a101110c76c..f754078acf7 100644 --- a/server/mapping.c +++ b/server/mapping.c @@ -993,7 +993,7 @@ static struct mapping *create_mapping( struct object *root, const struct unicode } else if (st.st_size < mapping->size) { - if (!(file_access & FILE_WRITE_DATA)) + if (!(file_access & FILE_WRITE_DATA) || mapping->size >> 54 /* ntfs limit */) { set_error( STATUS_SECTION_TOO_BIG ); goto error;