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
|
# 2023 April 30
#
# 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.
#
#***********************************************************************
#
source [file join [file dirname [info script]] fts5_common.tcl]
set testprefix fts5corrupt7
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
ifcapable !fts5 {
finish_test
return
}
sqlite3_fts5_may_be_corrupt 1
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE t1 USING fts5(x);
INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
}
set doc [string repeat "a b " 30]
do_execsql_test 1.1 {
BEGIN;
INSERT INTO t1(rowid, x) VALUES(123, $doc);
INSERT INTO t1(rowid, x) VALUES(124, $doc);
COMMIT;
}
execsql_pp {
SELECT id, fts5_decode(id, block), quote(block) FROM t1_data
}
set rows [db eval { SELECT rowid FROM t1_data }]
db_save_and_close
foreach r $rows {
db_restore_and_reopen
proc edit_block {b} {
binary scan $b c* in
set out [lreplace $in 0 1 255 255]
binary format c* $out
}
db func edit_block edit_block
do_execsql_test 1.2.$r.1 {
UPDATE t1_data SET block = edit_block(block) WHERE rowid=$r;
}
do_execsql_test 1.2.$r.2 {
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
do_test 1.2.$r.3 {
catchsql { DELETE FROM t1 WHERE rowid=123; }
catchsql { DELETE FROM t1 WHERE rowid=124; }
set {} {}
} {}
db close
}
foreach r $rows {
set r 137438953475
db_restore_and_reopen
proc edit_block {b} {
binary scan $b c* in
set out [lreplace $in end end 127]
binary format c* $out
}
db func edit_block edit_block
do_execsql_test 1.2.$r.1 {
UPDATE t1_data SET block = edit_block(block) WHERE rowid=$r;
}
do_execsql_test 1.2.$r.2 {
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
do_test 1.2.$r.3 {
catchsql { DELETE FROM t1 WHERE rowid=124; }
catchsql { DELETE FROM t1 WHERE rowid=123; }
set {} {}
} {}
db close
}
#-------------------------------------------------------------------------
reset_db
do_execsql_test 2.0 {
CREATE VIRTUAL TABLE t1 USING fts5(x);
BEGIN;
INSERT INTO t1 VALUES('abc');
INSERT INTO t1 VALUES('b d d d');
COMMIT;
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
}
execsql_pp {
SELECT id, quote(block) FROM t1_data
}
do_execsql_test 2.1 {
SELECT quote(block) FROM t1_data WHERE id > 10;
} {X'0000001A04306162630102020101620202020101640206030303040806'}
do_execsql_test 2.2 {
UPDATE t1_data SET
block=X'0000001A04306162630102025501620202020101640206030303040806'
WHERE id>10
}
do_catchsql_test 2.3 {
DELETE FROM t1 WHERE rowid = 1
} {1 {database disk image is malformed}}
finish_test
|