From 43c1e622cd0b99c2445711aaf6dd0dc149aa5bb5 Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 7 Aug 2017 18:13:28 +0000 Subject: [PATCH 1/4] Avoid casting a value larger than 2^31 to a (size_t) on systems where it is a 32-bit type. FossilOrigin-Name: 46c3085dcad6372ac20eff499e17fe11680fdf4adb9186bf8b12221a5047e485 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/os_unix.c | 7 +++++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 632eafe272..fd064848f8 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\sout-of-order\stest\snumber. -D 2017-08-07T17:28:18.557 +C Avoid\scasting\sa\svalue\slarger\sthan\s2^31\sto\sa\s(size_t)\son\ssystems\swhere\sit\n\sis\sa\s32-bit\stype. +D 2017-08-07T18:13:28.414 F Makefile.in d9873c9925917cca9990ee24be17eb9613a668012c85a343aef7e5536ae266e8 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 02b469e9dcd5b7ee63fc1fb05babc174260ee4cfa4e0ef2e48c3c6801567a016 @@ -436,7 +436,7 @@ F src/os.c add02933b1dce7a39a005b00a2f5364b763e9a24 F src/os.h 8e976e59eb4ca1c0fca6d35ee803e38951cb0343 F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85 F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 -F src/os_unix.c 0681c6ef336fcb6a111f45b60a5faea38992ed6c4ae9fbd57a6f8e247724fa68 +F src/os_unix.c bbe39b5921b7ced6d25fcbff9fd17eb4aa101fd0bd97e1db3c3e2d526527f9de F src/os_win.c 2a6c73eef01c51a048cc4ddccd57f981afbec18a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c 1e63b0299cf123cf38c48413ec03190f56c1e7d0ccc6573c467d8ac240b898e9 @@ -1644,7 +1644,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 17447062799239ee978bedbf7fcc67f4c7d2cad2e82dcf9349a966fc8f67d390 -R ca41cbb6852190e871773e9cd0aff375 -U mistachkin -Z 3adad62141c8f232faf24a8c8ab64143 +P 38f30091f9b1e2c393396da7257f3487fa374e1ee6d610577291909768ff9626 +R d7182bcc87ba6fa2b23f4b7d5a15d267 +U dan +Z 7df27ce143e774d3022f4451dd6ffa24 diff --git a/manifest.uuid b/manifest.uuid index 9f1b0d6dd1..5e786a636a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -38f30091f9b1e2c393396da7257f3487fa374e1ee6d610577291909768ff9626 \ No newline at end of file +46c3085dcad6372ac20eff499e17fe11680fdf4adb9186bf8b12221a5047e485 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 157be3c3ac..99a06279f3 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -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; From 010a016ac9b01e5b42148b4f4862a3eab0f1643f Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 7 Aug 2017 18:27:19 +0000 Subject: [PATCH 2/4] Update bigmmap.test to account for builds that use "-DSQLITE_MAX_MMAP_SIZE=LL". FossilOrigin-Name: 7c8b6f1cace42ee1182c252c8e66e5679f523f4248c27d38c075ae21e7c25374 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/bigmmap.test | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index fd064848f8..40348eadca 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\scasting\sa\svalue\slarger\sthan\s2^31\sto\sa\s(size_t)\son\ssystems\swhere\sit\n\sis\sa\s32-bit\stype. -D 2017-08-07T18:13:28.414 +C Update\sbigmmap.test\sto\saccount\sfor\sbuilds\sthat\suse\n"-DSQLITE_MAX_MMAP_SIZE=LL". +D 2017-08-07T18:27:19.354 F Makefile.in d9873c9925917cca9990ee24be17eb9613a668012c85a343aef7e5536ae266e8 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 02b469e9dcd5b7ee63fc1fb05babc174260ee4cfa4e0ef2e48c3c6801567a016 @@ -608,7 +608,7 @@ F test/bestindex4.test 4cb5ff7dbaebadb87d366f51969271778423b455 F test/between.test 34d375fb5ce1ae283ffe82b6b233e9f38e84fc6c F test/bigfile.test aa74f4e5db51c8e54a1d9de9fa65d01d1eb20b59 F test/bigfile2.test 1b489a3a39ae90c7f027b79110d6b4e1dbc71bfc -F test/bigmmap.test 736009b1fa591b4e12b4569d189e8e2020d9c2532aa270db924e6a662d18cd98 +F test/bigmmap.test ed6058a7794be26865c94d5bb62e12cdc4f7f01562b3b04f13eb3cdc52783921 F test/bigrow.test f0aeb7573dcb8caaafea76454be3ade29b7fc747 F test/bigsort.test 8299fa9298f4f1e02fc7d2712e8b77d6cd60e5a2 F test/bind.test 1e136709b306f7ed3192d349c2930d89df6ab621654ad6f1a72381d3fe76f483 @@ -1644,7 +1644,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 38f30091f9b1e2c393396da7257f3487fa374e1ee6d610577291909768ff9626 -R d7182bcc87ba6fa2b23f4b7d5a15d267 +P 46c3085dcad6372ac20eff499e17fe11680fdf4adb9186bf8b12221a5047e485 +R 917e163835aeeed6d367dbe94c0c0ca5 U dan -Z 7df27ce143e774d3022f4451dd6ffa24 +Z a557a600c035a5d5a09fd207b43b667b diff --git a/manifest.uuid b/manifest.uuid index 5e786a636a..721979933e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -46c3085dcad6372ac20eff499e17fe11680fdf4adb9186bf8b12221a5047e485 \ No newline at end of file +7c8b6f1cace42ee1182c252c8e66e5679f523f4248c27d38c075ae21e7c25374 \ No newline at end of file diff --git a/test/bigmmap.test b/test/bigmmap.test index 8ab93dd81a..d44c487fc2 100644 --- a/test/bigmmap.test +++ b/test/bigmmap.test @@ -30,7 +30,7 @@ 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" From 089df506879c9e95476855958a01bb1210f5980c Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 7 Aug 2017 18:54:10 +0000 Subject: [PATCH 3/4] Fix a problem with handling SQLITE_FCNTL_MMAP_SIZE requests with a negative parameter in os_unix.c. FossilOrigin-Name: 4249fcf7b0c0233f9b3ba5139702738d5221c5309240e6e91dc139eff59471fe --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_unix.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 40348eadca..5a37dac9d0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sbigmmap.test\sto\saccount\sfor\sbuilds\sthat\suse\n"-DSQLITE_MAX_MMAP_SIZE=LL". -D 2017-08-07T18:27:19.354 +C Fix\sa\sproblem\swith\shandling\sSQLITE_FCNTL_MMAP_SIZE\srequests\swith\sa\snegative\nparameter\sin\sos_unix.c. +D 2017-08-07T18:54:10.201 F Makefile.in d9873c9925917cca9990ee24be17eb9613a668012c85a343aef7e5536ae266e8 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 02b469e9dcd5b7ee63fc1fb05babc174260ee4cfa4e0ef2e48c3c6801567a016 @@ -436,7 +436,7 @@ F src/os.c add02933b1dce7a39a005b00a2f5364b763e9a24 F src/os.h 8e976e59eb4ca1c0fca6d35ee803e38951cb0343 F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85 F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 -F src/os_unix.c bbe39b5921b7ced6d25fcbff9fd17eb4aa101fd0bd97e1db3c3e2d526527f9de +F src/os_unix.c 47b6c1e501902272fa23f1356e1048bcdfa89b9974a664612e4ad018a16bf533 F src/os_win.c 2a6c73eef01c51a048cc4ddccd57f981afbec18a F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c 1e63b0299cf123cf38c48413ec03190f56c1e7d0ccc6573c467d8ac240b898e9 @@ -1644,7 +1644,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 46c3085dcad6372ac20eff499e17fe11680fdf4adb9186bf8b12221a5047e485 -R 917e163835aeeed6d367dbe94c0c0ca5 +P 7c8b6f1cace42ee1182c252c8e66e5679f523f4248c27d38c075ae21e7c25374 +R 798f9b25fca6a2710c43590a6d82bf28 U dan -Z a557a600c035a5d5a09fd207b43b667b +Z 6e6dcb1a7a4b333e27c902b697e4e4b3 diff --git a/manifest.uuid b/manifest.uuid index 721979933e..5b50b75668 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7c8b6f1cace42ee1182c252c8e66e5679f523f4248c27d38c075ae21e7c25374 \ No newline at end of file +4249fcf7b0c0233f9b3ba5139702738d5221c5309240e6e91dc139eff59471fe \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 99a06279f3..3daa8fec9a 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3861,7 +3861,7 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){ /* 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 ){ + if( newLimit>0 && sizeof(size_t)<8 ){ newLimit = (newLimit & 0x7FFFFFFF); } From e35395a45a134e9ef99373aa5497a0fed556e4ec Mon Sep 17 00:00:00 2001 From: mistachkin Date: Mon, 7 Aug 2017 19:06:54 +0000 Subject: [PATCH 4/4] On Windows, avoid casting a value larger than 2^31 to a (SIZE_T) on systems where it is a 32-bit type. FossilOrigin-Name: f08d63b413601b22726e8b96ff8eb779857321b9df30db0333f71e50ffb5077d --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/os_unix.c | 3 ++- src/os_win.c | 8 ++++++++ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 5a37dac9d0..e7cd451881 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\swith\shandling\sSQLITE_FCNTL_MMAP_SIZE\srequests\swith\sa\snegative\nparameter\sin\sos_unix.c. -D 2017-08-07T18:54:10.201 +C On\sWindows,\savoid\scasting\sa\svalue\slarger\sthan\s2^31\sto\sa\s(SIZE_T)\son\ssystems\swhere\sit\sis\sa\s32-bit\stype. +D 2017-08-07T19:06:54.041 F Makefile.in d9873c9925917cca9990ee24be17eb9613a668012c85a343aef7e5536ae266e8 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 02b469e9dcd5b7ee63fc1fb05babc174260ee4cfa4e0ef2e48c3c6801567a016 @@ -436,8 +436,8 @@ F src/os.c add02933b1dce7a39a005b00a2f5364b763e9a24 F src/os.h 8e976e59eb4ca1c0fca6d35ee803e38951cb0343 F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85 F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586 -F src/os_unix.c 47b6c1e501902272fa23f1356e1048bcdfa89b9974a664612e4ad018a16bf533 -F src/os_win.c 2a6c73eef01c51a048cc4ddccd57f981afbec18a +F src/os_unix.c a361273749229755f92c8f0e3e4855054ad39bbc5c65773e8db5d0b79afa632c +F src/os_win.c 964165b66cde03abc72fe948198b01be608436894732eadb94c8720d2467f223 F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a F src/pager.c 1e63b0299cf123cf38c48413ec03190f56c1e7d0ccc6573c467d8ac240b898e9 F src/pager.h f2a99646c5533ffe11afa43e9e0bea74054e4efa @@ -1644,7 +1644,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 7c8b6f1cace42ee1182c252c8e66e5679f523f4248c27d38c075ae21e7c25374 -R 798f9b25fca6a2710c43590a6d82bf28 -U dan -Z 6e6dcb1a7a4b333e27c902b697e4e4b3 +P 4249fcf7b0c0233f9b3ba5139702738d5221c5309240e6e91dc139eff59471fe +R ada1495a3f5fb5efd255ea78a3bbd776 +U mistachkin +Z fa32878e56ea1fef6300b9cb2bae7ccb diff --git a/manifest.uuid b/manifest.uuid index 5b50b75668..d6a6257bdc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4249fcf7b0c0233f9b3ba5139702738d5221c5309240e6e91dc139eff59471fe \ No newline at end of file +f08d63b413601b22726e8b96ff8eb779857321b9df30db0333f71e50ffb5077d \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 3daa8fec9a..d1ebd81f68 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -3860,7 +3860,8 @@ static int unixFileControl(sqlite3_file *id, int op, void *pArg){ } /* 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. */ + ** 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); } diff --git a/src/os_win.c b/src/os_win.c index a87d7d0925..7045448fe1 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -3559,6 +3559,14 @@ static int winFileControl(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 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;