1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

Early detection of implausibly sized records to avoid unnecessary

large memory allocations.

FossilOrigin-Name: 2c8769c69f301307db6663adb8b7c0b89f5959516bf6110cb8ff4b21bd903f70
This commit is contained in:
drh
2019-02-04 21:10:24 +00:00
parent af48257bc9
commit 53d30dd371
5 changed files with 32 additions and 9 deletions

View File

@@ -4519,6 +4519,25 @@ u32 sqlite3BtreePayloadSize(BtCursor *pCur){
return pCur->info.nPayload;
}
/*
** Return an upper bound on the size of any record for the table
** that the cursor is pointing into.
**
** This is an optimization. Everything will still work if this
** routine always returns 2147483647 (which is the largest record
** that SQLite can handle) or more. But returning a smaller value might
** prevent large memory allocations when trying to interpret a
** corrupt datrabase.
**
** The current implementation merely returns the size of the underlying
** database file.
*/
sqlite3_int64 sqlite3BtreeMaxRecordSize(BtCursor *pCur){
assert( cursorHoldsMutex(pCur) );
assert( pCur->eState==CURSOR_VALID );
return pCur->pBt->pageSize * (sqlite3_int64)pCur->pBt->nPage;
}
/*
** Given the page number of an overflow page in the database (parameter
** ovfl), this function finds the page number of the next page in the