blob: 58643534f1a8df20df79acf916734c10be13cf8b (
plain)
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
|
# 2010 October 30
#
# 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.
#
#***********************************************************************
# Test that the FTS3 extension does not crash when it encounters a
# corrupt data structure on disk.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# If SQLITE_ENABLE_FTS3 is not defined, omit this file.
ifcapable !fts3 { finish_test ; return }
set ::testprefix fts3corrupt2
sqlite3_fts3_may_be_corrupt 1
set data [list]
lappend data {*}{
"amxtvoo adqwroyhz auq aithtir avniqnuynvf axp ahibayfynig agbicpm"
"ajdtebs anteaxr aieynenwmd awpl alo akxcrwow aoxftge aoqvgul"
"amcfvdr auz apu aebelm ahuxyz aqc asyafdb agulvhvqu"
"apepwfyz azkhdvkw aenyelxzbk aslnitbyet aycdsdcpgr aqzzdbc agfi axnypydou"
"aaqrzzcm apcxdxo atumltzj aevvivo aodknoft aqoyytoz alobx apldt"
"adjllxlhnmj aiuhvuj adwppceuht atvj azrsam ahkjqdhny audlqxr aotgcd"
"aira azflsceos awj auzbobfkc awmezplr aeh awec ahndxlmv"
"aydwnied alk auoap agihyqeix aymqxzajnl aydwnied aojkarx agbo"
"ahajsmcl anvx amdhjm aoptsj agugzjjm apkevm acnj acjg"
"amwtkw aogttbykvt aubwrfqnbjf ajow agsj aerkqzjdqst anenlvbalkn arfajzzgckx"
"adqqqofkmz amjpavjuhw aqgehgnb awvvxlbtqzn agstqko akmkzehyh atagzey agwja"
"amag ahe autkllywhr avnk atmt akn anvdh aixfrv"
"aqdyerbws avefykly awl azaduojgzo anxfsmw axpt abgbvk ati"
"attyqkwz aiweypiczul afy asitaqbczhh aitxisizpv auhviq aibql ajfqc"
"aylzprtmta aiuemihqrpi awluvgsw ampbuy axlifpzfqr aems aoaxwads apianfn"
"aodrkijelq acdb aaserrdxm aqyasgofqu aevvivo afi apmwu aeoqysl"
"amqnk ankaotm ayfy ajcupeeoc advcbukan aucahlwnyk adbfyo azqjpeant"
"afczpp asqrs ahslvda akhlf aiqgdp atyd aznuglxqbrg awirndrh"
"aqhiajp amxeazb asxuehg akod axvolvsp agcz asmovmohy acmqa"
"avvomv aafms ashuaec arevx audtq alrwqhjvao avgsgpg ajbrctpsel"
"atxoirr ayopboobqdu ajunntua arh aernimxid aipljda aglo aefk"
"aonxf acmnnkna abgviaswe aulvcbv axp apemgakpzo aibql acioaid"
"axo alrwqhjvao ayqounftdzl azmoakdyh apajze ajk artvy apxiamy"
"ayjafsraz addjj agsj asejtziqws acatvhegu aoxdjqblsvv aekdmmbs aaobe"
"abjjvzubkwt alczv ati awz auyxgcxeb aymjoym anqoukprtyt atwfhpmbooh"
"ajfqz aethlgir aclcx aowlyvetby aproqm afjlqtkv anebfy akzrcpfrrvw"
"aoledfotm aiwlfm aeejlaej anz abgbvk aktfn aayoh anpywgdvgz"
"acvmldguld asdvz aqb aeomsyzyu aggylhprbdz asrfkwz auipybpsn agsnszzfb"
}
sqlite3_db_config db DEFENSIVE 0
do_test fts3corrupt2-1.0 {
execsql BEGIN
execsql { CREATE VIRTUAL TABLE t2 USING FTS3(a, b); }
execsql { INSERT INTO t2(t2) VALUES('nodesize=32') }
foreach d $data {
execsql { INSERT INTO t2 VALUES($d, $d) }
}
execsql COMMIT
execsql { SELECT count(*) FROM t2_segments }
} {163}
proc set_byte {blob byte val} {
binary format a*ca* \
[string range $blob 0 [expr $byte-1]] \
$val \
[string range $blob [expr $byte+1] end] \
}
set tn 0
set c 256
foreach {rowid sz blob} [
db eval {SELECT rowid, length(block), block FROM t2_segments}
] {
incr tn
set c [expr (($c+255)%256)]
for {set i 0} {$i < $sz} {incr i} {
set b2 [set_byte $blob $i $c]
execsql { UPDATE t2_segments SET block = $b2 WHERE rowid = $rowid }
do_test fts3corrupt2-1.$tn.$i {
catchsql { SELECT * FROM t2 WHERE t2 MATCH 'a*' }
set {} {}
} {}
}
execsql { UPDATE t2_segments SET block = $blob WHERE rowid = $rowid }
}
foreach c {50 100 150 200 250} {
foreach {rowid sz blob} [
db eval {SELECT rowid, length(root), root FROM t2_segdir}
] {
incr tn
for {set i 0} {$i < $sz} {incr i} {
set b2 [set_byte $blob $i $c]
execsql { UPDATE t2_segdir SET root = $b2 WHERE rowid = $rowid }
do_test fts3corrupt2-2.$c.$tn.$i {
catchsql { SELECT * FROM t2 WHERE t2 MATCH 'a*' }
set {} {}
} {}
}
execsql { UPDATE t2_segdir SET root = $blob WHERE rowid = $rowid }
}
}
finish_test
|