3 # May you do good and not evil.
4 # May you find forgiveness for yourself and forgive others.
5 # May you share freely, never taking more than you give.
7 #***********************************************************************
8 # Test that the FTS3 extension does not crash when it encounters a
9 # corrupt data structure on disk.
12 set testdir [file dirname $argv0]
13 source $testdir/tester.tcl
15 # If SQLITE_ENABLE_FTS3 is not defined, omit this file.
16 ifcapable !fts3 { finish_test ; return }
18 set ::testprefix fts3corrupt2
19 sqlite3_fts3_may_be_corrupt 1
23 "amxtvoo adqwroyhz auq aithtir avniqnuynvf axp ahibayfynig agbicpm"
24 "ajdtebs anteaxr aieynenwmd awpl alo akxcrwow aoxftge aoqvgul"
25 "amcfvdr auz apu aebelm ahuxyz aqc asyafdb agulvhvqu"
26 "apepwfyz azkhdvkw aenyelxzbk aslnitbyet aycdsdcpgr aqzzdbc agfi axnypydou"
27 "aaqrzzcm apcxdxo atumltzj aevvivo aodknoft aqoyytoz alobx apldt"
28 "adjllxlhnmj aiuhvuj adwppceuht atvj azrsam ahkjqdhny audlqxr aotgcd"
29 "aira azflsceos awj auzbobfkc awmezplr aeh awec ahndxlmv"
30 "aydwnied alk auoap agihyqeix aymqxzajnl aydwnied aojkarx agbo"
31 "ahajsmcl anvx amdhjm aoptsj agugzjjm apkevm acnj acjg"
32 "amwtkw aogttbykvt aubwrfqnbjf ajow agsj aerkqzjdqst anenlvbalkn arfajzzgckx"
33 "adqqqofkmz amjpavjuhw aqgehgnb awvvxlbtqzn agstqko akmkzehyh atagzey agwja"
34 "amag ahe autkllywhr avnk atmt akn anvdh aixfrv"
35 "aqdyerbws avefykly awl azaduojgzo anxfsmw axpt abgbvk ati"
36 "attyqkwz aiweypiczul afy asitaqbczhh aitxisizpv auhviq aibql ajfqc"
37 "aylzprtmta aiuemihqrpi awluvgsw ampbuy axlifpzfqr aems aoaxwads apianfn"
38 "aodrkijelq acdb aaserrdxm aqyasgofqu aevvivo afi apmwu aeoqysl"
39 "amqnk ankaotm ayfy ajcupeeoc advcbukan aucahlwnyk adbfyo azqjpeant"
40 "afczpp asqrs ahslvda akhlf aiqgdp atyd aznuglxqbrg awirndrh"
41 "aqhiajp amxeazb asxuehg akod axvolvsp agcz asmovmohy acmqa"
42 "avvomv aafms ashuaec arevx audtq alrwqhjvao avgsgpg ajbrctpsel"
43 "atxoirr ayopboobqdu ajunntua arh aernimxid aipljda aglo aefk"
44 "aonxf acmnnkna abgviaswe aulvcbv axp apemgakpzo aibql acioaid"
45 "axo alrwqhjvao ayqounftdzl azmoakdyh apajze ajk artvy apxiamy"
46 "ayjafsraz addjj agsj asejtziqws acatvhegu aoxdjqblsvv aekdmmbs aaobe"
47 "abjjvzubkwt alczv ati awz auyxgcxeb aymjoym anqoukprtyt atwfhpmbooh"
48 "ajfqz aethlgir aclcx aowlyvetby aproqm afjlqtkv anebfy akzrcpfrrvw"
49 "aoledfotm aiwlfm aeejlaej anz abgbvk aktfn aayoh anpywgdvgz"
50 "acvmldguld asdvz aqb aeomsyzyu aggylhprbdz asrfkwz auipybpsn agsnszzfb"
53 sqlite3_db_config db DEFENSIVE 0
54 do_test fts3corrupt2-1.0 {
56 execsql { CREATE VIRTUAL TABLE t2 USING FTS3(a, b); }
57 execsql { INSERT INTO t2(t2) VALUES('nodesize=32') }
59 execsql { INSERT INTO t2 VALUES($d, $d) }
62 execsql { SELECT count(*) FROM t2_segments }
65 proc set_byte {blob byte val} {
67 [string range $blob 0 [expr $byte-1]] \
69 [string range $blob [expr $byte+1] end] \
74 foreach {rowid sz blob} [
75 db eval {SELECT rowid, length(block), block FROM t2_segments}
78 set c [expr (($c+255)%256)]
79 for {set i 0} {$i < $sz} {incr i} {
80 set b2 [set_byte $blob $i $c]
81 execsql { UPDATE t2_segments SET block = $b2 WHERE rowid = $rowid }
82 do_test fts3corrupt2-1.$tn.$i {
83 catchsql { SELECT * FROM t2 WHERE t2 MATCH 'a*' }
87 execsql { UPDATE t2_segments SET block = $blob WHERE rowid = $rowid }
90 foreach c {50 100 150 200 250} {
91 foreach {rowid sz blob} [
92 db eval {SELECT rowid, length(root), root FROM t2_segdir}
95 for {set i 0} {$i < $sz} {incr i} {
96 set b2 [set_byte $blob $i $c]
97 execsql { UPDATE t2_segdir SET root = $b2 WHERE rowid = $rowid }
98 do_test fts3corrupt2-2.$c.$tn.$i {
99 catchsql { SELECT * FROM t2 WHERE t2 MATCH 'a*' }
103 execsql { UPDATE t2_segdir SET root = $blob WHERE rowid = $rowid }