aboutsummaryrefslogtreecommitdiff
path: root/src/btree.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2019-01-14 05:48:10 +0000
committerdrh <drh@noemail.net>2019-01-14 05:48:10 +0000
commitd12db3dabb11873ba51e3e090e818d645c6d33d8 (patch)
tree972d8ea8fcc6e9408ea1efd656945d0996af305f /src/btree.c
parentb10a50e7f829f7038242db6f52b557e7624df412 (diff)
downloadsqlite-d12db3dabb11873ba51e3e090e818d645c6d33d8.tar.gz
sqlite-d12db3dabb11873ba51e3e090e818d645c6d33d8.zip
Avoid reading off the front of a page buffer when balancing a corrupt
btree page. FossilOrigin-Name: cb50509020d952fa9efed8df7fa08b07b71ae9bdbdefea216b6e660863291039
Diffstat (limited to 'src/btree.c')
-rw-r--r--src/btree.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/btree.c b/src/btree.c
index 6b8bb0d01..85c942d24 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -6663,9 +6663,16 @@ static void insertCell(
assert( idx >= pPage->cellOffset+2*pPage->nCell+2 || CORRUPT_DB );
assert( idx+sz <= (int)pPage->pBt->usableSize );
pPage->nFree -= (u16)(2 + sz);
- memcpy(&data[idx], pCell, sz);
if( iChild ){
+ /* In a corrupt database where an entry in the cell index section of
+ ** a btree page has a value of 3 or less, the pCell value might point
+ ** as many as 4 bytes in front of the start of the aData buffer for
+ ** the source page. Make sure this does not cause problems by not
+ ** reading the first 4 bytes */
+ memcpy(&data[idx+4], pCell+4, sz-4);
put4byte(&data[idx], iChild);
+ }else{
+ memcpy(&data[idx], pCell, sz);
}
pIns = pPage->aCellIdx + i*2;
memmove(pIns+2, pIns, 2*(pPage->nCell - i));