Skip to content

Commit 1876fe6

Browse files
committed
Revert "allow the pager to remain usable following an error occuring on a read operation"
This reverts commit e440622.
1 parent 437bb47 commit 1876fe6

2 files changed

Lines changed: 2 additions & 101 deletions

File tree

src/crypto.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -747,9 +747,9 @@ static void* sqlite3Codec(void *iCtx, void *data, Pgno pgno, int mode) {
747747
rc = SQLITE_ERROR;
748748
}
749749
#endif
750-
if(rc != SQLITE_OK) { /* clear results of failed cipher operation */
751-
/* this will be considered a temporary error condition. the pager is still usable */
750+
if(rc != SQLITE_OK) { /* clear results of failed cipher operation and set error */
752751
sqlcipher_memset((unsigned char*) buffer+offset, 0, page_sz-offset);
752+
sqlcipher_codec_ctx_set_error(ctx, rc);
753753
}
754754
memcpy(pData, buffer, page_sz); /* copy buffer data back to pData and return */
755755
return pData;
@@ -775,8 +775,6 @@ static void* sqlite3Codec(void *iCtx, void *data, Pgno pgno, int mode) {
775775
}
776776
#endif
777777
if(rc != SQLITE_OK) { /* clear results of failed cipher operation and set error */
778-
/* failure to encrypt a page is considered a permanent error and will render the pager unusable
779-
in order to prevent corrupted pages from being written to the main databased when using WAL */
780778
sqlcipher_memset((unsigned char*)buffer+offset, 0, page_sz-offset);
781779
sqlcipher_codec_ctx_set_error(ctx, rc);
782780
return NULL;

test/sqlcipher-integrity.test

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ set testdir [file dirname $argv0]
3838
source $testdir/tester.tcl
3939
source $testdir/sqlcipher.tcl
4040

41-
set old_pending_byte [sqlite3_test_control_pending_byte 0x40000000]
42-
4341
# 1. create a database and insert a bunch of data, close the database
4442
# 2. seek to the middle of the first database page and write some junk
4543
# 3. Open the database and verify that the database is no longer readable
@@ -343,99 +341,4 @@ do_test integrity-check-plaintext-header {
343341
} {{} 1 {{HMAC verification failed for page 1} {HMAC verification failed for page 2}}}
344342
file delete -force test.db
345343

346-
# verify that the default page size for the
347-
# tests is 1024 (via makefile for testfixure. If
348-
# the default pagesize is different it will breat
349-
# the following tests
350-
do_test default-page-size {
351-
sqlite_orig db test.db
352-
execsql {
353-
CREATE TABLE t1(a,b);
354-
PRAGMA page_size;
355-
}
356-
} {1024}
357-
358-
# zero out the 65th page, verify the behavior of
359-
# pragma integrity check on a plaintext database
360-
do_test integrity-check-one-page-plaintext {
361-
sqlite_orig db $sampleDir/sqlcipher-4.0-testkey.db
362-
set rc {}
363-
364-
execsql {
365-
PRAGMA key = 'testkey';
366-
ATTACH DATABASE 'plain-corrupt.db' AS plain KEY '';
367-
SELECT sqlcipher_export('plain');
368-
DETACH DATABASE plain;
369-
}
370-
371-
db close
372-
373-
set txt ""
374-
for {set i 0} {$i < 2048} {incr i} {
375-
append txt "0"
376-
}
377-
378-
hexio_write plain-corrupt.db 65536 $txt
379-
380-
sqlite_orig db plain-corrupt.db
381-
382-
set DB [sqlite3_connection_pointer db]
383-
set VM [sqlite3_prepare $DB {PRAGMA integrity_check;} -1 TAIL]
384-
while {[sqlite3_step $VM] == "SQLITE_ROW"} {
385-
lappend rc [sqlite3_column_text $VM 0]
386-
}
387-
sqlite3_finalize $VM
388-
389-
lappend rc [catchsql {
390-
PRAGMA integrity_check;
391-
}]
392-
} {{*** in database main ***
393-
Page 65: btreeInitPage() returns error code 11} {1 {database disk image is malformed}}}
394-
db close
395-
file delete -force plain-corrupt.db
396-
397-
# introduce a corruption in the 17th page then verify that
398-
# both integrity checks only reports one corrupt page
399-
# (not that all subsequent pages corrupt). Behavior of
400-
# PRAGMA integrity check should be consistent with the plaintext database
401-
# save that the page number will be different because page size for
402-
# sqlcipher is 4096 under the testfixture instead of 1024
403-
do_test version-4-integrity-check-one-page {
404-
file copy -force $sampleDir/sqlcipher-4.0-testkey.db test.db
405-
406-
set txt ""
407-
for {set i 0} {$i < 8192} {incr i} {
408-
append txt "0"
409-
}
410-
411-
hexio_write test.db 65536 $txt
412-
413-
sqlite_orig db test.db
414-
set rc {}
415-
lappend rc [
416-
execsql {
417-
PRAGMA key = 'testkey';
418-
PRAGMA cipher_integrity_check;
419-
}
420-
]
421-
422-
set DB [sqlite3_connection_pointer db]
423-
set VM [sqlite3_prepare $DB {PRAGMA integrity_check;} -1 TAIL]
424-
while {[sqlite3_step $VM] == "SQLITE_ROW"} {
425-
lappend rc [sqlite3_column_text $VM 0]
426-
}
427-
sqlite3_finalize $VM
428-
429-
lappend rc [
430-
catchsql {
431-
PRAGMA integrity_check;
432-
}
433-
]
434-
} {{ok {HMAC verification failed for page 17}} {*** in database main ***
435-
Page 17: btreeInitPage() returns error code 11} {1 {database disk image is malformed}}}
436-
db close
437-
file delete -force test.db
438-
439-
sqlite3_test_control_pending_byte $old_pending_byte
440-
441344
finish_test

0 commit comments

Comments
 (0)