| 1 |
# 2023 April 30 |
| 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 |
|
| 13 |
source [file join [file dirname [info script]] fts5_common.tcl] |
| 14 |
set testprefix fts5corrupt7 |
| 15 |
|
| 16 |
# If SQLITE_ENABLE_FTS5 is defined, omit this file. |
| 17 |
ifcapable !fts5 { |
| 18 |
finish_test |
| 19 |
return |
| 20 |
} |
| 21 |
sqlite3_fts5_may_be_corrupt 1 |
| 22 |
|
| 23 |
do_execsql_test 1.0 { |
| 24 |
CREATE VIRTUAL TABLE t1 USING fts5(x); |
| 25 |
INSERT INTO t1(t1, rank) VALUES('pgsz', 32); |
| 26 |
} |
| 27 |
|
| 28 |
set doc [string repeat "a b " 30] |
| 29 |
|
| 30 |
do_execsql_test 1.1 { |
| 31 |
BEGIN; |
| 32 |
INSERT INTO t1(rowid, x) VALUES(123, $doc); |
| 33 |
INSERT INTO t1(rowid, x) VALUES(124, $doc); |
| 34 |
COMMIT; |
| 35 |
} |
| 36 |
|
| 37 |
execsql_pp { |
| 38 |
SELECT id, fts5_decode(id, block), quote(block) FROM t1_data |
| 39 |
} |
| 40 |
|
| 41 |
set rows [db eval { SELECT rowid FROM t1_data }] |
| 42 |
db_save_and_close |
| 43 |
|
| 44 |
foreach r $rows { |
| 45 |
db_restore_and_reopen |
| 46 |
|
| 47 |
proc edit_block {b} { |
| 48 |
binary scan $b c* in |
| 49 |
set out [lreplace $in 0 1 255 255] |
| 50 |
binary format c* $out |
| 51 |
} |
| 52 |
db func edit_block edit_block |
| 53 |
|
| 54 |
do_execsql_test 1.2.$r.1 { |
| 55 |
UPDATE t1_data SET block = edit_block(block) WHERE rowid=$r; |
| 56 |
} |
| 57 |
|
| 58 |
do_execsql_test 1.2.$r.2 { |
| 59 |
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1); |
| 60 |
} |
| 61 |
|
| 62 |
do_test 1.2.$r.3 { |
| 63 |
catchsql { DELETE FROM t1 WHERE rowid=123; } |
| 64 |
catchsql { DELETE FROM t1 WHERE rowid=124; } |
| 65 |
set {} {} |
| 66 |
} {} |
| 67 |
|
| 68 |
db close |
| 69 |
} |
| 70 |
|
| 71 |
foreach r $rows { |
| 72 |
set r 137438953475 |
| 73 |
db_restore_and_reopen |
| 74 |
|
| 75 |
proc edit_block {b} { |
| 76 |
binary scan $b c* in |
| 77 |
set out [lreplace $in end end 127] |
| 78 |
binary format c* $out |
| 79 |
} |
| 80 |
db func edit_block edit_block |
| 81 |
|
| 82 |
do_execsql_test 1.2.$r.1 { |
| 83 |
UPDATE t1_data SET block = edit_block(block) WHERE rowid=$r; |
| 84 |
} |
| 85 |
|
| 86 |
do_execsql_test 1.2.$r.2 { |
| 87 |
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1); |
| 88 |
} |
| 89 |
|
| 90 |
do_test 1.2.$r.3 { |
| 91 |
catchsql { DELETE FROM t1 WHERE rowid=124; } |
| 92 |
catchsql { DELETE FROM t1 WHERE rowid=123; } |
| 93 |
set {} {} |
| 94 |
} {} |
| 95 |
|
| 96 |
db close |
| 97 |
} |
| 98 |
|
| 99 |
#------------------------------------------------------------------------- |
| 100 |
reset_db |
| 101 |
do_execsql_test 2.0 { |
| 102 |
CREATE VIRTUAL TABLE t1 USING fts5(x); |
| 103 |
BEGIN; |
| 104 |
INSERT INTO t1 VALUES('abc'); |
| 105 |
INSERT INTO t1 VALUES('b d d d'); |
| 106 |
COMMIT; |
| 107 |
INSERT INTO t1(t1, rank) VALUES('secure-delete', 1); |
| 108 |
} |
| 109 |
|
| 110 |
execsql_pp { |
| 111 |
SELECT id, quote(block) FROM t1_data |
| 112 |
} |
| 113 |
|
| 114 |
do_execsql_test 2.1 { |
| 115 |
SELECT quote(block) FROM t1_data WHERE id > 10; |
| 116 |
} {X'0000001A04306162630102020101620202020101640206030303040806'} |
| 117 |
|
| 118 |
do_execsql_test 2.2 { |
| 119 |
UPDATE t1_data SET |
| 120 |
block=X'0000001A04306162630102025501620202020101640206030303040806' |
| 121 |
WHERE id>10 |
| 122 |
} |
| 123 |
|
| 124 |
do_catchsql_test 2.3 { |
| 125 |
DELETE FROM t1 WHERE rowid = 1 |
| 126 |
} {1 {database disk image is malformed}} |
| 127 |
|
| 128 |
finish_test |