mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Fix some trivial cases where database corruption was causing an error code other than SQLITE_CORRUPT to be returned. (CVS 5690)
FossilOrigin-Name: 89fda074f6b4959c32f1083badba3c73cffb4995
This commit is contained in:
28
src/btree.c
28
src/btree.c
@@ -9,7 +9,7 @@
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** $Id: btree.c,v 1.510 2008/09/10 14:45:58 danielk1977 Exp $
|
||||
** $Id: btree.c,v 1.511 2008/09/10 17:53:36 danielk1977 Exp $
|
||||
**
|
||||
** This file implements a external (disk-based) database using BTrees.
|
||||
** See the header comment on "btreeInt.h" for additional information.
|
||||
@@ -1085,6 +1085,17 @@ int sqlite3BtreeGetPage(
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the size of the database file in pages. Or return -1 if
|
||||
** there is any kind of error.
|
||||
*/
|
||||
static int pagerPagecount(Pager *pPager){
|
||||
int rc;
|
||||
int nPage;
|
||||
rc = sqlite3PagerPagecount(pPager, &nPage);
|
||||
return (rc==SQLITE_OK?nPage:-1);
|
||||
}
|
||||
|
||||
/*
|
||||
** Get a page from the pager and initialize it. This routine
|
||||
** is just a convenience wrapper around separate calls to
|
||||
@@ -1099,7 +1110,7 @@ static int getAndInitPage(
|
||||
int rc;
|
||||
assert( sqlite3_mutex_held(pBt->mutex) );
|
||||
assert( !pParent || pParent->isInit );
|
||||
if( pgno==0 ){
|
||||
if( pgno==0 || pgno>pagerPagecount(pBt->pPager) ){
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
rc = sqlite3BtreeGetPage(pBt, pgno, ppPage, 0);
|
||||
@@ -2029,17 +2040,6 @@ trans_begun:
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the size of the database file in pages. Or return -1 if
|
||||
** there is any kind of error.
|
||||
*/
|
||||
static int pagerPagecount(Pager *pPager){
|
||||
int rc;
|
||||
int nPage;
|
||||
rc = sqlite3PagerPagecount(pPager, &nPage);
|
||||
return (rc==SQLITE_OK?nPage:-1);
|
||||
}
|
||||
|
||||
|
||||
#ifndef SQLITE_OMIT_AUTOVACUUM
|
||||
|
||||
@@ -3184,7 +3184,7 @@ static int accessPayload(
|
||||
}
|
||||
if( offset+amt > nKey+pCur->info.nData ){
|
||||
/* Trying to read or write past the end of the data is an error */
|
||||
return SQLITE_ERROR;
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
}
|
||||
|
||||
/* Check if data must be read/written to/from the btree page itself. */
|
||||
|
Reference in New Issue
Block a user