1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

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
This commit is contained in:
dan
2012-10-01 06:50:55 +00:00
parent 60441af4f2
commit c9a5326974
5 changed files with 28 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
C Improved\sORDER\sBY\soptimization\swhen\souter\sloops\sof\sa\sjoin\sreturn\sa\ssingle\srow. 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-09-29T19:10:29.355 D 2012-10-01T06:50:55.576
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 5f4f26109f9d80829122e0e09f9cda008fa065fb F Makefile.in 5f4f26109f9d80829122e0e09f9cda008fa065fb
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -162,8 +162,8 @@ F src/os.h 027491c77d2404c0a678bb3fb06286f331eb9b57
F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04
F src/os_unix.c 69b2fe66316524eebf5f1ce85c1fdfe2952307e9 F src/os_unix.c 69b2fe66316524eebf5f1ce85c1fdfe2952307e9
F src/os_win.c 90c7a1fe2698867555ba4266f5bd436c85d0d1dc F src/os_win.c 90c7a1fe2698867555ba4266f5bd436c85d0d1dc
F src/pager.c 9c59818c480261c1c5a4772532e0df92a27745a1 F src/pager.c 9f5f2823594cc2848e151510f726af02896485b5
F src/pager.h 8b8c9bc065a3c66769df8724dfdf492ee1aab3c5 F src/pager.h bdbc379557eb2e233dfec10986b3086877e72db7
F src/parse.y f29df90bd3adc64b33114ab1de9fb7768fcf2099 F src/parse.y f29df90bd3adc64b33114ab1de9fb7768fcf2099
F src/pcache.c f8043b433a57aba85384a531e3937a804432a346 F src/pcache.c f8043b433a57aba85384a531e3937a804432a346
F src/pcache.h 1b5dcc3dc8103d03e625b177023ee67764fa6b7c F src/pcache.h 1b5dcc3dc8103d03e625b177023ee67764fa6b7c
@@ -246,7 +246,7 @@ F src/vdbemem.c cb55e84b8e2c15704968ee05f0fae25883299b74
F src/vdbesort.c 0dc1b274dcb4d4c8e71b0b2b15261f286caba39b F src/vdbesort.c 0dc1b274dcb4d4c8e71b0b2b15261f286caba39b
F src/vdbetrace.c 8bd5da325fc90f28464335e4cc4ad1407fe30835 F src/vdbetrace.c 8bd5da325fc90f28464335e4cc4ad1407fe30835
F src/vtab.c d8020c0a0e8ccc490ca449d7e665311b6e9f3ba9 F src/vtab.c d8020c0a0e8ccc490ca449d7e665311b6e9f3ba9
F src/wal.c 5acb3e7bbd31f10ba39acad9ce6b399055337a9d F src/wal.c e1fe8f92a0ea0fef8faa87ec43a127a478589d22
F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6 F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6
F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b
F src/where.c acc2ec5f6879721f332223da393777438ea5a606 F src/where.c acc2ec5f6879721f332223da393777438ea5a606
@@ -1018,7 +1018,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9
P d869eddaf208c4bf03f6bd1848f510392f9dba49 P 62225b4a4c4bfe1820ef54cb202edf2cd866429f
R 13af348b1bf68a7c36428c6258d6aba5 R 09d3e5b05c9dfd1b20715f593e6818b6
U drh U dan
Z 7bbfe622f493f625120e8c012f0943a5 Z 07828d460d32254f1342208677faf52f

View File

@@ -1 +1 @@
62225b4a4c4bfe1820ef54cb202edf2cd866429f 6b4ff83bff07d427af585c9fd03be90abf2fc82f

View File

@@ -2509,6 +2509,21 @@ static int pager_truncate(Pager *pPager, Pgno nPage){
return rc; 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 ** Set the value of the Pager.sectorSize variable for the given
** pager based on the value returned by the xSectorSize method ** pager based on the value returned by the xSectorSize method
@@ -2544,14 +2559,7 @@ static void setSectorSize(Pager *pPager){
** call will segfault. */ ** call will segfault. */
pPager->sectorSize = 512; pPager->sectorSize = 512;
}else{ }else{
pPager->sectorSize = sqlite3OsSectorSize(pPager->fd); pPager->sectorSize = sqlite3SectorSize(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;
}
} }
} }

View File

@@ -160,6 +160,7 @@ void *sqlite3PagerTempSpace(Pager*);
int sqlite3PagerIsMemdb(Pager*); int sqlite3PagerIsMemdb(Pager*);
void sqlite3PagerCacheStat(Pager *, int, int, int *); void sqlite3PagerCacheStat(Pager *, int, int, int *);
void sqlite3PagerClearCache(Pager *); void sqlite3PagerClearCache(Pager *);
int sqlite3SectorSize(sqlite3_file *);
/* Functions used to truncate the database file. */ /* Functions used to truncate the database file. */
void sqlite3PagerTruncateImage(Pager*,Pgno); void sqlite3PagerTruncateImage(Pager*,Pgno);

View File

@@ -2828,7 +2828,7 @@ int sqlite3WalFrames(
*/ */
if( isCommit && (sync_flags & WAL_SYNC_TRANSACTIONS)!=0 ){ if( isCommit && (sync_flags & WAL_SYNC_TRANSACTIONS)!=0 ){
if( pWal->padToSectorBoundary ){ if( pWal->padToSectorBoundary ){
int sectorSize = sqlite3OsSectorSize(pWal->pWalFd); int sectorSize = sqlite3SectorSize(pWal->pWalFd);
w.iSyncPoint = ((iOffset+sectorSize-1)/sectorSize)*sectorSize; w.iSyncPoint = ((iOffset+sectorSize-1)/sectorSize)*sectorSize;
while( iOffset<w.iSyncPoint ){ while( iOffset<w.iSyncPoint ){
rc = walWriteOneFrame(&w, pLast, nTruncate, iOffset); rc = walWriteOneFrame(&w, pLast, nTruncate, iOffset);