interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / fts3corrupt7.test

440 lines · 24850 bytes Raw Blame History
1# 2024 November 7
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# This file implements regression tests for SQLite library. The
12# focus of this script is testing the FTS3 module.
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17source $testdir/fts3_common.tcl
18set testprefix fts3corrupt7
19
20# If SQLITE_ENABLE_FTS3 is defined, omit this file.
21ifcapable !fts3 {
22 finish_test
23 return
24}
25
26sqlite3_fts3_may_be_corrupt 1
27database_may_be_corrupt
28extra_schema_checks 0
29
30#-------------------------------------------------------------------------
31reset_db
32do_test 1.0 {
33 sqlite3 db {}
34 db deserialize [decode_hexdb {
35| size 28672 pagesize 4096 filename x.db
36| page 1 offset 0
37| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
38| 16: 10 00 01 01 00 40 20 20 00 00 00 04 00 00 00 07 .....@ ........
39| 32: 00 00 00 02 00 00 00 01 00 00 00 04 00 00 00 04 ................
40| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................
41| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 ................
42| 96: 00 2e 82 40 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21 ...@...........!
43| 112: 0e b9 0d c8 0e 7e 0d a4 7d a4 00 00 00 00 00 00 .....~..........
44| 2512: 00 00 00 00 00 00 00 00 96 00 00 00 00 00 00 00 ................
45| 3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c ...........1tabl
46| 3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB
47| 3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01 LE t2(x).3......
48| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir
49| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE
50| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi
51| 3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 r'(level INTEGER
52| 3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 ,idx INTEGER,sta
53| 3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 rt_block INTEGER
54| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc
55| 3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c k INTEGER,end_bl
56| 3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 ock INTEGER,root
57| 3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 BLOB,PRIMARY KE
58| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06 Y(level, idx))1.
59| 3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 ..E...indexsqlit
60| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s
61| 3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 egdir_1t1_segdir
62| 3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01 .........f...##.
63| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen
64| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52 tst1_segments.CR
65| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s
66| 3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 egments'(blockid
67| 3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 INTEGER PRIMARY
68| 3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 KEY, block BLOB
69| 3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74 )j...!!...tablet
70| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont
71| 3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE
72| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do
73| 3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d cid INTEGER PRIM
74| 3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20 ARY KEY, 'c0a',
75| 3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06 'c1b', 'c2c')8..
76| 3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR
77| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB
78| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3
79| 4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00 (a,b,c)...9.....
80| page 2 offset 4096
81| 0: 01 00 00 00 00 01 00 00 00 00 01 00 00 00 00 01 ................
82| 16: 00 00 00 00 02 00 00 00 00 05 00 00 00 03 02 00 ................
83| 32: 00 00 00 05 00 00 00 03 02 00 00 00 00 05 00 00 ................
84| 48: 00 03 02 00 00 00 00 05 00 00 00 03 02 00 00 00 ................
85| 64: 00 05 00 00 00 03 02 00 00 00 00 05 00 00 00 03 ................
86| 80: 02 00 00 00 00 05 00 00 00 03 02 00 00 00 00 05 ................
87| 96: 00 00 00 03 02 00 00 00 00 05 00 00 00 03 05 00 ................
88| 112: 00 00 03 03 00 00 00 23 02 00 00 00 00 03 00 00 .......#........
89| 128: 00 23 02 00 00 00 00 03 00 00 4d 5a 14 00 ae 7c .#........MZ...|
90| 1088: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 ................
91| 4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 ................
92| page 3 offset 8192
93| 0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74 ....%.H........t
94| 16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5 .a.N./..........
95| 32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5 ...t.[.@.$......
96| 48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb .......h.O.5....
97| 64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a .......x.W.>.$..
98| 80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00 .H..............
99| 2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00 .........?%.....
100| 2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e .COMPILER=gcc-5.
101| 2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 45 42 4.0 20160609 DEB
102| 2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54 UG ENABLE DBSTAT
103| 2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53 VTAB ENABLE FTS
104| 2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e 4 ENABLE FTS5 EN
105| 2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41 ABLE GEOPOLY ENA
106| 2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45 BLE JSON1 ENABLE
107| 3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20 MEMSYS5 ENABLE
108| 3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59 RTREE MAX MEMORY
109| 3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c =50000000 OMIT L
110| 3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48 OAD EXTENSION TH
111| 3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f READSAFE=0.$..%.
112| 3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49 .THREADSAFE=0XBI
113| 3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41 NARY.#..%..THREA
114| 3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22 DSAFE=0XNOCASE..
115| 3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d ..%..THREADSAFE=
116| 3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d 0XRTRIM.!..3..OM
117| 3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f IT LOAD EXTENSIO
118| 3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f NXBINARY. ..3..O
119| 3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 MIT LOAD EXTENSI
120| 3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17 ONXNOCASE....3..
121| 3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 OMIT LOAD EXTENS
122| 3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 00 00 IONXRTRIM....3..
123| 4016: 54 41 42 4c 45 20 74 31 28 61 20 49 4e 54 45 47 TABLE t1(a INTEG
124| 4032: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 20 41 ER PRIMARY KEY A
125| 4048: 55 54 4f 49 4e 43 52 45 4d 45 4e 54 2c 0a 62 2c UTOINCREMENT,.b,
126| 4064: 63 2c 64 2c 65 2c 66 2c 67 2c 68 2c 6a 2c 6b 2c c,d,e,f,g,h,j,k,
127| 4080: 6c 2c 6d 2c 6e 2c 6f 2c 70 2c 71 2c 72 2c 73 29 l,m,n,o,p,q,r,s)
128| page 5 offset 16384
129| 0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00 ................
130| 2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33 ...........0 253
131| 2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36 ..0.%.....201606
132| 3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35 09.%....4.%....5
133| 3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a .%....0000000.%.
134| 3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00 ...compiler.%...
135| 3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75 .dbstat.%....ebu
136| 3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09 g.%....enable.%.
137| 3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f .........xtensio
138| 3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03 n.%....fts4.%...
139| 3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01 .5.%....gcc.%...
140| 3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f .eopoly.%....jso
141| 3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00 n1.%....load.%..
142| 3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79 ..max.%....emory
143| 3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04 .%....sys5.%....
144| 3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03 omit.%....rtree.
145| 3216: 25 01 00 d0 0a 07 68 72 65 61 64 73 61 66 65 03 %.....hreadsafe.
146| 3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01 %....vtab.%...P.
147| 3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30 ........0 835..0
148| 3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00 ................
149| 3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07 .....20160609...
150| 3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05 .........4......
151| 3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04 ......5.........
152| 3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04 ...0000000......
153| 3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02 ......binary<...
154| 3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................
155| 3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................
156| 3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 ................
157| 3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69 ...........compi
158| 3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64 ler............d
159| 3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01 bstat...........
160| 3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00 .ebug...........
161| 3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02 .enable?........
162| 3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 ................
163| 3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 ................
164| 3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 ................
165| 3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f .........xtensio
166| 3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73 n............fts
167| 3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d 4............5..
168| 3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03 ..........gcc...
169| 3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09 .........eopoly.
170| 3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31 ...........json1
171| 3632: 09 13 03 00 01 03 01 01 03 00 00 04 6c 6f 61 64 ............load
172| 3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09 ............max.
173| 3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79 ...........emory
174| 3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35 ............sys5
175| 3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61 ............noca
176| 3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02 se<.............
177| 3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 ................
178| 3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00 ................
179| 3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00 .omit...........
180| 3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00 .rtree..........
181| 3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03 ..im<...........
182| 3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 ................
183| 3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 ................
184| 3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 ................
185| 3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02 ...threadsafe...
186| 3888: 00 01 02 00 01 02 00 00 04 76 74 61 62 09 07 04 .........vtab...
187| 3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................
188| 3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................
189| 3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................
190| 4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................
191| 4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 ................
192| 4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 ................
193| 4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 ................
194| 4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 ................
195| page 6 offset 20480
196| 0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00 ................
197| 4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09 ................
198| end x.db
199}]} {}
200
201do_catchsql_test 1.1 {
202 SELECT offsets(t1) FROM t1 WHERE t1 MATCH 'rtree NEAR rtree NEAR "json1 enable"';
203} {0 {}}
204
205#-------------------------------------------------------------------------
206reset_db
207do_test 1.0 {
208 sqlite3 db {}
209 db deserialize [decode_hexdb {
210| size 24576 pagesize 4096 filename crash-10b0f1037e9c85.db
211| page 1 offset 0
212| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
213| 16: 10 00 00 00 00 40 20 20 00 00 00 01 00 00 00 07 .....@ ........
214| 32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................
215| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 ................
216| 96: 00 2e 82 40 0d 00 00 00 06 00 00 00 0f 8d 0f 21 ...@...........!
217| 112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00 .....~..........
218| 3488: 00 00 00 00 21 ff 06 17 10 10 01 30 74 61 62 6c ....!......0tabl
219| 3504: 65 74 32 74 32 00 43 52 45 41 54 45 20 54 41 42 et2t2.CREATE TAB
220| 3520: 4c 45 20 74 32 28 70 29 81 33 00 07 17 1f 1f 01 LE t2(p).3......
221| 3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 .5tablet1_segdir
222| 3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45 t1_segdir.CREATE
223| 3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 TABLE 't1_segdi
224| 3584: 72 27 28 6c 65 76 65 6c 20 09 4e 50 45 47 45 50 r'(level .NPEGEP
225| 3600: 2c 69 64 78 20 09 4e 50 45 47 45 50 2c 73 74 61 ,idx .NPEGEP,sta
226| 3616: 72 74 5f 62 6c 6f 63 6b 20 09 4e 50 45 47 45 50 rt_block .NPEGEP
227| 3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 ,leaves_end_bloc
228| 3648: 6b 20 09 4e 50 45 47 45 50 2c 65 6e 64 5f 62 6c k .NPEGEP,end_bl
229| 3664: 6f 63 6b 20 09 4e 50 45 47 45 50 2c 72 6f 6f 74 ock .NPEGEP,root
230| 3680: 20 42 0c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 B.OB,PRIMARY KE
231| 3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 00 Y(level, idx))1.
232| 3712: 06 17 45 1f 01 00 00 00 00 00 00 73 71 6c 69 74 ..E........sqlit
233| 3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 e_autoindex_t1_s
234| 3744: 65 67 64 69 72 5f 31 00 00 00 00 00 00 00 00 00 egdir_1.........
235| 3760: 06 00 00 00 00 00 00 00 00 66 00 07 17 23 23 01 .........f...##.
236| 3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e ..tablet1_segmen
237| 3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 00 43 52 tst1_segments.CR
238| 3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 EATE TABLE 't1_s
239| 3824: 65 67 6d 65 6e 74 73 27 28 0c 6f 63 6b 09 64 0a egments'(.ock.d.
240| 3840: 20 09 4e 50 45 47 45 50 20 50 50 09 04 31 50 09 .NPEGEP PP..1P.
241| 3856: 20 0b 45 09 0c 20 62 0c 6f 63 6b 20 42 0c 4f 42 .E.. b.ock B.OB
242| 3872: 29 6a 00 07 17 20 20 01 81 1f 74 61 62 6c 65 74 )j... ...tablet
243| 3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 1_contentt1_cont
244| 3904: 65 6e 74 00 43 52 45 41 54 45 20 54 41 42 4c 45 ent.CREATE TABLE
245| 3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 't1_content'(do
246| 3936: 09 64 20 09 4e 50 45 47 45 50 20 50 50 09 0d 0c .d .NPEGEP PP...
247| 3952: 50 09 20 0b 45 09 0c 20 27 03 03 01 27 0c 20 0a P. .E.. '...'. .
248| 3968: 27 03 01 02 27 0c 20 27 03 02 03 27 29 38 00 06 '...'. '...')8..
249| 3984: 17 10 10 08 5f 74 61 62 6c 65 74 31 74 31 43 52 ...._tablet1t1CR
250| 4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 EATE VIRTUAL TAB
251| 4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33 LE t1 USING fts3
252| page 5 offset 16384
253| 0: 0d 00 00 00 02 00 00 00 00 00 0b a0 00 00 00 00 ................
254| 2976: 82 0a 02 08 00 00 00 00 17 84 06 00 00 00 00 00 ................
255| 2992: 00 01 00 04 00 00 00 00 00 08 00 00 00 00 00 00 ................
256| 3008: 00 00 03 00 00 00 00 01 00 03 00 00 00 00 01 00 ................
257| 3024: 03 00 00 00 00 07 00 00 00 00 00 00 00 03 00 00 ................
258| 3040: 00 00 08 00 00 00 00 00 00 00 00 03 00 00 00 00 ................
259| 3056: 06 00 00 00 00 00 00 03 00 00 00 00 04 00 00 00 ................
260| 3072: 00 03 00 00 00 00 06 65 6e 61 62 6c 65 09 25 09 .......enable.%.
261| 3088: 05 04 04 04 04 00 00 00 08 00 00 00 00 00 00 00 ................
262| 3104: 00 03 00 00 00 00 04 00 00 00 00 03 00 00 00 00 ................
263| 3120: 01 00 03 00 00 00 00 03 00 00 00 03 00 00 00 00 ................
264| 3136: 06 00 00 00 00 00 00 03 00 00 00 00 05 6a 73 6f .............jso
265| 3152: 6e 31 03 25 13 00 00 04 00 00 00 00 03 00 00 00 n1.%............
266| 3168: 00 03 00 00 00 03 00 00 00 00 05 00 00 00 00 00 ................
267| 3184: 03 00 00 00 00 04 00 00 00 00 03 00 00 00 00 04 ................
268| 3200: 00 00 00 00 03 00 00 00 00 05 72 74 72 65 65 03 ..........rtree.
269| 3216: 25 01 00 0d 0a 07 08 01 ff ff ff ff ff 01 00 00 %...............
270| page 6 offset 20480
271| 0: 0a 00 00 00 02 00 00 00 0f fb 0f f5 00 00 00 00 ................
272| 4080: 00 00 00 00 00 05 04 09 00 01 02 04 00 00 00 00 ................
273| end crash-10b0f1037e9c85.db
274}]} {}
275
276do_catchsql_test 2.1 {
277 SELECT 0 FROM t1 WHERE t1 MATCH 'rtree NEAR rtree"json1 enable"';
278} {1 {database disk image is malformed}}
279
280#-------------------------------------------------------------------------
281reset_db
282
283set DEPTH 40000
284
285proc fts3_put_varint {v} {
286 set l [list]
287 while {$v >= 0x80} {
288 lappend l [expr ($v & 0x7F) | 0x80]
289 set v [expr $v >> 7]
290 }
291 lappend l [expr $v & 0x7F]
292
293 binary format cu* $l
294}
295
296proc make_interior_node {height child_blockid} {
297 binary format a*a* [fts3_put_varint $height] [fts3_put_varint $child_blockid]
298}
299db func make_interior_node make_interior_node
300
301do_execsql_test 3.0 {
302 CREATE VIRTUAL TABLE fts USING fts3(content TEXT);
303 INSERT INTO fts(content) VALUES ('hello world');
304 DELETE FROM fts_segdir;
305 INSERT INTO fts_segdir
306 (level, idx, start_block, leaves_end_block, end_block, root) VALUES
307 (0, 0, 100, 100 + $DEPTH, 100 + $DEPTH, make_interior_node($DEPTH+1, 100));
308}
309
310do_test 3.1 {
311 execsql BEGIN
312 for {set ii 0} {$ii<$DEPTH} {incr ii} {
313 execsql {
314 INSERT INTO fts_segments(blockid, block)
315 VALUES($ii+100, make_interior_node($DEPTH-$ii, 101+$ii))
316 }
317 }
318 execsql COMMIT
319} {}
320
321do_catchsql_test 3.2 {
322 SELECT * FROM fts WHERE fts MATCH 'x';
323} {1 {database disk image is malformed}}
324
325#-------------------------------------------------------------------------
326reset_db
327
328do_execsql_test 4.1 {
329 CREATE VIRTUAL TABLE t1 USING fts4(content);
330 DELETE FROM t1_segments;
331 DELETE FROM t1_segdir;
332}
333
334do_execsql_test 4.2 {
335 INSERT INTO t1_segdir
336 (level, idx, start_block, leaves_end_block, end_block, root)
337 VALUES(0, 0, 0, 0, 0, X'000568656C6C6F08010201FFFFFF7F00');
338}
339
340do_execsql_test 4.3 {
341 CREATE VIRTUAL TABLE t1_terms USING fts4aux(t1);
342}
343
344do_catchsql_test 4.4 {
345 SELECT * FROM t1_terms;
346} {1 {database disk image is malformed}}
347
348#-------------------------------------------------------------------------
349reset_db
350
351do_execsql_test 7.0 {
352 CREATE VIRTUAL TABLE t USING fts3(x);
353 INSERT INTO t_segdir(level,idx,start_block,leaves_end_block,end_block,root)
354 VALUES(1,0,0,0,'0 -9223372036854775808',x'00');
355}
356
357do_execsql_test 7.1 {
358 INSERT INTO t(x) VALUES('alpha');
359}
360
361#-------------------------------------------------------------------------
362reset_db
363do_execsql_test 8.0 {
364 CREATE VIRTUAL TABLE t USING fts4(x);
365 INSERT INTO t_content(docid,c0x) VALUES(1,'a b');
366 DELETE FROM t_segments;
367 DELETE FROM t_segdir;
368 INSERT INTO t_segdir(level,idx,start_block,leaves_end_block,end_block,root)
369 VALUES(0,0,0,0,0,x'000161110150028001500a818080800103038101000001622c010281008101ffffffffffffffffff010204ffffffffffffffffff01ffffffffffffffffff01c80109323200');
370}
371
372do_execsql_test 8.1 {
373 SELECT count(*) FROM t WHERE t MATCH 'a NEAR/100 b';
374} {1}
375
376#-------------------------------------------------------------------------
377reset_db
378do_test 9.0 {
379 sqlite3 db {}
380 db deserialize [decode_hexdb {
381| size 20480 pagesize 4096 filename poc.db
382| page 1 offset 0
383| 0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00 SQLite format 3.
384| 16: 10 00 01 01 00 40 20 20 00 00 00 03 00 00 00 05 .....@ ........
385| 32: 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 04 ................
386| 48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 ................
387| 80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 ................
388| 96: 00 2e 76 89 0d 0e f9 00 05 0e 15 00 0f c7 0f 66 ..v............f
389| 112: 0f 01 0e 15 0e c8 00 00 00 00 00 00 00 00 00 00 ................
390| 3600: 00 00 00 00 00 81 30 04 07 17 1d 1d 01 82 33 74 ......0.......3t
391| 3616: 61 62 6c 65 74 5f 73 65 67 64 69 72 74 5f 73 65 ablet_segdirt_se
392| 3632: 67 64 69 72 04 43 52 45 41 54 45 20 54 41 42 4c gdir.CREATE TABL
393| 3648: 45 20 27 74 5f 73 65 67 64 69 72 27 28 6c 65 76 E 't_segdir'(lev
394| 3664: 65 6c 20 49 4e 54 45 47 45 52 2c 69 64 78 20 49 el INTEGER,idx I
395| 3680: 4e 54 45 47 45 52 2c 73 74 61 72 74 5f 62 6c 6f NTEGER,start_blo
396| 3696: 63 6b 20 49 4e 54 45 47 45 52 2c 6c 65 61 76 65 ck INTEGER,leave
397| 3712: 73 5f 65 6e 64 5f 62 6c 6f 63 6b 20 49 4e 54 45 s_end_block INTE
398| 3728: 47 45 52 2c 65 6e 64 5f 62 6c 6f 63 6b 20 49 4e GER,end_block IN
399| 3744: 54 45 47 45 52 2c 72 6f 6f 74 20 42 4c 4f 42 2c TEGER,root BLOB,
400| 3760: 50 52 49 4d 41 52 59 20 4b 45 59 28 6c 65 76 65 PRIMARY KEY(leve
401| 3776: 6c 2c 20 69 64 78 29 29 2f 05 06 17 43 1d 01 00 l, idx))/...C...
402| 3792: 69 6e 64 65 78 73 71 6c 69 74 65 5f 61 75 74 6f indexsqlite_auto
403| 3808: 69 6e 64 65 78 5f 74 5f 73 65 67 64 69 72 5f 31 index_t_segdir_1
404| 3824: 74 5f 73 65 67 64 69 72 05 00 00 00 08 00 00 00 t_segdir........
405| 3840: 00 63 03 07 17 21 21 01 81 11 74 61 62 6c 65 74 .c...!!...tablet
406| 3856: 5f 73 65 67 6d 65 6e 74 73 74 5f 73 65 67 6d 65 _segmentst_segme
407| 3872: 6e 74 73 03 43 52 45 41 54 45 20 54 41 42 4c 45 nts.CREATE TABLE
408| 3888: 20 27 74 5f 73 65 67 6d 65 6e 74 73 27 28 62 6c 't_segments'(bl
409| 3904: 6f 63 6b 69 64 20 49 4e 54 45 47 45 52 20 50 52 ockid INTEGER PR
410| 3920: 49 4d 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b IMARY KEY, block
411| 3936: 20 42 4c 4f 42 29 5f 02 07 17 1f 1f 01 81 0d 74 BLOB)_........t
412| 3952: 61 62 6c 65 74 5f 63 6f 6e 74 65 6e 74 74 5f 63 ablet_contentt_c
413| 3968: 6f 6e 74 65 6e 74 02 43 52 45 41 54 45 20 54 41 ontent.CREATE TA
414| 3984: 42 4c 45 20 27 74 5f 63 6f 6e 74 65 6e 74 27 28 BLE 't_content'(
415| 4000: 64 6f 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 docid INTEGER PR
416| 4016: 49 4d 41 52 59 20 4b 45 59 2c 20 27 63 30 63 6f IMARY KEY, 'c0co
417| 4032: 6e 74 65 6e 74 27 29 37 01 06 17 0f 0f 08 61 74 ntent')7......at
418| 4048: 61 62 6c 65 74 74 43 52 45 41 54 45 20 56 49 52 ablettCREATE VIR
419| 4064: 54 55 41 4c 20 54 41 42 4c 45 20 74 20 55 53 49 TUAL TABLE t USI
420| 4080: 4e 47 20 66 74 73 33 28 63 6f 6e 74 65 6e 74 29 NG fts3(content)
421| page 2 offset 4096
422| 0: 0d 00 00 00 01 0f f6 00 0f f6 00 00 00 00 00 00 ................
423| 4080: 00 00 00 00 00 00 08 01 03 00 17 68 65 6c 6c 6f ...........hello
424| page 3 offset 8192
425| 0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00 ................
426| page 4 offset 12288
427| 0: 0d 00 00 00 01 0f e4 00 0f e4 00 00 00 00 00 00 ................
428| 4064: 00 00 00 00 1a 01 07 08 08 08 08 15 2a 30 20 31 ............*0 1
429| 4080: 31 00 05 68 65 6c 6c 6f 07 01 82 80 80 80 10 00 1..hello........
430| page 5 offset 16384
431| 0: 0a 00 00 00 01 0f fb 00 0f fb 00 00 00 00 00 00 ................
432| 4080: 00 00 00 00 00 00 00 00 00 00 00 04 04 08 08 09 ................
433| end poc.db
434}]} {}
435
436do_execsql_test 9.1 {
437 PRAGMA integrity_check;
438} {{malformed inverted index for FTS3 table main.t}}
439
440finish_test