797f3ee87c
FossilOrigin-Name: 252f0e457d3e33404df87d3e6c44ede61b78319c
96 lines
2.6 KiB
Plaintext
96 lines
2.6 KiB
Plaintext
# 2010 October 27
|
|
#
|
|
# 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.
|
|
#
|
|
#***********************************************************************
|
|
# Test that the FTS3 extension does not crash when it encounters a
|
|
# corrupt data structure on disk.
|
|
#
|
|
|
|
|
|
set testdir [file dirname $argv0]
|
|
source $testdir/tester.tcl
|
|
|
|
# If SQLITE_ENABLE_FTS3 is not defined, omit this file.
|
|
ifcapable !fts3 { finish_test ; return }
|
|
|
|
set ::testprefix fts3corrupt
|
|
|
|
|
|
# Test that a doclist with a length field that indicates that the doclist
|
|
# extends past the end of the node on which it resides is correctly identified
|
|
# as database corruption.
|
|
#
|
|
do_execsql_test 1.0 {
|
|
CREATE VIRTUAL TABLE t1 USING fts3;
|
|
INSERT INTO t1 VALUES('hello');
|
|
} {}
|
|
do_test fts3corrupt-1.1 {
|
|
set blob [db one {SELECT root from t1_segdir}]
|
|
set blob [binary format a7ca* $blob 24 [string range $blob 8 end]]
|
|
execsql { UPDATE t1_segdir SET root = $blob }
|
|
} {}
|
|
do_test fts3corrupt-1.2 {
|
|
foreach w {a b c d e f g h i j k l m n o} {
|
|
execsql { INSERT INTO t1 VALUES($w) }
|
|
}
|
|
} {}
|
|
do_catchsql_test 1.3 {
|
|
INSERT INTO t1 VALUES('world');
|
|
} {1 {database disk image is malformed}}
|
|
do_execsql_test 1.4 {
|
|
DROP TABLE t1;
|
|
}
|
|
|
|
# This block of tests checks that corruption is correctly detected if the
|
|
# length field of a term on a leaf node indicates that the term extends past
|
|
# the end of the node on which it resides. There are two cases:
|
|
#
|
|
# 1. The first term on the node.
|
|
# 2. The second or subsequent term on the node (prefix compressed term).
|
|
#
|
|
do_execsql_test 2.0 {
|
|
CREATE VIRTUAL TABLE t1 USING fts3;
|
|
BEGIN;
|
|
INSERT INTO t1 VALUES('hello');
|
|
INSERT INTO t1 VALUES('hello');
|
|
INSERT INTO t1 VALUES('hello');
|
|
INSERT INTO t1 VALUES('hello');
|
|
INSERT INTO t1 VALUES('hello');
|
|
COMMIT;
|
|
} {}
|
|
do_test fts3corrupt-2.1 {
|
|
set blob [db one {SELECT root from t1_segdir}]
|
|
set blob [binary format a*a* "\x00\x7F" [string range $blob 2 end]]
|
|
execsql { UPDATE t1_segdir SET root = $blob }
|
|
} {}
|
|
do_catchsql_test 2.2 {
|
|
SELECT rowid FROM t1 WHERE t1 MATCH 'hello'
|
|
} {1 {database disk image is malformed}}
|
|
|
|
do_execsql_test 3.0 {
|
|
DROP TABLE t1;
|
|
CREATE VIRTUAL TABLE t1 USING fts3;
|
|
BEGIN;
|
|
INSERT INTO t1 VALUES('hello');
|
|
INSERT INTO t1 VALUES('world');
|
|
COMMIT;
|
|
} {}
|
|
do_test fts3corrupt-3.1 {
|
|
set blob [db one {SELECT quote(root) from t1_segdir}]
|
|
set blob [binary format a11a*a* $blob "\x7F" [string range $blob 12 end]]
|
|
execsql { UPDATE t1_segdir SET root = $blob }
|
|
} {}
|
|
do_catchsql_test 3.2 {
|
|
SELECT rowid FROM t1 WHERE t1 MATCH 'world'
|
|
} {1 {database disk image is malformed}}
|
|
|
|
|
|
|
|
|
|
|
|
finish_test
|
|
|