1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Avoid casting a value larger than 2^31 to a (size_t) on systems where it

is a 32-bit type.

FossilOrigin-Name: 46c3085dcad6372ac20eff499e17fe11680fdf4adb9186bf8b12221a5047e485
This commit is contained in:
dan
2017-08-07 18:13:28 +00:00
parent 54640de156
commit 43c1e622cd
3 changed files with 15 additions and 8 deletions

View File

@@ -3858,6 +3858,13 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){
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 a 32-bit type. */
if( sizeof(size_t)<8 ){
newLimit = (newLimit & 0x7FFFFFFF);
}
*(i64*)pArg = pFile->mmapSizeMax;
if( newLimit>=0 && newLimit!=pFile->mmapSizeMax && pFile->nFetchOut==0 ){
pFile->mmapSizeMax = newLimit;