1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
# 2023 April 14
#
# 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. The
# focus of this script is testing the FTS5 module.
#
source [file join [file dirname [info script]] fts5_common.tcl]
source $testdir/malloc_common.tcl
set testprefix fts5securefault
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
return_if_no_fts5
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE t1 USING fts5(ab);
INSERT INTO t1(rowid, ab) VALUES
(0, 'abc'), (1, 'abc'), (2, 'abc'), (3, 'abc'), (4, 'def');
}
faultsim_save_and_close
do_faultsim_test 1.1 -faults oom* -prep {
faultsim_restore_and_reopen
execsql {
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
} -body {
execsql { DELETE FROM t1 WHERE rowid=2 }
} -test {
faultsim_test_result {0 {}}
}
do_faultsim_test 1.2 -faults oom* -prep {
faultsim_restore_and_reopen
execsql {
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
} -body {
execsql { DELETE FROM t1 WHERE rowid IN(0, 1, 2, 3, 4) }
} -test {
faultsim_test_result {0 {}}
}
#-------------------------------------------------------------------------
#
reset_db
set big [string repeat abcdefghij 5]
set big2 [string repeat klmnopqrst 5]
set doc "$big $big2"
do_execsql_test 2.0 {
CREATE VIRTUAL TABLE t1 USING fts5(ab);
INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
WITH s(i) AS (
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<4
)
INSERT INTO t1(rowid, ab) SELECT i, $doc FROM s;
}
faultsim_save_and_close
do_faultsim_test 2.1 -faults oom* -prep {
faultsim_restore_and_reopen
execsql {
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
} -body {
execsql { DELETE FROM t1 WHERE rowid = 3 }
execsql { DELETE FROM t1 WHERE rowid = 4 }
} -test {
faultsim_test_result {0 {}}
}
#-------------------------------------------------------------------------
#
reset_db
set big [string repeat abcdefghij 5]
set big2 [string repeat klmnopqrst 5]
set doc "$big $big2"
do_execsql_test 3.0 {
CREATE VIRTUAL TABLE t1 USING fts5(ab);
INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
WITH s(i) AS (
SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<25
)
INSERT INTO t1(rowid, ab) SELECT i, $doc FROM s;
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
DELETE FROM t1 WHERE rowid BETWEEN 3 AND 23;
}
faultsim_save_and_close
do_faultsim_test 3.1 -faults oom* -prep {
faultsim_restore_and_reopen
execsql {
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
} -body {
execsql { DELETE FROM t1 WHERE rowid = 24 }
execsql { DELETE FROM t1 WHERE rowid = 25 }
} -test {
faultsim_test_result {0 {}}
}
#-------------------------------------------------------------------------
#
reset_db
set doc [string repeat "tok " 400]
do_execsql_test 4.0 {
CREATE VIRTUAL TABLE t1 USING fts5(ab);
INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
INSERT INTO t1(rowid, ab) VALUES(1, $doc), (2, $doc), (3, $doc);
}
faultsim_save_and_close
do_faultsim_test 4.1 -faults oom* -prep {
faultsim_restore_and_reopen
execsql {
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
} -body {
execsql { DELETE FROM t1 WHERE rowid = 2 }
} -test {
faultsim_test_result {0 {}}
}
#-------------------------------------------------------------------------
#
reset_db
set doc1 [string repeat "abc " 10]
set doc2 [string repeat "def " 10]
do_test 5.0 {
execsql {
CREATE VIRTUAL TABLE t1 USING fts5(ab);
INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
BEGIN;
}
for {set i 0} {$i < 50} {incr i} {
execsql {
INSERT INTO t1(rowid, ab) VALUES($i, 'abcdefg');
}
}
execsql {
INSERT INTO t1(rowid, ab) VALUES(105, 'def');
COMMIT;
}
} {}
faultsim_save_and_close
do_faultsim_test 5.1 -faults oom* -prep {
faultsim_restore_and_reopen
execsql {
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
} -body {
execsql { DELETE FROM t1 WHERE rowid = 105 }
} -test {
faultsim_test_result {0 {}}
}
#-------------------------------------------------------------------------
#
reset_db
do_test 6.0 {
execsql {
CREATE VIRTUAL TABLE t1 USING fts5(ab);
INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
BEGIN;
INSERT INTO t1(rowid, ab) VALUES(1, 'abcdefg');
INSERT INTO t1(rowid, ab) VALUES(2, 'abcdefg');
INSERT INTO t1(rowid, ab) VALUES(3, 'abcdefg');
COMMIT;
}
} {}
faultsim_save_and_close
do_faultsim_test 6.1 -faults oom* -prep {
faultsim_restore_and_reopen
execsql {
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
} -body {
execsql {
UPDATE t1 SET ab='abcdefg' WHERE rowid=2;
}
} -test {
faultsim_test_result {0 {}}
}
#-------------------------------------------------------------------------
#
reset_db
do_test 7.0 {
execsql {
CREATE VIRTUAL TABLE t1 USING fts5(ab);
INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
} {}
faultsim_save_and_close
do_faultsim_test 7.1 -faults oom* -prep {
faultsim_restore_and_reopen
set big1 "[string repeat x 50] [string repeat y 50] [string repeat z 50]"
execsql {
BEGIN;
INSERT INTO t1 VALUES($big1);
}
} -body {
execsql { COMMIT }
} -test {
faultsim_test_result {0 {}}
}
finish_test
|