Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Unified Diff: third_party/sqlite/amalgamation/sqlite3.c

Issue 343423004: [sql] Prevent nChildren overrun decoding interior pages in recover.c. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
Download patch
« no previous file with comments | « no previous file | third_party/sqlite/src/src/recover.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/sqlite/amalgamation/sqlite3.c
diff --git a/third_party/sqlite/amalgamation/sqlite3.c b/third_party/sqlite/amalgamation/sqlite3.c
index c0315fffb7d828b45e93e136db72b5e4c4a4d34a..81506c1fc4301590f23c2a1edb4da4911f71d6b9 100644
--- a/third_party/sqlite/amalgamation/sqlite3.c
+++ b/third_party/sqlite/amalgamation/sqlite3.c
@@ -110899,12 +110899,22 @@ static void interiorCursorSetPage(RecoverInteriorCursor *pCursor,
pCursor->iChild = 0;
/* A child for each cell, plus one in the header. */
- /* TODO(shess): Sanity-check the count? Page header plus per-cell
- * cost of 16-bit offset, 32-bit page number, and one varint
- * (minimum 1 byte).
- */
pCursor->nChildren = decodeUnsigned16(PageHeader(pPage) +
kiPageCellCountOffset) + 1;
+
+ /* The maximum possible value for nChildren is:
+ * (nPageSize - kiPageInteriorHeaderBytes) /
+ * (sizeof(uint16) + sizeof(uint32) + 1) + 1
+ * Each child requires a 16-bit offset from an array after the header, and
+ * each child contains a 32-bit page number and at least a varint (min size of
+ * one byte). The final child page is in the header.
+ */
+ const unsigned knMinCellLength = 2 + 4 + 1;
+ unsigned nMaxChildren =
+ (pCursor->nPageSize - kiPageInteriorHeaderBytes) / knMinCellLength + 1;
+ if (pCursor->nChildren > nMaxChildren) {
+ pCursor->nChildren = nMaxChildren;
+ }
}
static int interiorCursorCreate(RecoverInteriorCursor *pParent,
« no previous file with comments | « no previous file | third_party/sqlite/src/src/recover.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698