2010-02-19 07:28:08 +03:00
|
|
|
# 2010 February 18
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
|
|
|
# This file implements regression tests for SQLite library.
|
|
|
|
#
|
|
|
|
# This file implements tests to make sure SQLite does not crash or
|
|
|
|
# segfault if it sees a corrupt database file. It specifcally
|
|
|
|
# focuses on rowid order corruption.
|
|
|
|
#
|
|
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
|
|
source $testdir/tester.tcl
|
|
|
|
|
2016-03-14 20:05:04 +03:00
|
|
|
# This module uses hard-coded offsets which do not work if the reserved_bytes
|
|
|
|
# value is nonzero.
|
|
|
|
if {[nonzero_reserved_bytes]} {finish_test; return;}
|
2010-06-22 17:46:43 +04:00
|
|
|
|
2013-11-29 19:06:27 +04:00
|
|
|
# These tests deal with corrupt database files
|
|
|
|
#
|
|
|
|
database_may_be_corrupt
|
|
|
|
|
2010-04-01 22:33:14 +04:00
|
|
|
# Do not run the tests in this file if ENABLE_OVERSIZE_CELL_CHECK is on.
|
|
|
|
#
|
|
|
|
ifcapable oversize_cell_check {
|
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2010-02-19 07:28:08 +03:00
|
|
|
# Construct a compact, dense database for testing.
|
|
|
|
#
|
|
|
|
do_test corruptE-1.1 {
|
|
|
|
execsql {
|
|
|
|
PRAGMA auto_vacuum = 0;
|
|
|
|
PRAGMA legacy_file_format=1;
|
|
|
|
BEGIN;
|
|
|
|
CREATE TABLE t1(x,y);
|
|
|
|
INSERT INTO t1 VALUES(1,1);
|
|
|
|
INSERT OR IGNORE INTO t1 SELECT x*2,y FROM t1;
|
|
|
|
INSERT OR IGNORE INTO t1 SELECT x*3,y FROM t1;
|
|
|
|
INSERT OR IGNORE INTO t1 SELECT x*5,y FROM t1;
|
|
|
|
INSERT OR IGNORE INTO t1 SELECT x*7,y FROM t1;
|
|
|
|
INSERT OR IGNORE INTO t1 SELECT x*11,y FROM t1;
|
|
|
|
INSERT OR IGNORE INTO t1 SELECT x*13,y FROM t1;
|
|
|
|
INSERT OR IGNORE INTO t1 SELECT x*17,y FROM t1;
|
|
|
|
INSERT OR IGNORE INTO t1 SELECT x*19,y FROM t1;
|
|
|
|
CREATE INDEX t1i1 ON t1(x);
|
2012-09-15 22:45:54 +04:00
|
|
|
CREATE TABLE t2 AS SELECT x,2 as y FROM t1 WHERE rowid%5!=0 ORDER BY rowid;
|
2010-02-19 07:28:08 +03:00
|
|
|
COMMIT;
|
|
|
|
}
|
|
|
|
} {}
|
|
|
|
|
|
|
|
ifcapable {integrityck} {
|
|
|
|
integrity_check corruptE-1.2
|
|
|
|
}
|
|
|
|
|
|
|
|
# Setup for the tests. Make a backup copy of the good database in test.bu.
|
|
|
|
#
|
|
|
|
db close
|
2011-08-02 04:57:34 +04:00
|
|
|
forcecopy test.db test.bu
|
2010-02-19 07:28:08 +03:00
|
|
|
sqlite3 db test.db
|
|
|
|
set fsize [file size test.db]
|
|
|
|
|
|
|
|
|
|
|
|
do_test corruptE-2.1 {
|
|
|
|
db close
|
2011-08-02 04:57:34 +04:00
|
|
|
forcecopy test.bu test.db
|
2010-02-19 07:28:08 +03:00
|
|
|
|
|
|
|
# insert corrupt byte(s)
|
|
|
|
hexio_write test.db 2041 [format %02x 0x2e]
|
|
|
|
|
|
|
|
sqlite3 db test.db
|
|
|
|
|
2015-07-02 19:17:30 +03:00
|
|
|
catchsql {PRAGMA integrity_check}
|
|
|
|
} {/ out of order/}
|
2010-02-19 07:28:08 +03:00
|
|
|
|
|
|
|
do_test corruptE-2.2 {
|
|
|
|
db close
|
2011-08-02 04:57:34 +04:00
|
|
|
forcecopy test.bu test.db
|
2010-02-19 07:28:08 +03:00
|
|
|
|
|
|
|
# insert corrupt byte(s)
|
|
|
|
hexio_write test.db 2047 [format %02x 0x84]
|
|
|
|
|
|
|
|
sqlite3 db test.db
|
|
|
|
|
2015-07-02 19:17:30 +03:00
|
|
|
catchsql {PRAGMA integrity_check}
|
|
|
|
} {/ Extends off end of page/}
|
2010-02-19 07:28:08 +03:00
|
|
|
|
|
|
|
do_test corruptE-2.3 {
|
|
|
|
db close
|
2011-08-02 04:57:34 +04:00
|
|
|
forcecopy test.bu test.db
|
2010-02-19 07:28:08 +03:00
|
|
|
|
|
|
|
# insert corrupt byte(s)
|
|
|
|
hexio_write test.db 7420 [format %02x 0xa8]
|
|
|
|
hexio_write test.db 10459 [format %02x 0x8d]
|
|
|
|
|
|
|
|
sqlite3 db test.db
|
|
|
|
|
2015-07-02 19:17:30 +03:00
|
|
|
catchsql {PRAGMA integrity_check}
|
|
|
|
} {/out of order/}
|
2010-02-19 07:28:08 +03:00
|
|
|
|
|
|
|
do_test corruptE-2.4 {
|
|
|
|
db close
|
2011-08-02 04:57:34 +04:00
|
|
|
forcecopy test.bu test.db
|
2010-02-19 07:28:08 +03:00
|
|
|
|
|
|
|
# insert corrupt byte(s)
|
|
|
|
hexio_write test.db 10233 [format %02x 0xd0]
|
|
|
|
|
|
|
|
sqlite3 db test.db
|
|
|
|
|
2015-07-02 19:17:30 +03:00
|
|
|
catchsql {PRAGMA integrity_check}
|
|
|
|
} {/out of order/}
|
2010-02-19 07:28:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
set tests [list {10233 0xd0} \
|
|
|
|
{941 0x42} \
|
|
|
|
{2041 0xd0} \
|
|
|
|
{2042 0x1f} \
|
|
|
|
{2274 0x75} \
|
|
|
|
{3267 0xf2} \
|
|
|
|
{5113 0x36} \
|
|
|
|
{10233 0x84} \
|
|
|
|
{10234 0x74} \
|
|
|
|
{10239 0x41} \
|
|
|
|
{11273 0x28} \
|
|
|
|
{11461 0xe6} \
|
|
|
|
{12297 0xd7} \
|
|
|
|
{13303 0x53} ]
|
|
|
|
|
|
|
|
set tc 1
|
|
|
|
foreach test $tests {
|
|
|
|
do_test corruptE-3.$tc {
|
|
|
|
db close
|
2011-08-02 04:57:34 +04:00
|
|
|
forcecopy test.bu test.db
|
2010-02-19 07:28:08 +03:00
|
|
|
|
|
|
|
# insert corrupt byte(s)
|
|
|
|
hexio_write test.db [lindex $test 0] [format %02x [lindex $test 1]]
|
|
|
|
|
|
|
|
sqlite3 db test.db
|
|
|
|
|
2015-07-02 19:17:30 +03:00
|
|
|
catchsql {PRAGMA integrity_check}
|
|
|
|
} {/out of order/}
|
2010-02-19 07:28:08 +03:00
|
|
|
incr tc 1
|
|
|
|
}
|
|
|
|
|
|
|
|
finish_test
|