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
22 "amxtvoo adqwroyhz auq aithtir avniqnuynvf axp ahibayfynig agbicpm"
23 "ajdtebs anteaxr aieynenwmd awpl alo akxcrwow aoxftge aoqvgul"
24 "amcfvdr auz apu aebelm ahuxyz aqc asyafdb agulvhvqu"
25 "apepwfyz azkhdvkw aenyelxzbk aslnitbyet aycdsdcpgr aqzzdbc agfi axnypydou"
26 "aaqrzzcm apcxdxo atumltzj aevvivo aodknoft aqoyytoz alobx apldt"
27 "adjllxlhnmj aiuhvuj adwppceuht atvj azrsam ahkjqdhny audlqxr aotgcd"
28 "aira azflsceos awj auzbobfkc awmezplr aeh awec ahndxlmv"
29 "aydwnied alk auoap agihyqeix aymqxzajnl aydwnied aojkarx agbo"
30 "ahajsmcl anvx amdhjm aoptsj agugzjjm apkevm acnj acjg"
31 "amwtkw aogttbykvt aubwrfqnbjf ajow agsj aerkqzjdqst anenlvbalkn arfajzzgckx"
32 "adqqqofkmz amjpavjuhw aqgehgnb awvvxlbtqzn agstqko akmkzehyh atagzey agwja"
33 "amag ahe autkllywhr avnk atmt akn anvdh aixfrv"
34 "aqdyerbws avefykly awl azaduojgzo anxfsmw axpt abgbvk ati"
35 "attyqkwz aiweypiczul afy asitaqbczhh aitxisizpv auhviq aibql ajfqc"
36 "aylzprtmta aiuemihqrpi awluvgsw ampbuy axlifpzfqr aems aoaxwads apianfn"
37 "aodrkijelq acdb aaserrdxm aqyasgofqu aevvivo afi apmwu aeoqysl"
38 "amqnk ankaotm ayfy ajcupeeoc advcbukan aucahlwnyk adbfyo azqjpeant"
39 "afczpp asqrs ahslvda akhlf aiqgdp atyd aznuglxqbrg awirndrh"
40 "aqhiajp amxeazb asxuehg akod axvolvsp agcz asmovmohy acmqa"
41 "avvomv aafms ashuaec arevx audtq alrwqhjvao avgsgpg ajbrctpsel"
42 "atxoirr ayopboobqdu ajunntua arh aernimxid aipljda aglo aefk"
43 "aonxf acmnnkna abgviaswe aulvcbv axp apemgakpzo aibql acioaid"
44 "axo alrwqhjvao ayqounftdzl azmoakdyh apajze ajk artvy apxiamy"
45 "ayjafsraz addjj agsj asejtziqws acatvhegu aoxdjqblsvv aekdmmbs aaobe"
46 "abjjvzubkwt alczv ati awz auyxgcxeb aymjoym anqoukprtyt atwfhpmbooh"
47 "ajfqz aethlgir aclcx aowlyvetby aproqm afjlqtkv anebfy akzrcpfrrvw"
48 "aoledfotm aiwlfm aeejlaej anz abgbvk aktfn aayoh anpywgdvgz"
49 "acvmldguld asdvz aqb aeomsyzyu aggylhprbdz asrfkwz auipybpsn agsnszzfb"
52 do_test fts3corrupt2-1.0 {
54 execsql { CREATE VIRTUAL TABLE t2 USING FTS3(a, b); }
55 execsql { INSERT INTO t2(t2) VALUES('nodesize=32') }
57 execsql { INSERT INTO t2 VALUES($d, $d) }
60 execsql { SELECT count(*) FROM t2_segments }
63 proc set_byte {blob byte val} {
65 [string range $blob 0 [expr $byte-1]] \
67 [string range $blob [expr $byte+1] end] \
72 foreach {rowid sz blob} [
73 db eval {SELECT rowid, length(block), block FROM t2_segments}
76 set c [expr (($c+255)%256)]
77 for {set i 0} {$i < $sz} {incr i} {
78 set b2 [set_byte $blob $i $c]
79 execsql { UPDATE t2_segments SET block = $b2 WHERE rowid = $rowid }
80 do_test fts3corrupt2-1.$tn.$i {
81 catchsql { SELECT * FROM t2 WHERE t2 MATCH 'a*' }
85 execsql { UPDATE t2_segments SET block = $blob WHERE rowid = $rowid }
88 foreach c {50 100 150 200 250} {
89 foreach {rowid sz blob} [
90 db eval {SELECT rowid, length(root), root FROM t2_segdir}
93 for {set i 0} {$i < $sz} {incr i} {
94 set b2 [set_byte $blob $i $c]
95 execsql { UPDATE t2_segdir SET root = $b2 WHERE rowid = $rowid }
96 do_test fts3corrupt2-2.$c.$tn.$i {
97 catchsql { SELECT * FROM t2 WHERE t2 MATCH 'a*' }
101 execsql { UPDATE t2_segdir SET root = $blob WHERE rowid = $rowid }