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 #*************************************************************************
12 # This file is focused on OOM errors.
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 source $testdir/malloc_common.tcl
17 set testprefix fts5faultB
19 # If SQLITE_ENABLE_FTS3 is defined, omit this file.
26 set scan(littleEndian) i*
27 set scan(bigEndian) I*
28 binary scan $blob $scan($::tcl_platform(byteOrder)) r
34 #-------------------------------------------------------------------------
35 # Errors while registering the matchinfo() demo function.
37 do_faultsim_test 1 -faults oom* -prep {
40 sqlite3_fts5_register_matchinfo db
42 faultsim_test_result {0 {}} {1 SQLITE_ERROR} {1 SQLITE_NOMEM}
46 #-------------------------------------------------------------------------
47 # Errors while executing the matchinfo() demo function.
50 sqlite3_fts5_register_matchinfo db
53 CREATE VIRTUAL TABLE t1 USING fts5(a, b);
54 INSERT INTO t1 VALUES('x y z', '1 2 3');
55 INSERT INTO t1 VALUES('x', '1 2 3 4 5 6 7');
58 do_faultsim_test 2.1 -faults oom* -body {
59 execsql { SELECT mit(matchinfo(t1, 'a')) FROM t1('x') }
61 faultsim_test_result {0 {{2 5} {2 5}}}
64 do_faultsim_test 2.2 -faults oom* -body {
65 execsql { SELECT mit(matchinfo(t1, 'l')) FROM t1('x') }
67 faultsim_test_result {0 {{3 3} {1 7}}}
71 INSERT INTO t1 VALUES('a b c d e f', 'a b d e f c');
72 INSERT INTO t1 VALUES('l m b c a', 'n o a b c z');
75 do_faultsim_test 2.4 -faults oom* -body {
76 execsql { SELECT mit(matchinfo(t1, 's')) FROM t1('a b c') }
78 faultsim_test_result {0 {{3 2} {2 3}}}
81 #-------------------------------------------------------------------------
85 CREATE VIRTUAL TABLE x1 USING fts5(z);
88 do_faultsim_test 3.1 -faults oom* -body {
90 SELECT rowid FROM x1('c') WHERE rowid>1;
93 faultsim_test_result {0 {}}
97 INSERT INTO x1 VALUES('a b c');
98 INSERT INTO x1 VALUES('b c d');
99 INSERT INTO x1 VALUES('c d e');
100 INSERT INTO x1 VALUES('d e f');
102 do_faultsim_test 3.3 -faults oom* -body {
104 SELECT rowid FROM x1('c') WHERE rowid>1;
107 faultsim_test_result {0 {2 3}}
110 #-------------------------------------------------------------------------
111 # Test OOM injection with nested colsets.
114 do_execsql_test 4.0 {
115 CREATE VIRTUAL TABLE t1 USING fts5(a, b, c, d);
116 INSERT INTO t1 VALUES('a', 'b', 'c', 'd'); -- 1
117 INSERT INTO t1 VALUES('d', 'a', 'b', 'c'); -- 2
118 INSERT INTO t1 VALUES('c', 'd', 'a', 'b'); -- 3
119 INSERT INTO t1 VALUES('b', 'c', 'd', 'a'); -- 4
121 do_faultsim_test 4.1 -faults oom* -body {
122 execsql { SELECT rowid FROM t1('{a b c} : (b:a AND c:b)'); }
124 faultsim_test_result {0 2}
127 do_faultsim_test 4.2 -faults oom* -body {
128 execsql { SELECT rowid FROM t1('{a b c} : (a AND d)') }
130 faultsim_test_result {0 {2 3}}
133 #-------------------------------------------------------------------------
134 # Test OOM injection while parsing a CARET expression
137 do_execsql_test 5.0 {
138 CREATE VIRTUAL TABLE t1 USING fts5(a);
139 INSERT INTO t1 VALUES('a b c d'); -- 1
140 INSERT INTO t1 VALUES('d a b c'); -- 2
141 INSERT INTO t1 VALUES('c d a b'); -- 3
142 INSERT INTO t1 VALUES('b c d a'); -- 4
144 do_faultsim_test 5.1 -faults oom* -body {
145 execsql { SELECT rowid FROM t1('^a OR ^b') }
147 faultsim_test_result {0 {1 4}}
150 #-------------------------------------------------------------------------
151 # Test OOM injection in a query with two MATCH expressions
154 do_execsql_test 6.0 {
155 CREATE VIRTUAL TABLE t1 USING fts5(a);
156 INSERT INTO t1 VALUES('a b c d'); -- 1
157 INSERT INTO t1 VALUES('d a b c'); -- 2
158 INSERT INTO t1 VALUES('c d a b'); -- 3
159 INSERT INTO t1 VALUES('b c d a'); -- 4
161 do_faultsim_test 6.1 -faults oom* -body {
162 execsql { SELECT rowid FROM t1 WHERE t1 MATCH 'a' AND t1 MATCH 'b' }
164 faultsim_test_result {0 {1 2 3 4}}
166 do_faultsim_test 6.2 -faults oom* -body {
167 execsql { SELECT rowid FROM t1 WHERE t1 MATCH 'a OR b' AND t1 MATCH 'c OR d' }
169 faultsim_test_result {0 {1 2 3 4}}