aboutsummaryrefslogtreecommitdiff
path: root/src/dbstat.c
diff options
context:
space:
mode:
authordrh <>2021-10-01 02:16:52 +0000
committerdrh <>2021-10-01 02:16:52 +0000
commit817424fe377dd4980f23a37125da8f39abdaba1c (patch)
tree7d52741b38a254d143147778a12e4fc6863e4fa1 /src/dbstat.c
parentf06db3e8929e36f7686ccc8f9f138359c6b12e80 (diff)
parentafaa660aef3d596fabbbcf6e99746294f77dbafa (diff)
downloadsqlite-817424fe377dd4980f23a37125da8f39abdaba1c.tar.gz
sqlite-817424fe377dd4980f23a37125da8f39abdaba1c.zip
Merge updates from trunk
FossilOrigin-Name: 35351371c5e9602dec210ad0926ff8a1a269556ce1a166e81eb0543938e0c57e
Diffstat (limited to 'src/dbstat.c')
-rw-r--r--src/dbstat.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/dbstat.c b/src/dbstat.c
index 33f9ea8f7..bb88a76f4 100644
--- a/src/dbstat.c
+++ b/src/dbstat.c
@@ -26,6 +26,15 @@
&& !defined(SQLITE_OMIT_VIRTUALTABLE)
/*
+** The pager and btree modules arrange objects in memory so that there are
+** always approximately 200 bytes of addressable memory following each page
+** buffer. This way small buffer overreads caused by corrupt database pages
+** do not cause undefined behaviour. This module pads each page buffer
+** by the following number of bytes for the same purpose.
+*/
+#define DBSTAT_PAGE_PADDING_BYTES 256
+
+/*
** Page paths:
**
** The value of the 'path' column describes the path taken from the
@@ -459,7 +468,7 @@ static int statDecodePage(Btree *pBt, StatPage *p){
if( nPayload>(u32)nLocal ){
int j;
int nOvfl = ((nPayload - nLocal) + nUsable-4 - 1) / (nUsable - 4);
- if( iOff+nLocal>nUsable || nPayload>0x7fffffff ){
+ if( iOff+nLocal+4>nUsable || nPayload>0x7fffffff ){
goto statPageIsCorrupt;
}
pCell->nLastOvfl = (nPayload-nLocal) - (nOvfl-1) * (nUsable-4);
@@ -533,10 +542,11 @@ static int statGetPage(
int rc;
if( pPg->aPg==0 ){
- pPg->aPg = (u8*)sqlite3_malloc(pgsz);
+ pPg->aPg = (u8*)sqlite3_malloc(pgsz + DBSTAT_PAGE_PADDING_BYTES);
if( pPg->aPg==0 ){
return SQLITE_NOMEM_BKPT;
}
+ memset(&pPg->aPg[pgsz], 0, DBSTAT_PAGE_PADDING_BYTES);
}
rc = sqlite3PagerGet(sqlite3BtreePager(pBt), iPg, &pDbPage, 0);