If a read() or pread() indicates that the database file is unreadable due to

filesystem damage, then it returns SQLITE_IOERR_CORRUPTFS which is then
converted into SQLITE_CORRUPT before being returned to the application.

FossilOrigin-Name: 849e4e14fd06eda512381f5f8aa65f75ad0a955e835da7c63526a53cf5e8f4dc
This commit is contained in:
drh
2020-11-18 23:44:41 +00:00
6 changed files with 46 additions and 20 deletions
+10 -7
View File
@@ -791,12 +791,15 @@ void sqlite3OomClear(sqlite3 *db){
}
/*
** Take actions at the end of an API call to indicate an OOM error
** Take actions at the end of an API call to deal with error codes.
*/
static SQLITE_NOINLINE int apiOomError(sqlite3 *db){
sqlite3OomClear(db);
sqlite3Error(db, SQLITE_NOMEM);
return SQLITE_NOMEM_BKPT;
static SQLITE_NOINLINE int apiHandleError(sqlite3 *db, int rc){
if( db->mallocFailed || rc==SQLITE_IOERR_NOMEM ){
sqlite3OomClear(db);
sqlite3Error(db, SQLITE_NOMEM);
return SQLITE_NOMEM_BKPT;
}
return rc & db->errMask;
}
/*
@@ -818,8 +821,8 @@ int sqlite3ApiExit(sqlite3* db, int rc){
*/
assert( db!=0 );
assert( sqlite3_mutex_held(db->mutex) );
if( db->mallocFailed || rc==SQLITE_IOERR_NOMEM ){
return apiOomError(db);
if( db->mallocFailed || rc ){
return apiHandleError(db, rc);
}
return rc & db->errMask;
}
+18 -1
View File
@@ -3375,7 +3375,24 @@ static int unixRead(
if( got==amt ){
return SQLITE_OK;
}else if( got<0 ){
/* lastErrno set by seekAndRead */
/* pFile->lastErrno has been set by seekAndRead().
** Usually we return SQLITE_IOERR_READ here, though for some
** kinds of errors we return SQLITE_IOERR_CORRUPTFS. The
** SQLITE_IOERR_CORRUPTFS will be converted into SQLITE_CORRUPT
** prior to returning to the application by the sqlite3ApiExit()
** routine.
*/
switch( pFile->lastErrno ){
case ERANGE:
case EIO:
#ifdef ENXIO
case ENXIO:
#endif
#ifdef EDEVERR
case EDEVERR:
#endif
return SQLITE_IOERR_CORRUPTFS;
}
return SQLITE_IOERR_READ;
}else{
storeLastErrno(pFile, 0); /* not a system error */
+1
View File
@@ -504,6 +504,7 @@ int sqlite3_exec(
#define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
#define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
#define SQLITE_IOERR_DATA (SQLITE_IOERR | (32<<8))
#define SQLITE_IOERR_CORRUPTFS (SQLITE_IOERR | (33<<8))
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
#define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8))
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
+5 -1
View File
@@ -8157,7 +8157,11 @@ default: { /* This is really OP_Noop, OP_Explain */
** an error of some kind.
*/
abort_due_to_error:
if( db->mallocFailed ) rc = SQLITE_NOMEM_BKPT;
if( db->mallocFailed ){
rc = SQLITE_NOMEM_BKPT;
}else if( rc==SQLITE_IOERR_CORRUPTFS ){
rc = SQLITE_CORRUPT_BKPT;
}
assert( rc );
if( p->zErrMsg==0 && rc!=SQLITE_IOERR_NOMEM ){
sqlite3VdbeError(p, "%s", sqlite3ErrStr(rc));