1# 2016 February 17 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 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. 9# 10#************************************************************************* 11# 12# This file is focused on OOM errors. 13# 14 15source [file join [file dirname [info script]] fts5_common.tcl] 16source $testdir/malloc_common.tcl 17set testprefix fts5faultB 18 19# If SQLITE_ENABLE_FTS3 is defined, omit this file. 20ifcapable !fts5 { 21 finish_test 22 return 23} 24 25proc mit {blob} { 26 set scan(littleEndian) i* 27 set scan(bigEndian) I* 28 binary scan $blob $scan($::tcl_platform(byteOrder)) r 29 return $r 30} 31db func mit mit 32 33 34#------------------------------------------------------------------------- 35# Errors while registering the matchinfo() demo function. 36# 37do_faultsim_test 1 -faults oom* -prep { 38 sqlite3 db test.db 39} -body { 40 sqlite3_fts5_register_matchinfo db 41} -test { 42 faultsim_test_result {0 {}} {1 SQLITE_ERROR} {1 SQLITE_NOMEM} 43} 44 45 46#------------------------------------------------------------------------- 47# Errors while executing the matchinfo() demo function. 48# 49reset_db 50sqlite3_fts5_register_matchinfo db 51db func mit mit 52do_execsql_test 2 { 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'); 56} 57 58do_faultsim_test 2.1 -faults oom* -body { 59 execsql { SELECT mit(matchinfo(t1, 'a')) FROM t1('x') } 60} -test { 61 faultsim_test_result {0 {{2 5} {2 5}}} 62} 63 64do_faultsim_test 2.2 -faults oom* -body { 65 execsql { SELECT mit(matchinfo(t1, 'l')) FROM t1('x') } 66} -test { 67 faultsim_test_result {0 {{3 3} {1 7}}} 68} 69 70do_execsql_test 2.3 { 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'); 73} 74 75do_faultsim_test 2.4 -faults oom* -body { 76 execsql { SELECT mit(matchinfo(t1, 's')) FROM t1('a b c') } 77} -test { 78 faultsim_test_result {0 {{3 2} {2 3}}} 79} 80 81#------------------------------------------------------------------------- 82# 83reset_db 84do_execsql_test 3.0 { 85 CREATE VIRTUAL TABLE x1 USING fts5(z); 86} 87 88do_faultsim_test 3.1 -faults oom* -body { 89 execsql { 90 SELECT rowid FROM x1('c') WHERE rowid>1; 91 } 92} -test { 93 faultsim_test_result {0 {}} 94} 95 96do_execsql_test 3.2 { 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'); 101} 102do_faultsim_test 3.3 -faults oom* -body { 103 execsql { 104 SELECT rowid FROM x1('c') WHERE rowid>1; 105 } 106} -test { 107 faultsim_test_result {0 {2 3}} 108} 109 110#------------------------------------------------------------------------- 111# Test OOM injection with nested colsets. 112# 113reset_db 114do_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 120} 121do_faultsim_test 4.1 -faults oom* -body { 122 execsql { SELECT rowid FROM t1('{a b c} : (b:a AND c:b)'); } 123} -test { 124 faultsim_test_result {0 2} 125} 126 127do_faultsim_test 4.2 -faults oom* -body { 128 execsql { SELECT rowid FROM t1('{a b c} : (a AND d)') } 129} -test { 130 faultsim_test_result {0 {2 3}} 131} 132 133#------------------------------------------------------------------------- 134# Test OOM injection while parsing a CARET expression 135# 136reset_db 137do_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 143} 144do_faultsim_test 5.1 -faults oom* -body { 145 execsql { SELECT rowid FROM t1('^a OR ^b') } 146} -test { 147 faultsim_test_result {0 {1 4}} 148} 149 150#------------------------------------------------------------------------- 151# Test OOM injection in a query with two MATCH expressions 152# 153reset_db 154do_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 160} 161do_faultsim_test 6.1 -faults oom* -body { 162 execsql { SELECT rowid FROM t1 WHERE t1 MATCH 'a' AND t1 MATCH 'b' } 163} -test { 164 faultsim_test_result {0 {1 2 3 4}} 165} 166do_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' } 168} -test { 169 faultsim_test_result {0 {1 2 3 4}} 170} 171 172 173finish_test 174