From: drh Date: Mon, 12 Dec 2016 01:30:01 +0000 (+0000) Subject: Size and performance optimization in btreeInitPage() in the freeblock X-Git-Tag: version-3.16.0~55 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=77dc0ed621b8b6cef0ad6a3c666f007c9750545d;p=thirdparty%2Fsqlite.git Size and performance optimization in btreeInitPage() in the freeblock validation step. FossilOrigin-Name: 57deb1b412e0c328528f2b4d697e326bfd028dca --- diff --git a/manifest b/manifest index 063b4151ee..3452a6cb53 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sorder\sof\scomparison\sfor\sdivider\scell\soverflow\sin\sbalance\snon-root\nto\savoid\sa\s(harmless)\sreference\sto\san\suninitialized\svariable. -D 2016-12-12T00:58:40.524 +C Size\sand\sperformance\soptimization\sin\sbtreeInitPage()\sin\sthe\sfreeblock\nvalidation\sstep. +D 2016-12-12T01:30:01.538 F Makefile.in 7639c6a09da11a9c7c6f2630fc981ee588d1072d F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da @@ -331,7 +331,7 @@ F src/auth.c 930b376a9c56998557367e6f7f8aaeac82a2a792 F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33 F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73 -F src/btree.c 5299b39ca2ae3a177aa4f10c32adecb6ae3dfb2e +F src/btree.c 383ce69bd36b0f409bfb8bd028786b2f0a4cbb24 F src/btree.h 2349a588abcd7e0c04f984e15c5c777b61637583 F src/btreeInt.h 10c4b77c2fb399580babbcc7cf652ac10dba796e F src/build.c 178f16698cbcb43402c343a9413fe22c99ffee21 @@ -1536,7 +1536,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 35ecd4ebc55579175f7c934e4eb1edb969008428 -R 4eec70a8d01ab30e743f435be503a7d5 +P f9f2e23bbd68a8994621623446868d666df52eff +R d6e7ff9713db8a1c5bca23b53d1ed305 U drh -Z 5a1985fcb882d74ad54a7fce35ec702f +Z a7e99aa30e3b05522d980cd982791774 diff --git a/manifest.uuid b/manifest.uuid index 614c1437a0..31c04846da 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f9f2e23bbd68a8994621623446868d666df52eff \ No newline at end of file +57deb1b412e0c328528f2b4d697e326bfd028dca \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 4598c624dd..a6a8a4782a 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1743,7 +1743,7 @@ static int btreeInitPage(MemPage *pPage){ assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) ); if( !pPage->isInit ){ - u16 pc; /* Address of a freeblock within pPage->aData[] */ + u32 pc; /* Address of a freeblock within pPage->aData[] */ u8 hdr; /* Offset to beginning of page header */ u8 *data; /* Equal to pPage->aData */ BtShared *pBt; /* The main btree structure */ @@ -1823,25 +1823,30 @@ static int btreeInitPage(MemPage *pPage){ ** freeblocks. */ pc = get2byte(&data[hdr+1]); nFree = data[hdr+7] + top; /* Init nFree to non-freeblock free space */ - while( pc>0 ){ - u16 next, size; - if( pciCellLast ){ + if( pc>0 ){ + u32 next, size; + if( pc0 && next<=pc+size+3) || pc+size>usableSize ){ - /* Free blocks must be in ascending order. And the last byte of - ** the free-block must lie on the database page. */ - return SQLITE_CORRUPT_BKPT; + while( 1 ){ + if( pc>iCellLast ){ + return SQLITE_CORRUPT_BKPT; /* Freeblock off the end of the page */ + } + next = get2byte(&data[pc]); + size = get2byte(&data[pc+2]); + nFree = nFree + size; + if( next<=pc+size+3 ) break; + pc = next; + } + if( next>0 ){ + return SQLITE_CORRUPT_BKPT; /* Freeblock not in ascending order */ + } + if( pc+size>usableSize ){ + return SQLITE_CORRUPT_BKPT; /* Last freeblock extends past page end */ } - nFree = nFree + size; - pc = next; } /* At this point, nFree contains the sum of the offset to the start