Index: src/os_unix.c ================================================================== --- src/os_unix.c +++ src/os_unix.c @@ -3856,10 +3856,18 @@ i64 newLimit = *(i64*)pArg; int rc = SQLITE_OK; if( newLimit>sqlite3GlobalConfig.mxMmap ){ newLimit = sqlite3GlobalConfig.mxMmap; } + + /* The value of newLimit may be eventually cast to (size_t) and passed + ** to mmap(). Restrict its value to 2GB if (size_t) is not at least a + ** 64-bit type. */ + if( newLimit>0 && sizeof(size_t)<8 ){ + newLimit = (newLimit & 0x7FFFFFFF); + } + *(i64*)pArg = pFile->mmapSizeMax; if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){ pFile->mmapSizeMax = newLimit; if( pFile->mmapSize>0 ){ unixUnmapfile(pFile); Index: src/os_win.c ================================================================== --- src/os_win.c +++ src/os_win.c @@ -3557,10 +3557,18 @@ i64 newLimit = *(i64*)pArg; int rc = SQLITE_OK; if( newLimit>sqlite3GlobalConfig.mxMmap ){ newLimit = sqlite3GlobalConfig.mxMmap; } + + /* The value of newLimit may be eventually cast to (SIZE_T) and passed + ** to MapViewOfFile(). Restrict its value to 2GB if (SIZE_T) is not at + ** least a 64-bit type. */ + if( newLimit>0 && sizeof(SIZE_T)<8 ){ + newLimit = (newLimit & 0x7FFFFFFF); + } + *(i64*)pArg = pFile->mmapSizeMax; if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){ pFile->mmapSizeMax = newLimit; if( pFile->mmapSize>0 ){ winUnmapfile(pFile); Index: test/bigmmap.test ================================================================== --- test/bigmmap.test +++ test/bigmmap.test @@ -28,11 +28,11 @@ set mmap_limit 0 db eval { SELECT compile_options AS x FROM pragma_compile_options WHERE x LIKE 'max_mmap_size=%' } { - regexp {MAX_MMAP_SIZE=(.*)} $x -> mmap_limit + regexp {MAX_MMAP_SIZE=([0-9]*)} $x -> mmap_limit } if {$mmap_limit < [expr 8 * 1<<30]} { puts "Skipping bigmmap.test - requires SQLITE_MAX_MMAP_SIZE >= 8G" finish_test return