Skip to content

Commit ece125f

Browse files
committed
Fix issue #18
Multiple calls to sqlite3_key/sqlite3_key_v2 with invalid key values could cause inconsistent error messages; a subsequent call with a valid key failed due to the pager still being in an error state. This has been fixed.
1 parent 3fa3256 commit ece125f

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

src/cipher_chacha20.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ DecryptPageChaCha20Cipher(void* cipher, int page, unsigned char* data, int len,
302302
/* Check whether number of required reserved bytes and actually reserved bytes match */
303303
if ((legacy == 0 && nReserved > reserved) || ((legacy != 0 && nReserved != reserved)))
304304
{
305-
return SQLITE_CORRUPT;
305+
return (page == 1) ? SQLITE_NOTADB : SQLITE_CORRUPT;
306306
}
307307

308308
if (nReserved > 0)
@@ -333,7 +333,7 @@ DecryptPageChaCha20Cipher(void* cipher, int page, unsigned char* data, int len,
333333
SQLITE3MC_DEBUG_HEX("decrypt tag r:", data + n + PAGE_NONCE_LEN_CHACHA20, PAGE_TAG_LEN_CHACHA20);
334334
SQLITE3MC_DEBUG_HEX("decrypt tag c:", tag, PAGE_TAG_LEN_CHACHA20);
335335
/* Bad MAC */
336-
rc = SQLITE_CORRUPT;
336+
rc = (page == 1) ? SQLITE_NOTADB : SQLITE_CORRUPT;
337337
}
338338
}
339339
if (page == 1 && rc == SQLITE_OK)

src/cipher_sqlcipher.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ DecryptPageSQLCipherCipher(void* cipher, int page, unsigned char* data, int len,
442442
/* Check whether number of required reserved bytes and actually reserved bytes match */
443443
if ((legacy == 0 && nReserved > reserved) || ((legacy != 0 && nReserved != reserved)))
444444
{
445-
return SQLITE_CORRUPT;
445+
return (page == 1) ? SQLITE_NOTADB : SQLITE_CORRUPT;
446446
}
447447

448448
/* Get nonce from buffer */
@@ -493,7 +493,7 @@ DecryptPageSQLCipherCipher(void* cipher, int page, unsigned char* data, int len,
493493
else
494494
{
495495
/* Bad MAC */
496-
rc = SQLITE_CORRUPT;
496+
rc = (page == 1) ? SQLITE_NOTADB : SQLITE_CORRUPT;
497497
}
498498

499499
return rc;

src/sqlite3mc_vfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ SQLITE_PRIVATE void sqlite3mcSetCodec(sqlite3* db, const char* zFileName, Codec*
252252
sqlite3mcCodecFree(pDbMain->codec);
253253
}
254254
pDbMain->codec = codec;
255+
mcReportCodecError(sqlite3mcGetBtShared(codec), SQLITE_OK);
255256
}
256257
else
257258
{

0 commit comments

Comments
 (0)