From: dan Date: Mon, 1 Oct 2012 06:50:55 +0000 (+0000) Subject: Ensure that the value returned by xSectorSize() is reasonable (currently defined... X-Git-Tag: version-3.7.15~106 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c9a532697400a62240e4ccfbf7f8f7cd404b576b;p=thirdparty%2Fsqlite.git Ensure that the value returned by xSectorSize() is reasonable (currently defined as between 2^5 and 2^16 bytes) before using it to calculate the amount of padding to add to a wal file. FossilOrigin-Name: 6b4ff83bff07d427af585c9fd03be90abf2fc82f --- diff --git a/manifest b/manifest index 9f30517df5..07b54cc849 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\sORDER\sBY\soptimization\swhen\souter\sloops\sof\sa\sjoin\sreturn\sa\ssingle\srow. -D 2012-09-29T19:10:29.355 +C Ensure\sthat\sthe\svalue\sreturned\sby\sxSectorSize()\sis\sreasonable\s(currently\sdefined\sas\sbetween\s2^5\sand\s2^16\sbytes)\sbefore\susing\sit\sto\scalculate\sthe\samount\sof\spadding\sto\sadd\sto\sa\swal\sfile. +D 2012-10-01T06:50:55.576 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5f4f26109f9d80829122e0e09f9cda008fa065fb F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -162,8 +162,8 @@ F src/os.h 027491c77d2404c0a678bb3fb06286f331eb9b57 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_unix.c 69b2fe66316524eebf5f1ce85c1fdfe2952307e9 F src/os_win.c 90c7a1fe2698867555ba4266f5bd436c85d0d1dc -F src/pager.c 9c59818c480261c1c5a4772532e0df92a27745a1 -F src/pager.h 8b8c9bc065a3c66769df8724dfdf492ee1aab3c5 +F src/pager.c 9f5f2823594cc2848e151510f726af02896485b5 +F src/pager.h bdbc379557eb2e233dfec10986b3086877e72db7 F src/parse.y f29df90bd3adc64b33114ab1de9fb7768fcf2099 F src/pcache.c f8043b433a57aba85384a531e3937a804432a346 F src/pcache.h 1b5dcc3dc8103d03e625b177023ee67764fa6b7c @@ -246,7 +246,7 @@ F src/vdbemem.c cb55e84b8e2c15704968ee05f0fae25883299b74 F src/vdbesort.c 0dc1b274dcb4d4c8e71b0b2b15261f286caba39b F src/vdbetrace.c 8bd5da325fc90f28464335e4cc4ad1407fe30835 F src/vtab.c d8020c0a0e8ccc490ca449d7e665311b6e9f3ba9 -F src/wal.c 5acb3e7bbd31f10ba39acad9ce6b399055337a9d +F src/wal.c e1fe8f92a0ea0fef8faa87ec43a127a478589d22 F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6 F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b F src/where.c acc2ec5f6879721f332223da393777438ea5a606 @@ -1018,7 +1018,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 -P d869eddaf208c4bf03f6bd1848f510392f9dba49 -R 13af348b1bf68a7c36428c6258d6aba5 -U drh -Z 7bbfe622f493f625120e8c012f0943a5 +P 62225b4a4c4bfe1820ef54cb202edf2cd866429f +R 09d3e5b05c9dfd1b20715f593e6818b6 +U dan +Z 07828d460d32254f1342208677faf52f diff --git a/manifest.uuid b/manifest.uuid index 2aa22ae871..19bd1d6a97 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -62225b4a4c4bfe1820ef54cb202edf2cd866429f \ No newline at end of file +6b4ff83bff07d427af585c9fd03be90abf2fc82f \ No newline at end of file diff --git a/src/pager.c b/src/pager.c index a094e0da20..28f6546301 100644 --- a/src/pager.c +++ b/src/pager.c @@ -2509,6 +2509,21 @@ static int pager_truncate(Pager *pPager, Pgno nPage){ return rc; } +/* +** Return a sanitized version of the sector-size of OS file pFile. The +** return value is guaranteed to lie between 32 and MAX_SECTOR_SIZE. +*/ +int sqlite3SectorSize(sqlite3_file *pFile){ + int iRet = sqlite3OsSectorSize(pFile); + if( iRet<32 ){ + iRet = 512; + }else if( iRet>MAX_SECTOR_SIZE ){ + assert( MAX_SECTOR_SIZE>=512 ); + iRet = MAX_SECTOR_SIZE; + } + return iRet; +} + /* ** Set the value of the Pager.sectorSize variable for the given ** pager based on the value returned by the xSectorSize method @@ -2544,14 +2559,7 @@ static void setSectorSize(Pager *pPager){ ** call will segfault. */ pPager->sectorSize = 512; }else{ - pPager->sectorSize = sqlite3OsSectorSize(pPager->fd); - if( pPager->sectorSize<32 ){ - pPager->sectorSize = 512; - } - if( pPager->sectorSize>MAX_SECTOR_SIZE ){ - assert( MAX_SECTOR_SIZE>=512 ); - pPager->sectorSize = MAX_SECTOR_SIZE; - } + pPager->sectorSize = sqlite3SectorSize(pPager->fd); } } diff --git a/src/pager.h b/src/pager.h index 2b60e058da..5fb0f0133f 100644 --- a/src/pager.h +++ b/src/pager.h @@ -160,6 +160,7 @@ void *sqlite3PagerTempSpace(Pager*); int sqlite3PagerIsMemdb(Pager*); void sqlite3PagerCacheStat(Pager *, int, int, int *); void sqlite3PagerClearCache(Pager *); +int sqlite3SectorSize(sqlite3_file *); /* Functions used to truncate the database file. */ void sqlite3PagerTruncateImage(Pager*,Pgno); diff --git a/src/wal.c b/src/wal.c index cc166ba430..8394bfa29f 100644 --- a/src/wal.c +++ b/src/wal.c @@ -2828,7 +2828,7 @@ int sqlite3WalFrames( */ if( isCommit && (sync_flags & WAL_SYNC_TRANSACTIONS)!=0 ){ if( pWal->padToSectorBoundary ){ - int sectorSize = sqlite3OsSectorSize(pWal->pWalFd); + int sectorSize = sqlite3SectorSize(pWal->pWalFd); w.iSyncPoint = ((iOffset+sectorSize-1)/sectorSize)*sectorSize; while( iOffset