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:
+16
-8
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<w.iSyncPoint ){
|
||||
rc = walWriteOneFrame(&w, pLast, nTruncate, iOffset);
|
||||
|
||||
Reference in New Issue
Block a user