Fix a case where a corrupt stat4 record could go unrecognized due to integer overflow.
[sqlite.git] / test / fts4record.test
blobf1a3eafa75db5ede51868922154298a2a2fb90a2
1 # 2019 September 18
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
6 #    May you do good and not evil.
7 #    May you find forgiveness for yourself and forgive others.
8 #    May you share freely, never taking more than you give.
10 #*************************************************************************
11 # This file implements regression tests for SQLite library.  The
12 # focus of this script is testing the FTS4 module.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 source $testdir/fts3_common.tcl
19 set testprefix fts4record
21 # If SQLITE_ENABLE_FTS3 is defined, omit this file.
22 ifcapable !fts3 {
23   finish_test
24   return
27 sqlite3_fts3_may_be_corrupt 1
29 do_execsql_test 1.0 {
30   CREATE VIRTUAL TABLE t1 USING fts4(x);
31   INSERT INTO t1 VALUES('terma terma terma termb');
34 do_execsql_test 1.1 {
35   SELECT quote(root) FROM t1_segdir
36 } {
37   X'00057465726D6105010203030004016203010500'
40 proc make_record_wrapper {args} { make_fts3record $args }
41 db func record make_record_wrapper
43 do_execsql_test 1.2 {
44   select quote( 
45     record(0,    5, 'terma', 5, 1, 2, 3, 3, 0, 
46               4, 1, 'b'    , 3, 1, 5, 0
47   ) );
48 } {
49   X'00057465726D6105010203030004016203010500'
52 do_execsql_test 1.3.1 {
53   UPDATE t1_segdir SET root = 
54     record(0,    5, 'terma', 5, 1, 2, 3, 3, 0, 
55               4, 1, 'b'    , 3, 1, 5, 
56               1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
57               1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
58               1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
59           );
62 do_catchsql_test 1.3.2 {
63   SELECT snippet(t1) FROM t1 WHERE t1 MATCH 'term*'
64 } {1 {database disk image is malformed}}
66 do_execsql_test 1.4.1 {
67   UPDATE t1_segdir SET root = 
68     record(0,    5, 'terma', 5, 1, 2, 3, 3, 0, 
69               4, 1, 'b'    , 4, 1, 5, 
70               256, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
71               1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
72               1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
73           );
76 do_catchsql_test 1.4.2 {
77   SELECT snippet(t1) FROM t1 WHERE t1 MATCH 'term*'
78 } {1 {database disk image is malformed}}
80 do_execsql_test 1.4.3 {
81   SELECT quote(root) FROM t1_segdir
82 } {
83   X'00057465726D610501020303000401620401058002010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100'
86 do_execsql_test 1.5.1 {
87   UPDATE t1_segdir SET root = 
88     record(0,    5, 'terma', 5, 1, 2, 3, 3, 0, 
89               4, 1, 'b'    , 4, 1, 5, 
90               256, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
91               1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
92               1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0
93           );
96 do_catchsql_test 1.4.2 {
97   SELECT snippet(t1) FROM t1 WHERE t1 MATCH 'term*'
98 } {1 {database disk image is malformed}}
100 do_execsql_test 1.4.3 {
101   SELECT quote(root) FROM t1_segdir
102 } {
103   X'00057465726D610501020303000401620401058002010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100'
107 do_execsql_test 1.5.1 {
108   UPDATE t1_segdir SET root = 
109   X'00057465726D61050102030300040162040105FF00010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010100'
112 do_catchsql_test 1.5.2 {
113   SELECT snippet(t1) FROM t1 WHERE t1 MATCH 'term*'
114 } {1 {database disk image is malformed}}
116 do_catchsql_test 1.5.3 {
117   INSERT INTO t1(t1) VALUES('integrity-check');
118 } {1 {database disk image is malformed}}
120 finish_test