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
commit 02e4b7d7df
6 changed files with 46 additions and 20 deletions

View File

@ -1,5 +1,5 @@
C Update\scksumvfs.c\sso\sthat\sif\sSQLITE_AMALGAMATION\sis\sdefined,\sSQLITE_CKSUMVFS_STATIC\sis\simplied.
D 2020-11-18T20:55:01.090
C If\sa\sread()\sor\spread()\sindicates\sthat\sthe\sdatabase\sfile\sis\sunreadable\sdue\sto\nfilesystem\sdamage,\sthen\sit\sreturns\sSQLITE_IOERR_CORRUPTFS\swhich\sis\sthen\nconverted\sinto\sSQLITE_CORRUPT\sbefore\sbeing\sreturned\sto\sthe\sapplication.
D 2020-11-18T23:44:41.584
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -503,7 +503,7 @@ F src/insert.c 7e081d33aab4a9d761c39dccf3c3872c35501565d2ed9db66301918d23bc7901
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c 436af4968c6954d304fce9efa12719367bd8f37b19b93b71d6ad607e85adbb47
F src/main.c 54d61d1e94f225636053c862c930d7dd7b29162b93d3f3ecb00439910ccba02a
F src/malloc.c 413b0ffea2b45c37c6cf2ed5509f6d6b508b0a033caa9b4bf90bed4ee044a2ff
F src/malloc.c c1af4ac5a463648cd2953fd4ac679b3ba9022ce5ec794a60806150ad69dfd33a
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c c12a42539b1ba105e3707d0e628ad70e611040d8f5e38cf942cee30c867083de
F src/mem2.c b93b8762ab999a29ae7751532dadf0a1ac78040308a5fb1d17fcc365171d67eb
@ -522,7 +522,7 @@ F src/os.c 80e4cf3e5da06be03ca641661e331ce60eeeeabf0d7354dbb1c0e166d0eedbbe
F src/os.h 48388821692e87da174ea198bf96b1b2d9d83be5dfc908f673ee21fafbe0d432
F src/os_common.h b2f4707a603e36811d9b1a13278bffd757857b85
F src/os_setup.h 0dbaea40a7d36bf311613d31342e0b99e2536586
F src/os_unix.c ff10667369f3b05aa697278a72d58fe7a43aaa674cb3fa9654d0fe21cda265d0
F src/os_unix.c c19f392825f4787dbdff2637371ba2210eef8aecfc268509c7aafa9beea3a653
F src/os_win.c 77d39873836f1831a9b0b91894fec45ab0e9ca8e067dc8c549e1d1eca1566fe9
F src/os_win.h 7b073010f1451abe501be30d12f6bc599824944a
F src/pager.c 3700a1c55427a3d4168ad1f1b8a8b0cb9ace1d107e4506e30a8f1e66d8a1195e
@ -540,7 +540,7 @@ F src/resolve.c 1948a92ca9eab776632816b97e57c61d933474a78aad4f4ef835c916a83dbb1c
F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
F src/select.c 31387e56f5e6d1adc798dfa04b946001289a61e65acf4615f7b7130f121f3b9c
F src/shell.c.in 2871f579186e71db54cdf6b262951d2cd88aa61747a3f3e745ade425268fd6f6
F src/sqlite.h.in ff32663b457306eb88c3039868280aa39da31162ed69c4e71fa8e028684e7277
F src/sqlite.h.in 70a0c35d729f16e9b57d29e371f2f090c3fda1d0e007df0c446df5560710dd40
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 2d1af80082edffd71c6f96f70ad1ce6a4fb46615ad10291fc77fe0dea9ff0197
F src/sqliteInt.h c01115c8dd967f7d334a98ba37ac821eafb04144c8085a795daaf2185743d27a
@ -610,7 +610,7 @@ F src/upsert.c 2920de71b20f04fe25eb00b655d086f0ba60ea133c59d7fa3325c49838818e78
F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0
F src/util.c c0c7977de7ef9b8cb10f6c85f2d0557889a658f817b0455909a49179ba4c8002
F src/vacuum.c 492422c1463c076473bae1858799c7a0a5fe87a133d1223239447c422cd26286
F src/vdbe.c 6f3fb4f058c478b38c5280ccfc939745076c6a693999e49846c99fdc761c9c90
F src/vdbe.c 0f4402a3f8ab7d7f37fbed04d74007f978805aa6ca09738606331e0dc7b2b614
F src/vdbe.h 83603854bfa5851af601fc0947671eb260f4363e62e960e8a994fb9bbcd2aaa1
F src/vdbeInt.h 3ca5e9fd6e095a8b6cf6bc3587a46fc93499503b2fe48951e1034ba9e2ce2f6e
F src/vdbeapi.c c5e7cb2ab89a24d7f723e87b508f21bfb1359a04db5277d8a99fd1e015c12eb9
@ -1885,7 +1885,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 43d4801df5dc4625f6829ed8246758493842b2416ba609ee0423ef63155cece2
R 819b2a35faf033f5ae6dd8bf0e39c618
U dan
Z 008d2a9a3f8427ff308e19cdcb995f1d
P 184e9d782dfbad8011b5b0043b3fd8e5a369ed7076e37e14b301483ce5ffe5db b887c7504e7edeba758f3c1203c6cc56eef499fe05e7e6c6d82939bf7d78c57f
R ca853ae029f53cda2f5e4e09a853497d
T +closed b887c7504e7edeba758f3c1203c6cc56eef499fe05e7e6c6d82939bf7d78c57f
U drh
Z 9d8b812fa0a6ee7104c4c9d6ceb68cc7

View File

@ -1 +1 @@
184e9d782dfbad8011b5b0043b3fd8e5a369ed7076e37e14b301483ce5ffe5db
849e4e14fd06eda512381f5f8aa65f75ad0a955e835da7c63526a53cf5e8f4dc

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;
}

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 */

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))

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));