CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
fts3corrupt2.test112 linesDownload Raw Back to test
1# 2010 October 302#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.6#7#***********************************************************************8# Test that the FTS3 extension does not crash when it encounters a9# corrupt data structure on disk.10#11 12set testdir [file dirname $argv0]13source $testdir/tester.tcl14 15# If SQLITE_ENABLE_FTS3 is not defined, omit this file.16ifcapable !fts3 { finish_test ; return }17 18set ::testprefix fts3corrupt219sqlite3_fts3_may_be_corrupt 120 21set data [list]22lappend data {*}{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"51}52 53sqlite3_db_config db DEFENSIVE 054do_test fts3corrupt2-1.0 {55  execsql BEGIN56  execsql { CREATE VIRTUAL TABLE t2 USING FTS3(a, b); }57  execsql { INSERT INTO t2(t2) VALUES('nodesize=32') }58  foreach d $data {59    execsql { INSERT INTO t2 VALUES($d, $d) }60  }61  execsql COMMIT62  execsql { SELECT count(*) FROM t2_segments }63} {163}64 65proc set_byte {blob byte val} {66  binary format a*ca*                         \67      [string range $blob 0 [expr $byte-1]]   \68      $val                                    \69      [string range $blob [expr $byte+1] end] \70}71 72set tn 073set c 25674foreach {rowid sz blob} [75  db eval {SELECT rowid, length(block), block FROM t2_segments}76] {77  incr tn78  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*' }84      set {} {}85    } {}86  }87  execsql { UPDATE t2_segments SET block = $blob WHERE rowid = $rowid }88}89 90foreach c {50 100 150 200 250} {91  foreach {rowid sz blob} [92    db eval {SELECT rowid, length(root), root FROM t2_segdir}93  ] {94    incr tn95    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*' }100        set {} {}101      } {}102    }103    execsql { UPDATE t2_segdir SET root = $blob WHERE rowid = $rowid }104  }105}106 107 108 109 110 111finish_test112