/ Check-in [c089cc4f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merge latest trunk into this branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | reuse-schema
Files: files | file ages | folders
SHA3-256:c089cc4fbe2e5e53d76154146870d14fc3b8d342a49580e41a5616817099715c
User & Date: dan 2019-02-05 19:51:15
Wiki:reuse-schema
Context
2019-02-08
19:30
Add test cases and fix problems on this branch. check-in: 2b2e9f81 user: dan tags: reuse-schema
2019-02-05
19:51
Merge latest trunk into this branch. check-in: c089cc4f user: dan tags: reuse-schema
19:15
Fix memory leaks on this branch. check-in: e9c5e189 user: dan tags: reuse-schema
16:53
Update the tester.tcl --malloctrace option so that it uses eu-addr2line instead of addr2line. check-in: 79c07387 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

    28     28   # are provide so that these aspects of the build process can be changed
    29     29   # on the "make" command-line.  Ex:  "make CC=clang CFLAGS=-fsanitize=undefined"
    30     30   #
    31     31   CC = @CC@
    32     32   CFLAGS = @CPPFLAGS@ @CFLAGS@
    33     33   TCC = ${CC} ${CFLAGS} -I. -I${TOP}/src -I${TOP}/ext/rtree -I${TOP}/ext/icu
    34     34   TCC += -I${TOP}/ext/fts3 -I${TOP}/ext/async -I${TOP}/ext/session
           35  +TCC += -I${TOP}/ext/userauth
    35     36   
    36     37   # Define this for the autoconf-based build, so that the code knows it can
    37     38   # include the generated config.h
    38     39   #
    39     40   TCC += -D_HAVE_SQLITE_CONFIG_H -DBUILD_sqlite
    40     41   
    41     42   # Define -DNDEBUG to compile without debugging (i.e., for production usage)
................................................................................
   183    184            memdb.lo memjournal.lo \
   184    185            mutex.lo mutex_noop.lo mutex_unix.lo mutex_w32.lo \
   185    186            notify.lo opcodes.lo os.lo os_unix.lo os_win.lo \
   186    187            pager.lo parse.lo pcache.lo pcache1.lo pragma.lo prepare.lo printf.lo \
   187    188            random.lo resolve.lo rowset.lo rtree.lo \
   188    189            sqlite3session.lo select.lo sqlite3rbu.lo status.lo stmt.lo \
   189    190            table.lo threads.lo tokenize.lo treeview.lo trigger.lo \
   190         -         update.lo upsert.lo util.lo vacuum.lo \
          191  +         update.lo userauth.lo upsert.lo util.lo vacuum.lo \
   191    192            vdbe.lo vdbeapi.lo vdbeaux.lo vdbeblob.lo vdbemem.lo vdbesort.lo \
   192    193            vdbetrace.lo wal.lo walker.lo where.lo wherecode.lo whereexpr.lo \
   193    194            window.lo utf.lo vtab.lo
   194    195   
   195    196   # Object files for the amalgamation.
   196    197   #
   197    198   LIBOBJS1 = sqlite3.lo
................................................................................
   352    353     $(TOP)/ext/rtree/rtree.h \
   353    354     $(TOP)/ext/rtree/rtree.c \
   354    355     $(TOP)/ext/rtree/geopoly.c
   355    356   SRC += \
   356    357     $(TOP)/ext/session/sqlite3session.c \
   357    358     $(TOP)/ext/session/sqlite3session.h
   358    359   SRC += \
          360  +  $(TOP)/ext/userauth/userauth.c \
          361  +  $(TOP)/ext/userauth/sqlite3userauth.h
          362  +SRC += \
   359    363     $(TOP)/ext/rbu/sqlite3rbu.h \
   360    364     $(TOP)/ext/rbu/sqlite3rbu.c
   361    365   SRC += \
   362    366     $(TOP)/ext/misc/json1.c \
   363    367     $(TOP)/ext/misc/stmt.c
   364    368   
   365    369   # Generated source code files
................................................................................
   444    448     $(TOP)/ext/fts5/fts5_test_mi.c \
   445    449     $(TOP)/ext/fts5/fts5_test_tok.c \
   446    450     $(TOP)/ext/misc/ieee754.c \
   447    451     $(TOP)/ext/misc/mmapwarm.c \
   448    452     $(TOP)/ext/misc/nextchar.c \
   449    453     $(TOP)/ext/misc/normalize.c \
   450    454     $(TOP)/ext/misc/percentile.c \
          455  +  $(TOP)/ext/misc/prefixes.c \
   451    456     $(TOP)/ext/misc/regexp.c \
   452    457     $(TOP)/ext/misc/remember.c \
   453    458     $(TOP)/ext/misc/series.c \
   454    459     $(TOP)/ext/misc/spellfix.c \
   455    460     $(TOP)/ext/misc/totype.c \
   456    461     $(TOP)/ext/misc/unionvtab.c \
   457    462     $(TOP)/ext/misc/wholenumber.c \
   458         -  $(TOP)/ext/misc/zipfile.c
          463  +  $(TOP)/ext/misc/zipfile.c \
          464  +  $(TOP)/ext/userauth/userauth.c
   459    465   
   460    466   # Source code to the library files needed by the test fixture
   461    467   #
   462    468   TESTSRC2 = \
   463    469     $(TOP)/src/attach.c \
   464    470     $(TOP)/src/backup.c \
   465    471     $(TOP)/src/bitvec.c \
................................................................................
   467    473     $(TOP)/src/build.c \
   468    474     $(TOP)/src/ctime.c \
   469    475     $(TOP)/src/date.c \
   470    476     $(TOP)/src/dbpage.c \
   471    477     $(TOP)/src/dbstat.c \
   472    478     $(TOP)/src/expr.c \
   473    479     $(TOP)/src/func.c \
          480  +  $(TOP)/src/global.c \
   474    481     $(TOP)/src/insert.c \
   475    482     $(TOP)/src/wal.c \
   476    483     $(TOP)/src/main.c \
   477    484     $(TOP)/src/mem5.c \
   478    485     $(TOP)/src/os.c \
   479    486     $(TOP)/src/os_unix.c \
   480    487     $(TOP)/src/os_win.c \
................................................................................
   556    563   EXTHDR += \
   557    564     $(TOP)/ext/rtree/rtree.h \
   558    565     $(TOP)/ext/rtree/geopoly.c
   559    566   EXTHDR += \
   560    567     $(TOP)/ext/icu/sqliteicu.h
   561    568   EXTHDR += \
   562    569     $(TOP)/ext/rtree/sqlite3rtree.h
          570  +EXTHDR += \
          571  +  $(TOP)/ext/userauth/sqlite3userauth.h
   563    572   
   564    573   # executables needed for testing
   565    574   #
   566    575   TESTPROGS = \
   567    576     testfixture$(TEXE) \
   568    577     sqlite3$(TEXE) \
   569    578     sqlite3_analyzer$(TEXE) \
................................................................................
   576    585   FUZZDATA = \
   577    586     $(TOP)/test/fuzzdata1.db \
   578    587     $(TOP)/test/fuzzdata2.db \
   579    588     $(TOP)/test/fuzzdata3.db \
   580    589     $(TOP)/test/fuzzdata4.db \
   581    590     $(TOP)/test/fuzzdata5.db \
   582    591     $(TOP)/test/fuzzdata6.db \
   583         -  $(TOP)/test/fuzzdata7.db
          592  +  $(TOP)/test/fuzzdata7.db \
          593  +  $(TOP)/test/fuzzdata8.db
   584    594   
   585    595   # Standard options to testfixture
   586    596   #
   587    597   TESTOPTS = --verbose=file --output=test-out.txt
   588    598   
   589    599   # Extra compiler options for various shell tools
   590    600   #
................................................................................
   599    609   SHELL_OPT += -DSQLITE_ENABLE_OFFSET_SQL_FUNC
   600    610   SHELL_OPT += -DSQLITE_ENABLE_DESERIALIZE
   601    611   SHELL_OPT += -DSQLITE_INTROSPECTION_PRAGMAS
   602    612   FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1
   603    613   FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ
   604    614   FUZZCHECK_OPT += -DSQLITE_MAX_MEMORY=50000000
   605    615   FUZZCHECK_OPT += -DSQLITE_PRINTF_PRECISION_LIMIT=1000
          616  +FUZZCHECK_OPT += -DSQLITE_ENABLE_DESERIALIZE
          617  +FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS4
          618  +#FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS5
          619  +FUZZCHECK_OPT += -DSQLITE_ENABLE_RTREE
          620  +FUZZCHECK_OPT += -DSQLITE_ENABLE_GEOPOLY
          621  +FUZZCHECK_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
   606    622   FUZZCHECK_SRC = $(TOP)/test/fuzzcheck.c $(TOP)/test/ossfuzz.c
   607    623   DBFUZZ_OPT =
   608    624   
   609    625   # This is the default Makefile target.  The objects listed here
   610    626   # are what get build when you type just "make" with no arguments.
   611    627   #
   612    628   all:	sqlite3.h libsqlite3.la sqlite3$(TEXE) $(HAVE_TCL:1=libtclsqlite3.la)
................................................................................
   657    673   	$(LTLINK) -o $@ $(FUZZCHECK_OPT) $(FUZZCHECK_SRC) sqlite3.c $(TLIBS)
   658    674   
   659    675   ossshell$(TEXE):	$(TOP)/test/ossfuzz.c $(TOP)/test/ossshell.c sqlite3.c sqlite3.h
   660    676   	$(LTLINK) -o $@ $(FUZZCHECK_OPT) $(TOP)/test/ossshell.c \
   661    677                $(TOP)/test/ossfuzz.c sqlite3.c $(TLIBS)
   662    678   
   663    679   sessionfuzz$(TEXE):	$(TOP)/test/sessionfuzz.c sqlite3.c sqlite3.h
   664         -	$(CC) $(CFLAGS) -I. -o $@ $(TOP)/test/sessionfuzz.c $(TLIBS)
          680  +	$(LTLINK) -o $@ $(TOP)/test/sessionfuzz.c $(TLIBS)
   665    681   
   666    682   dbfuzz$(TEXE):	$(TOP)/test/dbfuzz.c sqlite3.c sqlite3.h
   667    683   	$(LTLINK) -o $@ $(DBFUZZ_OPT) $(TOP)/test/dbfuzz.c sqlite3.c $(TLIBS)
   668    684   
   669    685   DBFUZZ2_OPTS = \
   670    686     -DSQLITE_THREADSAFE=0 \
   671    687     -DSQLITE_OMIT_LOAD_EXTENSION \
   672    688     -DSQLITE_ENABLE_DESERIALIZE \
   673    689     -DSQLITE_DEBUG \
   674    690     -DSQLITE_ENABLE_DBSTAT_VTAB \
   675    691     -DSQLITE_ENABLE_RTREE \
   676    692     -DSQLITE_ENABLE_FTS4 \
   677         -  -DSQLITE_EANBLE_FTS5
          693  +  -DSQLITE_ENABLE_FTS5
   678    694   
   679         -dbfuzz2:	$(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
   680         -	clang-6.0 -I. -g -O0 -fsanitize=fuzzer,undefined -o dbfuzz2 \
   681         -		$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c
          695  +dbfuzz2$(TEXE):	$(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
          696  +	$(CC) $(OPT_FEATURE_FLAGS) $(OPTS) -I. -g -O0 \
          697  +		-DSTANDALONE -o dbfuzz2 \
          698  +		$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c $(TLIBS)
          699  +	mkdir -p dbfuzz2-dir
          700  +	cp $(TOP)/test/dbfuzz2-seed* dbfuzz2-dir
          701  +
          702  +dbfuzz2-asan:	$(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
          703  +	clang-6.0 $(OPT_FEATURE_FLAGS) $(OPTS) -I. -g -O0 \
          704  +		-fsanitize=fuzzer,undefined,address -o dbfuzz2-asan \
          705  +		$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c $(TLIBS)
          706  +	mkdir -p dbfuzz2-dir
          707  +	cp $(TOP)/test/dbfuzz2-seed* dbfuzz2-dir
          708  +
          709  +dbfuzz2-msan:	$(TOP)/test/dbfuzz2.c sqlite3.c sqlite3.h
          710  +	clang-6.0 $(OPT_FEATURE_FLAGS) $(OPTS) -I. -g -O0 \
          711  +		-fsanitize=fuzzer,undefined,memory -o dbfuzz2-msan \
          712  +		$(DBFUZZ2_OPTS) $(TOP)/test/dbfuzz2.c sqlite3.c $(TLIBS)
   682    713   	mkdir -p dbfuzz2-dir
   683    714   	cp $(TOP)/test/dbfuzz2-seed* dbfuzz2-dir
   684    715   
   685    716   mptester$(TEXE):	sqlite3.lo $(TOP)/mptest/mptest.c
   686    717   	$(LTLINK) -o $@ -I. $(TOP)/mptest/mptest.c sqlite3.lo \
   687    718   		$(TLIBS) -rpath "$(libdir)"
   688    719   
................................................................................
  1040   1071   	$(TOP)/ext/misc/shathree.c \
  1041   1072   	$(TOP)/ext/misc/fileio.c \
  1042   1073   	$(TOP)/ext/misc/completion.c \
  1043   1074   	$(TOP)/ext/misc/sqlar.c \
  1044   1075   	$(TOP)/ext/expert/sqlite3expert.c \
  1045   1076   	$(TOP)/ext/expert/sqlite3expert.h \
  1046   1077   	$(TOP)/ext/misc/zipfile.c \
         1078  +	$(TOP)/ext/misc/memtrace.c \
  1047   1079           $(TOP)/src/test_windirent.c
  1048   1080   
  1049   1081   shell.c:	$(SHELL_SRC) $(TOP)/tool/mkshellc.tcl
  1050   1082   	$(TCLSH_CMD) $(TOP)/tool/mkshellc.tcl >shell.c
  1051   1083   
  1052   1084   
  1053   1085   
................................................................................
  1113   1145   
  1114   1146   fts3_write.lo:	$(TOP)/ext/fts3/fts3_write.c $(HDR) $(EXTHDR)
  1115   1147   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/fts3/fts3_write.c
  1116   1148   
  1117   1149   rtree.lo:	$(TOP)/ext/rtree/rtree.c $(HDR) $(EXTHDR)
  1118   1150   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/rtree/rtree.c
  1119   1151   
  1120         -sqlite3session.lo:	$(TOP)/ext/session/sqlite3session.c $(HDR) $(EXTHDR)
         1152  +sqlite3session.lo:	$(TOP)/ext/userauth/userauth.c $(HDR) $(EXTHDR)
         1153  +	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/userauth/userauth.c
         1154  +
         1155  +userauth.lo:	$(TOP)/ext/session/sqlite3session.c $(HDR) $(EXTHDR)
  1121   1156   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/session/sqlite3session.c
  1122   1157   
  1123   1158   json1.lo:	$(TOP)/ext/misc/json1.c
  1124   1159   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/misc/json1.c
  1125   1160   
  1126   1161   stmt.lo:	$(TOP)/ext/misc/stmt.c
  1127   1162   	$(LTCOMPILE) -DSQLITE_CORE -c $(TOP)/ext/misc/stmt.c
................................................................................
  1174   1209   TESTFIXTURE_FLAGS += -DTCLSH_INIT_PROC=sqlite3TestInit
  1175   1210   TESTFIXTURE_FLAGS += -DSQLITE_SERVER=1 -DSQLITE_PRIVATE="" -DSQLITE_CORE
  1176   1211   TESTFIXTURE_FLAGS += -DBUILD_sqlite
  1177   1212   TESTFIXTURE_FLAGS += -DSQLITE_SERIES_CONSTRAINT_VERIFY=1
  1178   1213   TESTFIXTURE_FLAGS += -DSQLITE_DEFAULT_PAGE_SIZE=1024
  1179   1214   TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_STMTVTAB
  1180   1215   TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_DBPAGE_VTAB
         1216  +TESTFIXTURE_FLAGS += -DSQLITE_ENABLE_DESERIALIZE
  1181   1217   
  1182   1218   TESTFIXTURE_SRC0 = $(TESTSRC2) libsqlite3.la
  1183   1219   TESTFIXTURE_SRC1 = sqlite3.c
  1184   1220   TESTFIXTURE_SRC = $(TESTSRC) $(TOP)/src/tclsqlite.c
  1185   1221   TESTFIXTURE_SRC += $(TESTFIXTURE_SRC$(USE_AMALGAMATION))
  1186   1222   
  1187   1223   testfixture$(TEXE):	$(TESTFIXTURE_SRC)
................................................................................
  1275   1311   
  1276   1312   sqlite3_checker$(TEXE):	sqlite3_checker.c
  1277   1313   	$(LTLINK) sqlite3_checker.c -o $@ $(LIBTCL) $(TLIBS)
  1278   1314   
  1279   1315   dbdump$(TEXE): $(TOP)/ext/misc/dbdump.c sqlite3.lo
  1280   1316   	$(LTLINK) -DDBDUMP_STANDALONE -o $@ \
  1281   1317              $(TOP)/ext/misc/dbdump.c sqlite3.lo $(TLIBS)
         1318  +
         1319  +dbtotxt$(TEXE): $(TOP)/tool/dbtotxt.c
         1320  +	$(LTLINK)-o $@ $(TOP)/tool/dbtotxt.c
  1282   1321   
  1283   1322   showdb$(TEXE):	$(TOP)/tool/showdb.c sqlite3.lo
  1284   1323   	$(LTLINK) -o $@ $(TOP)/tool/showdb.c sqlite3.lo $(TLIBS)
  1285   1324   
  1286   1325   showstat4$(TEXE):	$(TOP)/tool/showstat4.c sqlite3.lo
  1287   1326   	$(LTLINK) -o $@ $(TOP)/tool/showstat4.c sqlite3.lo $(TLIBS)
  1288   1327   
................................................................................
  1291   1330   
  1292   1331   showwal$(TEXE):	$(TOP)/tool/showwal.c sqlite3.lo
  1293   1332   	$(LTLINK) -o $@ $(TOP)/tool/showwal.c sqlite3.lo $(TLIBS)
  1294   1333   
  1295   1334   showshm$(TEXE):	$(TOP)/tool/showshm.c
  1296   1335   	$(LTLINK) -o $@ $(TOP)/tool/showshm.c
  1297   1336   
         1337  +index_usage$(TEXE): $(TOP)/tool/index_usage.c sqlite3.lo
         1338  +	$(LTLINK) $(SHELL_OPT) -o $@ $(TOP)/tool/index_usage.c sqlite3.lo $(TLIBS)
         1339  +
  1298   1340   changeset$(TEXE):	$(TOP)/ext/session/changeset.c sqlite3.lo
  1299   1341   	$(LTLINK) -o $@ $(TOP)/ext/session/changeset.c sqlite3.lo $(TLIBS)
  1300   1342   
         1343  +changesetfuzz$(TEXE):	$(TOP)/ext/session/changesetfuzz.c sqlite3.lo
         1344  +	$(LTLINK) -o $@ $(TOP)/ext/session/changesetfuzz.c sqlite3.lo $(TLIBS)
         1345  +
  1301   1346   rollback-test$(TEXE):	$(TOP)/tool/rollback-test.c sqlite3.lo
  1302   1347   	$(LTLINK) -o $@ $(TOP)/tool/rollback-test.c sqlite3.lo $(TLIBS)
  1303   1348   
  1304   1349   atrc$(TEXX): $(TOP)/test/atrc.c sqlite3.lo
  1305   1350   	$(LTLINK) -o $@ $(TOP)/test/atrc.c sqlite3.lo $(TLIBS)
  1306   1351   
  1307   1352   LogEst$(TEXE):	$(TOP)/tool/logest.c sqlite3.h

Changes to Makefile.msc.

   341    341   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_RTREE=1
   342    342   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_GEOPOLY=1
   343    343   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_JSON1=1
   344    344   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
   345    345   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
   346    346   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1
   347    347   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_INTROSPECTION_PRAGMAS=1
          348  +OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DESERIALIZE=1
   348    349   !ENDIF
   349    350   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_COLUMN_METADATA=1
   350    351   !ENDIF
   351    352   
   352    353   # Should the session extension be enabled?  If so, add compilation options
   353    354   # to enable it.
   354    355   #
................................................................................
  1522   1523     $(TOP)\ext\fts5\fts5_test_mi.c \
  1523   1524     $(TOP)\ext\fts5\fts5_test_tok.c \
  1524   1525     $(TOP)\ext\misc\ieee754.c \
  1525   1526     $(TOP)\ext\misc\mmapwarm.c \
  1526   1527     $(TOP)\ext\misc\nextchar.c \
  1527   1528     $(TOP)\ext\misc\normalize.c \
  1528   1529     $(TOP)\ext\misc\percentile.c \
         1530  +  $(TOP)\ext\misc\prefixes.c \
  1529   1531     $(TOP)\ext\misc\regexp.c \
  1530   1532     $(TOP)\ext\misc\remember.c \
  1531   1533     $(TOP)\ext\misc\series.c \
  1532   1534     $(TOP)\ext\misc\spellfix.c \
  1533   1535     $(TOP)\ext\misc\totype.c \
  1534   1536     $(TOP)\ext\misc\unionvtab.c \
  1535   1537     $(TOP)\ext\misc\wholenumber.c
................................................................................
  1620   1622   FUZZDATA = \
  1621   1623     $(TOP)\test\fuzzdata1.db \
  1622   1624     $(TOP)\test\fuzzdata2.db \
  1623   1625     $(TOP)\test\fuzzdata3.db \
  1624   1626     $(TOP)\test\fuzzdata4.db \
  1625   1627     $(TOP)\test\fuzzdata5.db \
  1626   1628     $(TOP)\test\fuzzdata6.db \
  1627         -  $(TOP)\test\fuzzdata7.db
         1629  +  $(TOP)\test\fuzzdata7.db \
         1630  +  $(TOP)\test\fuzzdata8.db
  1628   1631   # <</mark>>
  1629   1632   
  1630   1633   # Additional compiler options for the shell.  These are only effective
  1631   1634   # when the shell is not being dynamically linked.
  1632   1635   #
  1633   1636   !IF $(DYNAMIC_SHELL)==0 && $(FOR_WIN10)==0
  1634   1637   SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_FTS4=1
................................................................................
  1638   1641   !ENDIF
  1639   1642   
  1640   1643   # <<mark>>
  1641   1644   # Extra compiler options for various test tools.
  1642   1645   #
  1643   1646   MPTESTER_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5
  1644   1647   FUZZERSHELL_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1
  1645         -FUZZCHECK_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ -DSQLITE_MAX_MEMORY=50000000 -DSQLITE_PRINTF_PRECISION_LIMIT=1000
         1648  +FUZZCHECK_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ -DSQLITE_MAX_MEMORY=50000000 -DSQLITE_PRINTF_PRECISION_LIMIT=1000
         1649  +FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DESERIALIZE
         1650  +FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_FTS4
         1651  +FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_RTREE
         1652  +FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_GEOPOLY
         1653  +FUZZCHECK_OPTS = $(FUZZCHECK_OPTS) -DSQLITE_ENABLE_DBSTAT_VTAB
         1654  +
  1646   1655   FUZZCHECK_SRC = $(TOP)\test\fuzzcheck.c $(TOP)\test\ossfuzz.c
  1647   1656   OSSSHELL_SRC = $(TOP)\test\ossshell.c $(TOP)\test\ossfuzz.c
  1648   1657   DBFUZZ_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION
  1649   1658   KV_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_DIRECT_OVERFLOW_READ
  1650   1659   ST_COMPILE_OPTS = -DSQLITE_THREADSAFE=0
  1651   1660   
  1652   1661   # Standard options to testfixture.
................................................................................
  1725   1734   fuzzershell.exe:	$(TOP)\tool\fuzzershell.c $(SQLITE3C) $(SQLITE3H)
  1726   1735   	$(LTLINK) $(NO_WARN) $(FUZZERSHELL_COMPILE_OPTS) $(TOP)\tool\fuzzershell.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1727   1736   
  1728   1737   dbfuzz.exe:	$(TOP)\test\dbfuzz.c $(SQLITE3C) $(SQLITE3H)
  1729   1738   	$(LTLINK) $(NO_WARN) $(DBFUZZ_COMPILE_OPTS) $(TOP)\test\dbfuzz.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1730   1739   
  1731   1740   fuzzcheck.exe:	$(FUZZCHECK_SRC) $(SQLITE3C) $(SQLITE3H)
  1732         -	$(LTLINK) $(NO_WARN) $(FUZZCHECK_COMPILE_OPTS) $(FUZZCHECK_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
         1741  +	$(LTLINK) $(NO_WARN) $(FUZZCHECK_OPTS) $(FUZZCHECK_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1733   1742   
  1734   1743   ossshell.exe:	$(OSSSHELL_SRC) $(SQLITE3C) $(SQLITE3H)
  1735         -	$(LTLINK) $(NO_WARN) $(FUZZCHECK_COMPILE_OPTS) $(OSSSHELL_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
         1744  +	$(LTLINK) $(NO_WARN) $(FUZZCHECK_OPTS) $(OSSSHELL_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1736   1745   
  1737   1746   sessionfuzz.exe:	zlib $(TOP)\test\sessionfuzz.c $(SQLITE3C) $(SQLITE3H)
  1738   1747   	$(LTLINK) $(NO_WARN) -I$(ZLIBINCDIR) $(TOP)\test\sessionfuzz.c /link $(LDFLAGS) $(LTLINKOPTS) /LIBPATH:$(ZLIBLIBDIR) $(ZLIBLIB)
  1739   1748   
  1740   1749   mptester.exe:	$(TOP)\mptest\mptest.c $(SQLITE3C) $(SQLITE3H)
  1741   1750   	$(LTLINK) $(NO_WARN) $(MPTESTER_COMPILE_OPTS) $(TOP)\mptest\mptest.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1742   1751   
................................................................................
  2125   2134   	$(TOP)\src\shell.c.in \
  2126   2135   	$(TOP)\ext\misc\appendvfs.c \
  2127   2136   	$(TOP)\ext\misc\shathree.c \
  2128   2137   	$(TOP)\ext\misc\fileio.c \
  2129   2138   	$(TOP)\ext\misc\completion.c \
  2130   2139   	$(TOP)\ext\expert\sqlite3expert.c \
  2131   2140   	$(TOP)\ext\expert\sqlite3expert.h \
         2141  +	$(TOP)\ext\misc\memtrace.c \
  2132   2142   	$(TOP)\src\test_windirent.c
  2133   2143   
  2134   2144   # If use of zlib is enabled, add the "zipfile.c" source file.
  2135   2145   #
  2136   2146   !IF $(USE_ZLIB)!=0
  2137   2147   SHELL_SRC = $(SHELL_SRC) $(TOP)\ext\misc\sqlar.c
  2138   2148   SHELL_SRC = $(SHELL_SRC) $(TOP)\ext\misc\zipfile.c
................................................................................
  2293   2303   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_SERVER=1 -DSQLITE_PRIVATE=""
  2294   2304   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_CORE $(NO_WARN)
  2295   2305   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_SERIES_CONSTRAINT_VERIFY=1
  2296   2306   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_DEFAULT_PAGE_SIZE=1024
  2297   2307   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
  2298   2308   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
  2299   2309   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_JSON1=1
         2310  +TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) -DSQLITE_ENABLE_DESERIALIZE=1
  2300   2311   TESTFIXTURE_FLAGS = $(TESTFIXTURE_FLAGS) $(TEST_CCONV_OPTS)
  2301   2312   
  2302   2313   TESTFIXTURE_SRC0 = $(TESTEXT) $(TESTSRC2)
  2303   2314   TESTFIXTURE_SRC1 = $(TESTEXT) $(SQLITE3C)
  2304   2315   !IF $(USE_AMALGAMATION)==0
  2305   2316   TESTFIXTURE_SRC = $(TESTSRC) $(TOP)\src\tclsqlite.c $(TESTFIXTURE_SRC0)
  2306   2317   !ELSE
................................................................................
  2420   2431   
  2421   2432   testloadext.lo:	$(TOP)\src\test_loadext.c $(SQLITE3H)
  2422   2433   	$(LTCOMPILE) $(NO_WARN) -c $(TOP)\src\test_loadext.c
  2423   2434   
  2424   2435   testloadext.dll:	testloadext.lo
  2425   2436   	$(LD) $(LDFLAGS) $(LTLINKOPTS) $(LTLIBPATHS) /DLL /OUT:$@ testloadext.lo
  2426   2437   
         2438  +dbtotxt.exe:	$(TOP)\tool\dbtotxt.c
         2439  +	$(LTLINK) $(NO_WARN)	$(TOP)\tool\dbtotxt.c /link $(LDFLAGS) $(LTLINKOPTS)
         2440  +
  2427   2441   showdb.exe:	$(TOP)\tool\showdb.c $(SQLITE3C) $(SQLITE3H)
  2428   2442   	$(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
  2429   2443   		$(TOP)\tool\showdb.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  2430   2444   
  2431   2445   showstat4.exe:	$(TOP)\tool\showstat4.c $(SQLITE3C) $(SQLITE3H)
  2432   2446   	$(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
  2433   2447   		$(TOP)\tool\showstat4.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
................................................................................
  2439   2453   showwal.exe:	$(TOP)\tool\showwal.c $(SQLITE3C) $(SQLITE3H)
  2440   2454   	$(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
  2441   2455   		$(TOP)\tool\showwal.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  2442   2456   
  2443   2457   showshm.exe:	$(TOP)\tool\showshm.c
  2444   2458   	$(LTLINK) $(NO_WARN)	$(TOP)\tool\showshm.c /link $(LDFLAGS) $(LTLINKOPTS)
  2445   2459   
         2460  +index_usage.exe: $(TOP)\tool\index_usage.c $(SQLITE3C) $(SQLITE3H)
         2461  +	$(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
         2462  +		$(TOP)\tool\index_usage.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
         2463  +
  2446   2464   changeset.exe:	$(TOP)\ext\session\changeset.c $(SQLITE3C) $(SQLITE3H)
  2447   2465   	$(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
  2448   2466   		-DSQLITE_ENABLE_SESSION=1 -DSQLITE_ENABLE_PREUPDATE_HOOK=1 \
  2449   2467   		$(TOP)\ext\session\changeset.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  2450   2468   
         2469  +changesetfuzz.exe:	$(TOP)\ext\session\changesetfuzz.c $(SQLITE3C) $(SQLITE3H)
         2470  +	$(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
         2471  +		-DSQLITE_ENABLE_SESSION=1 -DSQLITE_ENABLE_PREUPDATE_HOOK=1 \
         2472  +		$(TOP)\ext\session\changesetfuzz.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
         2473  +
  2451   2474   fts3view.exe:	$(TOP)\ext\fts3\tool\fts3view.c $(SQLITE3C) $(SQLITE3H)
  2452   2475   	$(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
  2453   2476   		$(TOP)\ext\fts3\tool\fts3view.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  2454   2477   
  2455   2478   rollback-test.exe:	$(TOP)\tool\rollback-test.c $(SQLITE3C) $(SQLITE3H)
  2456   2479   	$(LTLINK) $(NO_WARN) -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION \
  2457   2480   		$(TOP)\tool\rollback-test.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)

Changes to VERSION.

     1         -3.26.0
            1  +3.27.0

Changes to autoconf/Makefile.msc.

   279    279   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_RTREE=1
   280    280   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_GEOPOLY=1
   281    281   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_JSON1=1
   282    282   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_STMTVTAB=1
   283    283   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBPAGE_VTAB=1
   284    284   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DBSTAT_VTAB=1
   285    285   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_INTROSPECTION_PRAGMAS=1
          286  +OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_DESERIALIZE=1
   286    287   !ENDIF
   287    288   OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_COLUMN_METADATA=1
   288    289   !ENDIF
   289    290   
   290    291   # Should the session extension be enabled?  If so, add compilation options
   291    292   # to enable it.
   292    293   #
................................................................................
   933    934   # Additional compiler options for the shell.  These are only effective
   934    935   # when the shell is not being dynamically linked.
   935    936   #
   936    937   !IF $(DYNAMIC_SHELL)==0 && $(FOR_WIN10)==0
   937    938   SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_FTS4=1
   938    939   SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_EXPLAIN_COMMENTS=1
   939    940   SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_OFFSET_SQL_FUNC=1
          941  +SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_DESERIALIZE=1
   940    942   !ENDIF
   941    943   
   942    944   
   943    945   # This is the default Makefile target.  The objects listed here
   944    946   # are what get build when you type just "make" with no arguments.
   945    947   #
   946    948   core:	dll shell

Changes to configure.

     1      1   #! /bin/sh
     2      2   # Guess values for system-dependent variables and create Makefiles.
     3         -# Generated by GNU Autoconf 2.69 for sqlite 3.26.0.
            3  +# Generated by GNU Autoconf 2.69 for sqlite 3.27.0.
     4      4   #
     5      5   #
     6      6   # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
     7      7   #
     8      8   #
     9      9   # This configure script is free software; the Free Software Foundation
    10     10   # gives unlimited permission to copy, distribute and modify it.
................................................................................
   722    722   subdirs=
   723    723   MFLAGS=
   724    724   MAKEFLAGS=
   725    725   
   726    726   # Identity of this package.
   727    727   PACKAGE_NAME='sqlite'
   728    728   PACKAGE_TARNAME='sqlite'
   729         -PACKAGE_VERSION='3.26.0'
   730         -PACKAGE_STRING='sqlite 3.26.0'
          729  +PACKAGE_VERSION='3.27.0'
          730  +PACKAGE_STRING='sqlite 3.27.0'
   731    731   PACKAGE_BUGREPORT=''
   732    732   PACKAGE_URL=''
   733    733   
   734    734   # Factoring default headers for most tests.
   735    735   ac_includes_default="\
   736    736   #include <stdio.h>
   737    737   #ifdef HAVE_SYS_TYPES_H
................................................................................
  1462   1462   #
  1463   1463   # Report the --help message.
  1464   1464   #
  1465   1465   if test "$ac_init_help" = "long"; then
  1466   1466     # Omit some internal or obsolete options to make the list less imposing.
  1467   1467     # This message is too long to be a string in the A/UX 3.1 sh.
  1468   1468     cat <<_ACEOF
  1469         -\`configure' configures sqlite 3.26.0 to adapt to many kinds of systems.
         1469  +\`configure' configures sqlite 3.27.0 to adapt to many kinds of systems.
  1470   1470   
  1471   1471   Usage: $0 [OPTION]... [VAR=VALUE]...
  1472   1472   
  1473   1473   To assign environment variables (e.g., CC, CFLAGS...), specify them as
  1474   1474   VAR=VALUE.  See below for descriptions of some of the useful variables.
  1475   1475   
  1476   1476   Defaults for the options are specified in brackets.
................................................................................
  1527   1527     --build=BUILD     configure for building on BUILD [guessed]
  1528   1528     --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  1529   1529   _ACEOF
  1530   1530   fi
  1531   1531   
  1532   1532   if test -n "$ac_init_help"; then
  1533   1533     case $ac_init_help in
  1534         -     short | recursive ) echo "Configuration of sqlite 3.26.0:";;
         1534  +     short | recursive ) echo "Configuration of sqlite 3.27.0:";;
  1535   1535      esac
  1536   1536     cat <<\_ACEOF
  1537   1537   
  1538   1538   Optional Features:
  1539   1539     --disable-option-checking  ignore unrecognized --enable/--with options
  1540   1540     --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  1541   1541     --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
................................................................................
  1653   1653       cd "$ac_pwd" || { ac_status=$?; break; }
  1654   1654     done
  1655   1655   fi
  1656   1656   
  1657   1657   test -n "$ac_init_help" && exit $ac_status
  1658   1658   if $ac_init_version; then
  1659   1659     cat <<\_ACEOF
  1660         -sqlite configure 3.26.0
         1660  +sqlite configure 3.27.0
  1661   1661   generated by GNU Autoconf 2.69
  1662   1662   
  1663   1663   Copyright (C) 2012 Free Software Foundation, Inc.
  1664   1664   This configure script is free software; the Free Software Foundation
  1665   1665   gives unlimited permission to copy, distribute and modify it.
  1666   1666   _ACEOF
  1667   1667     exit
................................................................................
  2072   2072     eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  2073   2073   
  2074   2074   } # ac_fn_c_check_header_mongrel
  2075   2075   cat >config.log <<_ACEOF
  2076   2076   This file contains any messages produced by compilers while
  2077   2077   running configure, to aid debugging if configure makes a mistake.
  2078   2078   
  2079         -It was created by sqlite $as_me 3.26.0, which was
         2079  +It was created by sqlite $as_me 3.27.0, which was
  2080   2080   generated by GNU Autoconf 2.69.  Invocation command line was
  2081   2081   
  2082   2082     $ $0 $@
  2083   2083   
  2084   2084   _ACEOF
  2085   2085   exec 5>>config.log
  2086   2086   {
................................................................................
 12228  12228   test $as_write_fail = 0 && chmod +x $CONFIG_STATUS || ac_write_fail=1
 12229  12229   
 12230  12230   cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
 12231  12231   # Save the log message, to keep $0 and so on meaningful, and to
 12232  12232   # report actual input values of CONFIG_FILES etc. instead of their
 12233  12233   # values after options handling.
 12234  12234   ac_log="
 12235         -This file was extended by sqlite $as_me 3.26.0, which was
        12235  +This file was extended by sqlite $as_me 3.27.0, which was
 12236  12236   generated by GNU Autoconf 2.69.  Invocation command line was
 12237  12237   
 12238  12238     CONFIG_FILES    = $CONFIG_FILES
 12239  12239     CONFIG_HEADERS  = $CONFIG_HEADERS
 12240  12240     CONFIG_LINKS    = $CONFIG_LINKS
 12241  12241     CONFIG_COMMANDS = $CONFIG_COMMANDS
 12242  12242     $ $0 $@
................................................................................
 12294  12294   
 12295  12295   Report bugs to the package provider."
 12296  12296   
 12297  12297   _ACEOF
 12298  12298   cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 12299  12299   ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 12300  12300   ac_cs_version="\\
 12301         -sqlite config.status 3.26.0
        12301  +sqlite config.status 3.27.0
 12302  12302   configured by $0, generated by GNU Autoconf 2.69,
 12303  12303     with options \\"\$ac_cs_config\\"
 12304  12304   
 12305  12305   Copyright (C) 2012 Free Software Foundation, Inc.
 12306  12306   This config.status script is free software; the Free Software Foundation
 12307  12307   gives unlimited permission to copy, distribute and modify it."
 12308  12308   

Changes to doc/lemon.html.

   772    772   
   773    773   <p><pre>
   774    774      %include {#include &lt;unistd.h&gt;}
   775    775   </pre></p>
   776    776   
   777    777   <p>This might be needed, for example, if some of the C actions in the
   778    778   grammar call functions that are prototyped in unistd.h.</p>
          779  +
          780  +<p>Use the <tt><a href="#pcode">%code</a></tt> directive to add code to
          781  +the end of the generated parser.</p>
   779    782   
   780    783   <a name='pleft'></a>
   781    784   <h4>The <tt>%left</tt> directive</h4>
   782    785   
   783    786   The <tt>%left</tt> directive is used (along with the
   784    787   <tt><a href='#pright'>%right</a></tt> and
   785    788   <tt><a href='#pnonassoc'>%nonassoc</a></tt> directives) to declare

Changes to ext/expert/expert1.test.

   239    239     CREATE TABLE t7(a, b);
   240    240   } {
   241    241     SELECT * FROM t7 WHERE a=? OR b=?
   242    242   } {
   243    243     CREATE INDEX t7_idx_00000062 ON t7(b);
   244    244     CREATE INDEX t7_idx_00000061 ON t7(a);
   245    245     MULTI-INDEX OR
   246         -    SEARCH TABLE t7 USING INDEX t7_idx_00000061 (a=?) 
   247         -    SEARCH TABLE t7 USING INDEX t7_idx_00000062 (b=?)
          246  +    INDEX 1
          247  +      SEARCH TABLE t7 USING INDEX t7_idx_00000061 (a=?) 
          248  +    INDEX 2
          249  +      SEARCH TABLE t7 USING INDEX t7_idx_00000062 (b=?)
   248    250   }
   249    251   
   250    252   # rowid terms.
   251    253   #
   252    254   do_setup_rec_test $tn.13.1 {
   253    255     CREATE TABLE t8(a, b);
   254    256   } {

Changes to ext/expert/sqlite3expert.c.

   640    640       0,                            /* xCommit - commit transaction */
   641    641       0,                            /* xRollback - rollback transaction */
   642    642       0,                            /* xFindFunction - function overloading */
   643    643       0,                            /* xRename - rename the table */
   644    644       0,                            /* xSavepoint */
   645    645       0,                            /* xRelease */
   646    646       0,                            /* xRollbackTo */
          647  +    0,                            /* xShadowName */
   647    648     };
   648    649   
   649    650     return sqlite3_create_module(p->dbv, "expert", &expertModule, (void*)p);
   650    651   }
   651    652   /*
   652    653   ** End of virtual table implementation.
   653    654   *************************************************************************/

Changes to ext/fts3/fts3.c.

   316    316   #ifndef SQLITE_AMALGAMATION
   317    317   # if defined(SQLITE_DEBUG)
   318    318   int sqlite3Fts3Always(int b) { assert( b ); return b; }
   319    319   int sqlite3Fts3Never(int b)  { assert( !b ); return b; }
   320    320   # endif
   321    321   #endif
   322    322   
          323  +/*
          324  +** This variable is set to false when running tests for which the on disk
          325  +** structures should not be corrupt. Otherwise, true. If it is false, extra
          326  +** assert() conditions in the fts3 code are activated - conditions that are
          327  +** only true if it is guaranteed that the fts3 database is not corrupt.
          328  +*/
          329  +int sqlite3_fts3_may_be_corrupt = 1;
          330  +
   323    331   /* 
   324    332   ** Write a 64-bit variable-length integer to memory starting at p[0].
   325    333   ** The length of data written will be between 1 and FTS3_VARINT_MAX bytes.
   326    334   ** The number of bytes written is returned.
   327    335   */
   328    336   int sqlite3Fts3PutVarint(char *p, sqlite_int64 v){
   329    337     unsigned char *q = (unsigned char *) p;
................................................................................
   334    342     }while( vu!=0 );
   335    343     q[-1] &= 0x7f;  /* turn off high bit in final byte */
   336    344     assert( q - (unsigned char *)p <= FTS3_VARINT_MAX );
   337    345     return (int) (q - (unsigned char *)p);
   338    346   }
   339    347   
   340    348   #define GETVARINT_STEP(v, ptr, shift, mask1, mask2, var, ret) \
   341         -  v = (v & mask1) | ( (*ptr++) << shift );                    \
          349  +  v = (v & mask1) | ( (*(const unsigned char*)(ptr++)) << shift );  \
   342    350     if( (v & mask2)==0 ){ var = v; return ret; }
   343    351   #define GETVARINT_INIT(v, ptr, shift, mask1, mask2, var, ret) \
   344    352     v = (*ptr++);                                               \
   345    353     if( (v & mask2)==0 ){ var = v; return ret; }
   346    354   
   347    355   /* 
   348    356   ** Read a 64-bit variable-length integer from memory starting at p[0].
................................................................................
   372    380   }
   373    381   
   374    382   /*
   375    383   ** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to 
   376    384   ** a non-negative 32-bit integer before it is returned.
   377    385   */
   378    386   int sqlite3Fts3GetVarint32(const char *p, int *pi){
          387  +  const unsigned char *ptr = (const unsigned char*)p;
   379    388     u32 a;
   380    389   
   381    390   #ifndef fts3GetVarint32
   382         -  GETVARINT_INIT(a, p, 0,  0x00,     0x80, *pi, 1);
          391  +  GETVARINT_INIT(a, ptr, 0,  0x00,     0x80, *pi, 1);
   383    392   #else
   384         -  a = (*p++);
          393  +  a = (*ptr++);
   385    394     assert( a & 0x80 );
   386    395   #endif
   387    396   
   388         -  GETVARINT_STEP(a, p, 7,  0x7F,     0x4000, *pi, 2);
   389         -  GETVARINT_STEP(a, p, 14, 0x3FFF,   0x200000, *pi, 3);
   390         -  GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4);
          397  +  GETVARINT_STEP(a, ptr, 7,  0x7F,     0x4000, *pi, 2);
          398  +  GETVARINT_STEP(a, ptr, 14, 0x3FFF,   0x200000, *pi, 3);
          399  +  GETVARINT_STEP(a, ptr, 21, 0x1FFFFF, 0x10000000, *pi, 4);
   391    400     a = (a & 0x0FFFFFFF );
   392         -  *pi = (int)(a | ((u32)(*p & 0x07) << 28));
          401  +  *pi = (int)(a | ((u32)(*ptr & 0x07) << 28));
   393    402     assert( 0==(a & 0x80000000) );
   394    403     assert( *pi>=0 );
   395    404     return 5;
   396    405   }
   397    406   
   398    407   /*
   399    408   ** Return the number of bytes required to encode v as a varint
................................................................................
   556    565   static int fts3DestroyMethod(sqlite3_vtab *pVtab){
   557    566     Fts3Table *p = (Fts3Table *)pVtab;
   558    567     int rc = SQLITE_OK;              /* Return code */
   559    568     const char *zDb = p->zDb;        /* Name of database (e.g. "main", "temp") */
   560    569     sqlite3 *db = p->db;             /* Database handle */
   561    570   
   562    571     /* Drop the shadow tables */
   563         -  if( p->zContentTbl==0 ){
   564         -    fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_content'", zDb, p->zName);
   565         -  }
   566         -  fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segments'", zDb,p->zName);
   567         -  fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segdir'", zDb, p->zName);
   568         -  fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_docsize'", zDb, p->zName);
   569         -  fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_stat'", zDb, p->zName);
          572  +  fts3DbExec(&rc, db, 
          573  +    "DROP TABLE IF EXISTS %Q.'%q_segments';"
          574  +    "DROP TABLE IF EXISTS %Q.'%q_segdir';"
          575  +    "DROP TABLE IF EXISTS %Q.'%q_docsize';"
          576  +    "DROP TABLE IF EXISTS %Q.'%q_stat';"
          577  +    "%s DROP TABLE IF EXISTS %Q.'%q_content';",
          578  +    zDb, p->zName,
          579  +    zDb, p->zName,
          580  +    zDb, p->zName,
          581  +    zDb, p->zName,
          582  +    (p->zContentTbl ? "--" : ""), zDb,p->zName
          583  +  );
   570    584   
   571    585     /* If everything has worked, invoke fts3DisconnectMethod() to free the
   572    586     ** memory associated with the Fts3Table structure and return SQLITE_OK.
   573    587     ** Otherwise, return an SQLite error code.
   574    588     */
   575    589     return (rc==SQLITE_OK ? fts3DisconnectMethod(pVtab) : rc);
   576    590   }
................................................................................
   794    808   **     fts3QuoteId("un \"zip\"")   ->    "un \"\"zip\"\""
   795    809   **
   796    810   ** The pointer returned points to memory obtained from sqlite3_malloc(). It
   797    811   ** is the callers responsibility to call sqlite3_free() to release this
   798    812   ** memory.
   799    813   */
   800    814   static char *fts3QuoteId(char const *zInput){
   801         -  int nRet;
          815  +  sqlite3_int64 nRet;
   802    816     char *zRet;
   803    817     nRet = 2 + (int)strlen(zInput)*2 + 1;
   804         -  zRet = sqlite3_malloc(nRet);
          818  +  zRet = sqlite3_malloc64(nRet);
   805    819     if( zRet ){
   806    820       int i;
   807    821       char *z = zRet;
   808    822       *(z++) = '"';
   809    823       for(i=0; zInput[i]; i++){
   810    824         if( zInput[i]=='"' ) *(z++) = '"';
   811    825         *(z++) = zInput[i];
................................................................................
   978    992       const char *p;
   979    993       nIndex++;
   980    994       for(p=zParam; *p; p++){
   981    995         if( *p==',' ) nIndex++;
   982    996       }
   983    997     }
   984    998   
   985         -  aIndex = sqlite3_malloc(sizeof(struct Fts3Index) * nIndex);
          999  +  aIndex = sqlite3_malloc64(sizeof(struct Fts3Index) * nIndex);
   986   1000     *apIndex = aIndex;
   987   1001     if( !aIndex ){
   988   1002       return SQLITE_NOMEM;
   989   1003     }
   990   1004   
   991   1005     memset(aIndex, 0, sizeof(struct Fts3Index) * nIndex);
   992   1006     if( zParam ){
................................................................................
  1057   1071         sqlite3Fts3ErrMsg(pzErr, "%s", sqlite3_errmsg(db));
  1058   1072       }
  1059   1073     }
  1060   1074     sqlite3_free(zSql);
  1061   1075   
  1062   1076     if( rc==SQLITE_OK ){
  1063   1077       const char **azCol;           /* Output array */
  1064         -    int nStr = 0;                 /* Size of all column names (incl. 0x00) */
         1078  +    sqlite3_int64 nStr = 0;       /* Size of all column names (incl. 0x00) */
  1065   1079       int nCol;                     /* Number of table columns */
  1066   1080       int i;                        /* Used to iterate through columns */
  1067   1081   
  1068   1082       /* Loop through the returned columns. Set nStr to the number of bytes of
  1069   1083       ** space required to store a copy of each column name, including the
  1070   1084       ** nul-terminator byte.  */
  1071   1085       nCol = sqlite3_column_count(pStmt);
  1072   1086       for(i=0; i<nCol; i++){
  1073   1087         const char *zCol = sqlite3_column_name(pStmt, i);
  1074         -      nStr += (int)strlen(zCol) + 1;
         1088  +      nStr += strlen(zCol) + 1;
  1075   1089       }
  1076   1090   
  1077   1091       /* Allocate and populate the array to return. */
  1078         -    azCol = (const char **)sqlite3_malloc(sizeof(char *) * nCol + nStr);
         1092  +    azCol = (const char **)sqlite3_malloc64(sizeof(char *) * nCol + nStr);
  1079   1093       if( azCol==0 ){
  1080   1094         rc = SQLITE_NOMEM;
  1081   1095       }else{
  1082   1096         char *p = (char *)&azCol[nCol];
  1083   1097         for(i=0; i<nCol; i++){
  1084   1098           const char *zCol = sqlite3_column_name(pStmt, i);
  1085   1099           int n = (int)strlen(zCol)+1;
................................................................................
  1119   1133     sqlite3_vtab **ppVTab,          /* Write the resulting vtab structure here */
  1120   1134     char **pzErr                    /* Write any error message here */
  1121   1135   ){
  1122   1136     Fts3Hash *pHash = (Fts3Hash *)pAux;
  1123   1137     Fts3Table *p = 0;               /* Pointer to allocated vtab */
  1124   1138     int rc = SQLITE_OK;             /* Return code */
  1125   1139     int i;                          /* Iterator variable */
  1126         -  int nByte;                      /* Size of allocation used for *p */
         1140  +  sqlite3_int64 nByte;            /* Size of allocation used for *p */
  1127   1141     int iCol;                       /* Column index */
  1128   1142     int nString = 0;                /* Bytes required to hold all column names */
  1129   1143     int nCol = 0;                   /* Number of columns in the FTS table */
  1130   1144     char *zCsr;                     /* Space for holding column names */
  1131   1145     int nDb;                        /* Bytes required to hold database name */
  1132   1146     int nName;                      /* Bytes required to hold table name */
  1133   1147     int isFts4 = (argv[0][3]=='4'); /* True for FTS4, false for FTS3 */
................................................................................
  1153   1167          || (sqlite3_strnicmp(argv[0], "fts3", 4)==0 && !isFts4)
  1154   1168     );
  1155   1169   
  1156   1170     nDb = (int)strlen(argv[1]) + 1;
  1157   1171     nName = (int)strlen(argv[2]) + 1;
  1158   1172   
  1159   1173     nByte = sizeof(const char *) * (argc-2);
  1160         -  aCol = (const char **)sqlite3_malloc(nByte);
         1174  +  aCol = (const char **)sqlite3_malloc64(nByte);
  1161   1175     if( aCol ){
  1162   1176       memset((void*)aCol, 0, nByte);
  1163         -    azNotindexed = (char **)sqlite3_malloc(nByte);
         1177  +    azNotindexed = (char **)sqlite3_malloc64(nByte);
  1164   1178     }
  1165   1179     if( azNotindexed ){
  1166   1180       memset(azNotindexed, 0, nByte);
  1167   1181     }
  1168   1182     if( !aCol || !azNotindexed ){
  1169   1183       rc = SQLITE_NOMEM;
  1170   1184       goto fts3_init_out;
................................................................................
  1351   1365     nByte = sizeof(Fts3Table) +                  /* Fts3Table */
  1352   1366             nCol * sizeof(char *) +              /* azColumn */
  1353   1367             nIndex * sizeof(struct Fts3Index) +  /* aIndex */
  1354   1368             nCol * sizeof(u8) +                  /* abNotindexed */
  1355   1369             nName +                              /* zName */
  1356   1370             nDb +                                /* zDb */
  1357   1371             nString;                             /* Space for azColumn strings */
  1358         -  p = (Fts3Table*)sqlite3_malloc(nByte);
         1372  +  p = (Fts3Table*)sqlite3_malloc64(nByte);
  1359   1373     if( p==0 ){
  1360   1374       rc = SQLITE_NOMEM;
  1361   1375       goto fts3_init_out;
  1362   1376     }
  1363   1377     memset(p, 0, nByte);
  1364   1378     p->db = db;
  1365   1379     p->nColumn = nCol;
................................................................................
  2130   2144   /*
  2131   2145   ** Compute the union of two position lists.  The output written
  2132   2146   ** into *pp contains all positions of both *pp1 and *pp2 in sorted
  2133   2147   ** order and with any duplicates removed.  All pointers are
  2134   2148   ** updated appropriately.   The caller is responsible for insuring
  2135   2149   ** that there is enough space in *pp to hold the complete output.
  2136   2150   */
  2137         -static void fts3PoslistMerge(
         2151  +static int fts3PoslistMerge(
  2138   2152     char **pp,                      /* Output buffer */
  2139   2153     char **pp1,                     /* Left input list */
  2140   2154     char **pp2                      /* Right input list */
  2141   2155   ){
  2142   2156     char *p = *pp;
  2143   2157     char *p1 = *pp1;
  2144   2158     char *p2 = *pp2;
  2145   2159   
  2146   2160     while( *p1 || *p2 ){
  2147   2161       int iCol1;         /* The current column index in pp1 */
  2148   2162       int iCol2;         /* The current column index in pp2 */
  2149   2163   
  2150         -    if( *p1==POS_COLUMN ) fts3GetVarint32(&p1[1], &iCol1);
         2164  +    if( *p1==POS_COLUMN ){ 
         2165  +      fts3GetVarint32(&p1[1], &iCol1);
         2166  +      if( iCol1==0 ) return FTS_CORRUPT_VTAB;
         2167  +    }
  2151   2168       else if( *p1==POS_END ) iCol1 = POSITION_LIST_END;
  2152   2169       else iCol1 = 0;
  2153   2170   
  2154         -    if( *p2==POS_COLUMN ) fts3GetVarint32(&p2[1], &iCol2);
         2171  +    if( *p2==POS_COLUMN ){
         2172  +      fts3GetVarint32(&p2[1], &iCol2);
         2173  +      if( iCol2==0 ) return FTS_CORRUPT_VTAB;
         2174  +    }
  2155   2175       else if( *p2==POS_END ) iCol2 = POSITION_LIST_END;
  2156   2176       else iCol2 = 0;
  2157   2177   
  2158   2178       if( iCol1==iCol2 ){
  2159   2179         sqlite3_int64 i1 = 0;       /* Last position from pp1 */
  2160   2180         sqlite3_int64 i2 = 0;       /* Last position from pp2 */
  2161   2181         sqlite3_int64 iPrev = 0;
................................................................................
  2195   2215       }
  2196   2216     }
  2197   2217   
  2198   2218     *p++ = POS_END;
  2199   2219     *pp = p;
  2200   2220     *pp1 = p1 + 1;
  2201   2221     *pp2 = p2 + 1;
         2222  +  return SQLITE_OK;
  2202   2223   }
  2203   2224   
  2204   2225   /*
  2205   2226   ** This function is used to merge two position lists into one. When it is
  2206   2227   ** called, *pp1 and *pp2 must both point to position lists. A position-list is
  2207   2228   ** the part of a doclist that follows each document id. For example, if a row
  2208   2229   ** contains:
................................................................................
  2259   2280         sqlite3_int64 iPos2 = 0;
  2260   2281   
  2261   2282         if( iCol1 ){
  2262   2283           *p++ = POS_COLUMN;
  2263   2284           p += sqlite3Fts3PutVarint(p, iCol1);
  2264   2285         }
  2265   2286   
  2266         -      assert( *p1!=POS_END && *p1!=POS_COLUMN );
  2267         -      assert( *p2!=POS_END && *p2!=POS_COLUMN );
  2268   2287         fts3GetDeltaVarint(&p1, &iPos1); iPos1 -= 2;
  2269   2288         fts3GetDeltaVarint(&p2, &iPos2); iPos2 -= 2;
         2289  +      if( iPos1<0 || iPos2<0 ) break;
  2270   2290   
  2271   2291         while( 1 ){
  2272   2292           if( iPos2==iPos1+nToken 
  2273   2293            || (isExact==0 && iPos2>iPos1 && iPos2<=iPos1+nToken) 
  2274   2294           ){
  2275   2295             sqlite3_int64 iSave;
  2276   2296             iSave = isSaveLeft ? iPos1 : iPos2;
................................................................................
  2488   2508   */
  2489   2509   static int fts3DoclistOrMerge(
  2490   2510     int bDescDoclist,               /* True if arguments are desc */
  2491   2511     char *a1, int n1,               /* First doclist */
  2492   2512     char *a2, int n2,               /* Second doclist */
  2493   2513     char **paOut, int *pnOut        /* OUT: Malloc'd doclist */
  2494   2514   ){
         2515  +  int rc = SQLITE_OK;
  2495   2516     sqlite3_int64 i1 = 0;
  2496   2517     sqlite3_int64 i2 = 0;
  2497   2518     sqlite3_int64 iPrev = 0;
  2498   2519     char *pEnd1 = &a1[n1];
  2499   2520     char *pEnd2 = &a2[n2];
  2500   2521     char *p1 = a1;
  2501   2522     char *p2 = a2;
................................................................................
  2531   2552     ** The space required to store the output is therefore the sum of the
  2532   2553     ** sizes of the two inputs, plus enough space for exactly one of the input
  2533   2554     ** docids to grow. 
  2534   2555     **
  2535   2556     ** A symetric argument may be made if the doclists are in descending 
  2536   2557     ** order.
  2537   2558     */
  2538         -  aOut = sqlite3_malloc(n1+n2+FTS3_VARINT_MAX-1);
         2559  +  aOut = sqlite3_malloc64((i64)n1+n2+FTS3_VARINT_MAX-1+FTS3_BUFFER_PADDING);
  2539   2560     if( !aOut ) return SQLITE_NOMEM;
  2540   2561   
  2541   2562     p = aOut;
  2542   2563     fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
  2543   2564     fts3GetDeltaVarint3(&p2, pEnd2, 0, &i2);
  2544   2565     while( p1 || p2 ){
  2545   2566       sqlite3_int64 iDiff = DOCID_CMP(i1, i2);
  2546   2567   
  2547   2568       if( p2 && p1 && iDiff==0 ){
  2548   2569         fts3PutDeltaVarint3(&p, bDescDoclist, &iPrev, &bFirstOut, i1);
  2549         -      fts3PoslistMerge(&p, &p1, &p2);
         2570  +      rc = fts3PoslistMerge(&p, &p1, &p2);
         2571  +      if( rc ) break;
  2550   2572         fts3GetDeltaVarint3(&p1, pEnd1, bDescDoclist, &i1);
  2551   2573         fts3GetDeltaVarint3(&p2, pEnd2, bDescDoclist, &i2);
  2552   2574       }else if( !p2 || (p1 && iDiff<0) ){
  2553   2575         fts3PutDeltaVarint3(&p, bDescDoclist, &iPrev, &bFirstOut, i1);
  2554   2576         fts3PoslistCopy(&p, &p1);
  2555   2577         fts3GetDeltaVarint3(&p1, pEnd1, bDescDoclist, &i1);
  2556   2578       }else{
  2557   2579         fts3PutDeltaVarint3(&p, bDescDoclist, &iPrev, &bFirstOut, i2);
  2558   2580         fts3PoslistCopy(&p, &p2);
  2559   2581         fts3GetDeltaVarint3(&p2, pEnd2, bDescDoclist, &i2);
  2560   2582       }
  2561   2583     }
  2562   2584   
         2585  +  if( rc!=SQLITE_OK ){
         2586  +    sqlite3_free(aOut);
         2587  +    p = aOut = 0;
         2588  +  }else{
         2589  +    assert( (p-aOut)<=n1+n2+FTS3_VARINT_MAX-1 );
         2590  +    memset(&aOut[(p-aOut)], 0, FTS3_BUFFER_PADDING);
         2591  +  }
  2563   2592     *paOut = aOut;
  2564   2593     *pnOut = (int)(p-aOut);
  2565         -  assert( *pnOut<=n1+n2+FTS3_VARINT_MAX-1 );
  2566         -  return SQLITE_OK;
         2594  +  return rc;
  2567   2595   }
  2568   2596   
  2569   2597   /*
  2570   2598   ** This function does a "phrase" merge of two doclists. In a phrase merge,
  2571   2599   ** the output contains a copy of each position from the right-hand input
  2572   2600   ** doclist for which there is a position in the left-hand input doclist
  2573   2601   ** exactly nDist tokens before it.
................................................................................
  2594   2622     char *p2 = aRight;
  2595   2623     char *p;
  2596   2624     int bFirstOut = 0;
  2597   2625     char *aOut;
  2598   2626   
  2599   2627     assert( nDist>0 );
  2600   2628     if( bDescDoclist ){
  2601         -    aOut = sqlite3_malloc(*pnRight + FTS3_VARINT_MAX);
         2629  +    aOut = sqlite3_malloc64((sqlite3_int64)*pnRight + FTS3_VARINT_MAX);
  2602   2630       if( aOut==0 ) return SQLITE_NOMEM;
  2603   2631     }else{
  2604   2632       aOut = aRight;
  2605   2633     }
  2606   2634     p = aOut;
  2607   2635   
  2608   2636     fts3GetDeltaVarint3(&p1, pEnd1, 0, &i1);
................................................................................
  2778   2806       **
  2779   2807       ** Similar padding is added in the fts3DoclistOrMerge() function.
  2780   2808       */
  2781   2809       pTS->aaOutput[0] = sqlite3_malloc(nDoclist + FTS3_VARINT_MAX + 1);
  2782   2810       pTS->anOutput[0] = nDoclist;
  2783   2811       if( pTS->aaOutput[0] ){
  2784   2812         memcpy(pTS->aaOutput[0], aDoclist, nDoclist);
         2813  +      memset(&pTS->aaOutput[0][nDoclist], 0, FTS3_VARINT_MAX);
  2785   2814       }else{
  2786   2815         return SQLITE_NOMEM;
  2787   2816       }
  2788   2817     }else{
  2789   2818       char *aMerge = aDoclist;
  2790   2819       int nMerge = nDoclist;
  2791   2820       int iOut;
................................................................................
  2829   2858   */
  2830   2859   static int fts3SegReaderCursorAppend(
  2831   2860     Fts3MultiSegReader *pCsr, 
  2832   2861     Fts3SegReader *pNew
  2833   2862   ){
  2834   2863     if( (pCsr->nSegment%16)==0 ){
  2835   2864       Fts3SegReader **apNew;
  2836         -    int nByte = (pCsr->nSegment + 16)*sizeof(Fts3SegReader*);
  2837         -    apNew = (Fts3SegReader **)sqlite3_realloc(pCsr->apSegment, nByte);
         2865  +    sqlite3_int64 nByte = (pCsr->nSegment + 16)*sizeof(Fts3SegReader*);
         2866  +    apNew = (Fts3SegReader **)sqlite3_realloc64(pCsr->apSegment, nByte);
  2838   2867       if( !apNew ){
  2839   2868         sqlite3Fts3SegReaderFree(pNew);
  2840   2869         return SQLITE_NOMEM;
  2841   2870       }
  2842   2871       pCsr->apSegment = apNew;
  2843   2872     }
  2844   2873     pCsr->apSegment[pCsr->nSegment++] = pNew;
................................................................................
  2894   2923         sqlite3_int64 iLeavesEndBlock = sqlite3_column_int64(pStmt, 2);
  2895   2924         sqlite3_int64 iEndBlock = sqlite3_column_int64(pStmt, 3);
  2896   2925         int nRoot = sqlite3_column_bytes(pStmt, 4);
  2897   2926         char const *zRoot = sqlite3_column_blob(pStmt, 4);
  2898   2927   
  2899   2928         /* If zTerm is not NULL, and this segment is not stored entirely on its
  2900   2929         ** root node, the range of leaves scanned can be reduced. Do this. */
  2901         -      if( iStartBlock && zTerm ){
         2930  +      if( iStartBlock && zTerm && zRoot ){
  2902   2931           sqlite3_int64 *pi = (isPrefix ? &iLeavesEndBlock : 0);
  2903   2932           rc = fts3SelectLeaf(p, zTerm, nTerm, zRoot, nRoot, &iStartBlock, pi);
  2904   2933           if( rc!=SQLITE_OK ) goto finished;
  2905   2934           if( isPrefix==0 && isScan==0 ) iLeavesEndBlock = iStartBlock;
  2906   2935         }
  2907   2936    
  2908   2937         rc = sqlite3Fts3SegReaderNew(pCsr->nSegment+1, 
................................................................................
  3836   3865   **
  3837   3866   ** Discard the contents of the pending terms table.
  3838   3867   */
  3839   3868   static int fts3RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
  3840   3869     Fts3Table *p = (Fts3Table*)pVtab;
  3841   3870     UNUSED_PARAMETER(iSavepoint);
  3842   3871     assert( p->inTransaction );
  3843         -  assert( p->mxSavepoint >= iSavepoint );
  3844   3872     TESTONLY( p->mxSavepoint = iSavepoint );
  3845   3873     sqlite3Fts3PendingTermsClear(p);
  3846   3874     return SQLITE_OK;
  3847   3875   }
         3876  +
         3877  +/*
         3878  +** Return true if zName is the extension on one of the shadow tables used
         3879  +** by this module.
         3880  +*/
         3881  +static int fts3ShadowName(const char *zName){
         3882  +  static const char *azName[] = {
         3883  +    "content", "docsize", "segdir", "segments", "stat", 
         3884  +  };
         3885  +  unsigned int i;
         3886  +  for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
         3887  +    if( sqlite3_stricmp(zName, azName[i])==0 ) return 1;
         3888  +  }
         3889  +  return 0;
         3890  +}
  3848   3891   
  3849   3892   static const sqlite3_module fts3Module = {
  3850         -  /* iVersion      */ 2,
         3893  +  /* iVersion      */ 3,
  3851   3894     /* xCreate       */ fts3CreateMethod,
  3852   3895     /* xConnect      */ fts3ConnectMethod,
  3853   3896     /* xBestIndex    */ fts3BestIndexMethod,
  3854   3897     /* xDisconnect   */ fts3DisconnectMethod,
  3855   3898     /* xDestroy      */ fts3DestroyMethod,
  3856   3899     /* xOpen         */ fts3OpenMethod,
  3857   3900     /* xClose        */ fts3CloseMethod,
................................................................................
  3866   3909     /* xCommit       */ fts3CommitMethod,
  3867   3910     /* xRollback     */ fts3RollbackMethod,
  3868   3911     /* xFindFunction */ fts3FindFunctionMethod,
  3869   3912     /* xRename */       fts3RenameMethod,
  3870   3913     /* xSavepoint    */ fts3SavepointMethod,
  3871   3914     /* xRelease      */ fts3ReleaseMethod,
  3872   3915     /* xRollbackTo   */ fts3RollbackToMethod,
         3916  +  /* xShadowName   */ fts3ShadowName,
  3873   3917   };
  3874   3918   
  3875   3919   /*
  3876   3920   ** This function is registered as the module destructor (called when an
  3877   3921   ** FTS3 enabled database connection is closed). It frees the memory
  3878   3922   ** allocated for the tokenizer hash table.
  3879   3923   */
................................................................................
  4146   4190       }
  4147   4191       assert( pToken->pSegcsr==0 );
  4148   4192     }
  4149   4193   
  4150   4194     return rc;
  4151   4195   }
  4152   4196   
         4197  +#ifndef SQLITE_DISABLE_FTS4_DEFERRED
  4153   4198   /*
  4154   4199   ** This function is called on each phrase after the position lists for
  4155   4200   ** any deferred tokens have been loaded into memory. It updates the phrases
  4156   4201   ** current position list to include only those positions that are really
  4157   4202   ** instances of the phrase (after considering deferred tokens). If this
  4158   4203   ** means that the phrase does not appear in the current row, doclist.pList
  4159   4204   ** and doclist.nList are both zeroed.
................................................................................
  4249   4294         }
  4250   4295         sqlite3_free(aPoslist);
  4251   4296       }
  4252   4297     }
  4253   4298   
  4254   4299     return SQLITE_OK;
  4255   4300   }
         4301  +#endif /* SQLITE_DISABLE_FTS4_DEFERRED */
  4256   4302   
  4257   4303   /*
  4258   4304   ** Maximum number of tokens a phrase may have to be considered for the
  4259   4305   ** incremental doclists strategy.
  4260   4306   */
  4261   4307   #define MAX_INCR_PHRASE_TOKENS 4
  4262   4308   
................................................................................
  4593   4639           }
  4594   4640         }
  4595   4641   
  4596   4642         /* Check if the current entries really are a phrase match */
  4597   4643         if( bEof==0 ){
  4598   4644           int nList = 0;
  4599   4645           int nByte = a[p->nToken-1].nList;
  4600         -        char *aDoclist = sqlite3_malloc(nByte+1);
         4646  +        char *aDoclist = sqlite3_malloc(nByte+FTS3_BUFFER_PADDING);
  4601   4647           if( !aDoclist ) return SQLITE_NOMEM;
  4602   4648           memcpy(aDoclist, a[p->nToken-1].pList, nByte+1);
         4649  +        memset(&aDoclist[nByte], 0, FTS3_BUFFER_PADDING);
  4603   4650   
  4604   4651           for(i=0; i<(p->nToken-1); i++){
  4605   4652             if( a[i].bIgnore==0 ){
  4606   4653               char *pL = a[i].pList;
  4607   4654               char *pR = aDoclist;
  4608   4655               char *pOut = aDoclist;
  4609   4656               int nDist = p->nToken-1-i;
................................................................................
  4986   5033     fts3EvalAllocateReaders(pCsr, pCsr->pExpr, &nToken, &nOr, &rc);
  4987   5034   
  4988   5035     /* Determine which, if any, tokens in the expression should be deferred. */
  4989   5036   #ifndef SQLITE_DISABLE_FTS4_DEFERRED
  4990   5037     if( rc==SQLITE_OK && nToken>1 && pTab->bFts4 ){
  4991   5038       Fts3TokenAndCost *aTC;
  4992   5039       Fts3Expr **apOr;
  4993         -    aTC = (Fts3TokenAndCost *)sqlite3_malloc(
         5040  +    aTC = (Fts3TokenAndCost *)sqlite3_malloc64(
  4994   5041           sizeof(Fts3TokenAndCost) * nToken
  4995   5042         + sizeof(Fts3Expr *) * nOr * 2
  4996   5043       );
  4997   5044       apOr = (Fts3Expr **)&aTC[nToken];
  4998   5045   
  4999   5046       if( !aTC ){
  5000   5047         rc = SQLITE_NOMEM;
................................................................................
  5297   5344     ** no exceptions to this - it's the way the parser in fts3_expr.c works.
  5298   5345     */
  5299   5346     if( *pRc==SQLITE_OK 
  5300   5347      && pExpr->eType==FTSQUERY_NEAR 
  5301   5348      && (pExpr->pParent==0 || pExpr->pParent->eType!=FTSQUERY_NEAR)
  5302   5349     ){
  5303   5350       Fts3Expr *p; 
  5304         -    int nTmp = 0;                 /* Bytes of temp space */
         5351  +    sqlite3_int64 nTmp = 0;       /* Bytes of temp space */
  5305   5352       char *aTmp;                   /* Temp space for PoslistNearMerge() */
  5306   5353   
  5307   5354       /* Allocate temporary working space. */
  5308   5355       for(p=pExpr; p->pLeft; p=p->pLeft){
  5309   5356         assert( p->pRight->pPhrase->doclist.nList>0 );
  5310   5357         nTmp += p->pRight->pPhrase->doclist.nList;
  5311   5358       }
  5312   5359       nTmp += p->pPhrase->doclist.nList;
  5313         -    aTmp = sqlite3_malloc(nTmp*2);
         5360  +    aTmp = sqlite3_malloc64(nTmp*2);
  5314   5361       if( !aTmp ){
  5315   5362         *pRc = SQLITE_NOMEM;
  5316   5363         res = 0;
  5317   5364       }else{
  5318   5365         char *aPoslist = p->pPhrase->doclist.pList;
  5319   5366         int nToken = p->pPhrase->nToken;
  5320   5367   
................................................................................
  5576   5623   ** After allocating the Fts3Expr.aMI[] array for each phrase in the 
  5577   5624   ** expression rooted at pExpr, the cursor iterates through all rows matched
  5578   5625   ** by pExpr, calling this function for each row. This function increments
  5579   5626   ** the values in Fts3Expr.aMI[] according to the position-list currently
  5580   5627   ** found in Fts3Expr.pPhrase->doclist.pList for each of the phrase 
  5581   5628   ** expression nodes.
  5582   5629   */
  5583         -static void fts3EvalUpdateCounts(Fts3Expr *pExpr){
         5630  +static void fts3EvalUpdateCounts(Fts3Expr *pExpr, int nCol){
  5584   5631     if( pExpr ){
  5585   5632       Fts3Phrase *pPhrase = pExpr->pPhrase;
  5586   5633       if( pPhrase && pPhrase->doclist.pList ){
  5587   5634         int iCol = 0;
  5588   5635         char *p = pPhrase->doclist.pList;
  5589   5636   
  5590         -      assert( *p );
  5591         -      while( 1 ){
         5637  +      do{
  5592   5638           u8 c = 0;
  5593   5639           int iCnt = 0;
  5594   5640           while( 0xFE & (*p | c) ){
  5595   5641             if( (c&0x80)==0 ) iCnt++;
  5596   5642             c = *p++ & 0x80;
  5597   5643           }
  5598   5644   
................................................................................
  5600   5646           ** aMI[iCol*3 + 2] = Number of rows containing at least one instance
  5601   5647           */
  5602   5648           pExpr->aMI[iCol*3 + 1] += iCnt;
  5603   5649           pExpr->aMI[iCol*3 + 2] += (iCnt>0);
  5604   5650           if( *p==0x00 ) break;
  5605   5651           p++;
  5606   5652           p += fts3GetVarint32(p, &iCol);
  5607         -      }
         5653  +      }while( iCol<nCol );
  5608   5654       }
  5609   5655   
  5610         -    fts3EvalUpdateCounts(pExpr->pLeft);
  5611         -    fts3EvalUpdateCounts(pExpr->pRight);
         5656  +    fts3EvalUpdateCounts(pExpr->pLeft, nCol);
         5657  +    fts3EvalUpdateCounts(pExpr->pRight, nCol);
  5612   5658     }
  5613   5659   }
  5614   5660   
  5615   5661   /*
  5616   5662   ** Expression pExpr must be of type FTSQUERY_PHRASE.
  5617   5663   **
  5618   5664   ** If it is not already allocated and populated, this function allocates and
................................................................................
  5648   5694       bEof = pRoot->bEof;
  5649   5695       assert( pRoot->bStart );
  5650   5696   
  5651   5697       /* Allocate space for the aMSI[] array of each FTSQUERY_PHRASE node */
  5652   5698       for(p=pRoot; p; p=p->pLeft){
  5653   5699         Fts3Expr *pE = (p->eType==FTSQUERY_PHRASE?p:p->pRight);
  5654   5700         assert( pE->aMI==0 );
  5655         -      pE->aMI = (u32 *)sqlite3_malloc(pTab->nColumn * 3 * sizeof(u32));
         5701  +      pE->aMI = (u32 *)sqlite3_malloc64(pTab->nColumn * 3 * sizeof(u32));
  5656   5702         if( !pE->aMI ) return SQLITE_NOMEM;
  5657   5703         memset(pE->aMI, 0, pTab->nColumn * 3 * sizeof(u32));
  5658   5704       }
  5659   5705   
  5660   5706       fts3EvalRestart(pCsr, pRoot, &rc);
  5661   5707   
  5662   5708       while( pCsr->isEof==0 && rc==SQLITE_OK ){
................................................................................
  5674   5720           pCsr->iPrevId = pRoot->iDocid;
  5675   5721         }while( pCsr->isEof==0 
  5676   5722              && pRoot->eType==FTSQUERY_NEAR 
  5677   5723              && sqlite3Fts3EvalTestDeferred(pCsr, &rc) 
  5678   5724         );
  5679   5725   
  5680   5726         if( rc==SQLITE_OK && pCsr->isEof==0 ){
  5681         -        fts3EvalUpdateCounts(pRoot);
         5727  +        fts3EvalUpdateCounts(pRoot, pTab->nColumn);
  5682   5728         }
  5683   5729       }
  5684   5730   
  5685   5731       pCsr->isEof = 0;
  5686   5732       pCsr->iPrevId = iPrevId;
  5687   5733   
  5688   5734       if( bEof ){

Changes to ext/fts3/fts3Int.h.

    91     91   
    92     92   /*
    93     93   ** Maximum length of a varint encoded integer. The varint format is different
    94     94   ** from that used by SQLite, so the maximum length is 10, not 9.
    95     95   */
    96     96   #define FTS3_VARINT_MAX 10
    97     97   
           98  +#define FTS3_BUFFER_PADDING 8
           99  +
    98    100   /*
    99    101   ** FTS4 virtual tables may maintain multiple indexes - one index of all terms
   100    102   ** in the document set and zero or more prefix indexes. All indexes are stored
   101    103   ** as one or more b+-trees in the %_segments and %_segdir tables. 
   102    104   **
   103    105   ** It is possible to determine which index a b+-tree belongs to based on the
   104    106   ** value stored in the "%_segdir.level" column. Given this value L, the index
................................................................................
   123    125   
   124    126   /*
   125    127   ** Terminator values for position-lists and column-lists.
   126    128   */
   127    129   #define POS_COLUMN  (1)     /* Column-list terminator */
   128    130   #define POS_END     (0)     /* Position-list terminator */ 
   129    131   
          132  +/*
          133  +** The assert_fts3_nc() macro is similar to the assert() macro, except that it
          134  +** is used for assert() conditions that are true only if it can be 
          135  +** guranteed that the database is not corrupt.
          136  +*/
          137  +#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
          138  +extern int sqlite3_fts3_may_be_corrupt;
          139  +# define assert_fts3_nc(x) assert(sqlite3_fts3_may_be_corrupt || (x))
          140  +#else
          141  +# define assert_fts3_nc(x) assert(x)
          142  +#endif
          143  +
   130    144   /*
   131    145   ** This section provides definitions to allow the
   132    146   ** FTS3 extension to be compiled outside of the 
   133    147   ** amalgamation.
   134    148   */
   135    149   #ifndef SQLITE_AMALGAMATION
   136    150   /*

Changes to ext/fts3/fts3_aux.c.

    62     62     sqlite3_vtab **ppVtab,          /* OUT: New sqlite3_vtab object */
    63     63     char **pzErr                    /* OUT: sqlite3_malloc'd error message */
    64     64   ){
    65     65     char const *zDb;                /* Name of database (e.g. "main") */
    66     66     char const *zFts3;              /* Name of fts3 table */
    67     67     int nDb;                        /* Result of strlen(zDb) */
    68     68     int nFts3;                      /* Result of strlen(zFts3) */
    69         -  int nByte;                      /* Bytes of space to allocate here */
           69  +  sqlite3_int64 nByte;            /* Bytes of space to allocate here */
    70     70     int rc;                         /* value returned by declare_vtab() */
    71     71     Fts3auxTable *p;                /* Virtual table object to return */
    72     72   
    73     73     UNUSED_PARAMETER(pUnused);
    74     74   
    75     75     /* The user should invoke this in one of two forms:
    76     76     **
................................................................................
    94     94     }
    95     95     nFts3 = (int)strlen(zFts3);
    96     96   
    97     97     rc = sqlite3_declare_vtab(db, FTS3_AUX_SCHEMA);
    98     98     if( rc!=SQLITE_OK ) return rc;
    99     99   
   100    100     nByte = sizeof(Fts3auxTable) + sizeof(Fts3Table) + nDb + nFts3 + 2;
   101         -  p = (Fts3auxTable *)sqlite3_malloc(nByte);
          101  +  p = (Fts3auxTable *)sqlite3_malloc64(nByte);
   102    102     if( !p ) return SQLITE_NOMEM;
   103    103     memset(p, 0, nByte);
   104    104   
   105    105     p->pFts3Tab = (Fts3Table *)&p[1];
   106    106     p->pFts3Tab->zDb = (char *)&p->pFts3Tab[1];
   107    107     p->pFts3Tab->zName = &p->pFts3Tab->zDb[nDb+1];
   108    108     p->pFts3Tab->db = db;
................................................................................
   244    244     sqlite3_free(pCsr);
   245    245     return SQLITE_OK;
   246    246   }
   247    247   
   248    248   static int fts3auxGrowStatArray(Fts3auxCursor *pCsr, int nSize){
   249    249     if( nSize>pCsr->nStat ){
   250    250       struct Fts3auxColstats *aNew;
   251         -    aNew = (struct Fts3auxColstats *)sqlite3_realloc(pCsr->aStat, 
          251  +    aNew = (struct Fts3auxColstats *)sqlite3_realloc64(pCsr->aStat, 
   252    252           sizeof(struct Fts3auxColstats) * nSize
   253    253       );
   254    254       if( aNew==0 ) return SQLITE_NOMEM;
   255    255       memset(&aNew[pCsr->nStat], 0, 
   256    256           sizeof(struct Fts3auxColstats) * (nSize - pCsr->nStat)
   257    257       );
   258    258       pCsr->aStat = aNew;
................................................................................
   412    412     if( isScan ) pCsr->filter.flags |= FTS3_SEGMENT_SCAN;
   413    413   
   414    414     if( iEq>=0 || iGe>=0 ){
   415    415       const unsigned char *zStr = sqlite3_value_text(apVal[0]);
   416    416       assert( (iEq==0 && iGe==-1) || (iEq==-1 && iGe==0) );
   417    417       if( zStr ){
   418    418         pCsr->filter.zTerm = sqlite3_mprintf("%s", zStr);
   419         -      pCsr->filter.nTerm = sqlite3_value_bytes(apVal[0]);
   420    419         if( pCsr->filter.zTerm==0 ) return SQLITE_NOMEM;
          420  +      pCsr->filter.nTerm = (int)strlen(pCsr->filter.zTerm);
   421    421       }
   422    422     }
   423    423   
   424    424     if( iLe>=0 ){
   425    425       pCsr->zStop = sqlite3_mprintf("%s", sqlite3_value_text(apVal[iLe]));
   426         -    pCsr->nStop = sqlite3_value_bytes(apVal[iLe]);
   427    426       if( pCsr->zStop==0 ) return SQLITE_NOMEM;
          427  +    pCsr->nStop = (int)strlen(pCsr->zStop);
   428    428     }
   429    429     
   430    430     if( iLangid>=0 ){
   431    431       iLangVal = sqlite3_value_int(apVal[iLangid]);
   432    432   
   433    433       /* If the user specified a negative value for the languageid, use zero
   434    434       ** instead. This works, as the "languageid=?" constraint will also
................................................................................
   535    535        0,                           /* xSync         */
   536    536        0,                           /* xCommit       */
   537    537        0,                           /* xRollback     */
   538    538        0,                           /* xFindFunction */
   539    539        0,                           /* xRename       */
   540    540        0,                           /* xSavepoint    */
   541    541        0,                           /* xRelease      */
   542         -     0                            /* xRollbackTo   */
          542  +     0,                           /* xRollbackTo   */
          543  +     0                            /* xShadowName   */
   543    544     };
   544    545     int rc;                         /* Return code */
   545    546   
   546    547     rc = sqlite3_create_module(db, "fts4aux", &fts3aux_module, 0);
   547    548     return rc;
   548    549   }
   549    550   
   550    551   #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */

Changes to ext/fts3/fts3_expr.c.

   118    118   }
   119    119   
   120    120   /*
   121    121   ** Allocate nByte bytes of memory using sqlite3_malloc(). If successful,
   122    122   ** zero the memory before returning a pointer to it. If unsuccessful, 
   123    123   ** return NULL.
   124    124   */
   125         -static void *fts3MallocZero(int nByte){
   126         -  void *pRet = sqlite3_malloc(nByte);
          125  +static void *fts3MallocZero(sqlite3_int64 nByte){
          126  +  void *pRet = sqlite3_malloc64(nByte);
   127    127     if( pRet ) memset(pRet, 0, nByte);
   128    128     return pRet;
   129    129   }
   130    130   
   131    131   int sqlite3Fts3OpenTokenizer(
   132    132     sqlite3_tokenizer *pTokenizer,
   133    133     int iLangid,
................................................................................
   194    194     }
   195    195   
   196    196     *pnConsumed = i;
   197    197     rc = sqlite3Fts3OpenTokenizer(pTokenizer, pParse->iLangid, z, i, &pCursor);
   198    198     if( rc==SQLITE_OK ){
   199    199       const char *zToken;
   200    200       int nToken = 0, iStart = 0, iEnd = 0, iPosition = 0;
   201         -    int nByte;                               /* total space to allocate */
          201  +    sqlite3_int64 nByte;                    /* total space to allocate */
   202    202   
   203    203       rc = pModule->xNext(pCursor, &zToken, &nToken, &iStart, &iEnd, &iPosition);
   204    204       if( rc==SQLITE_OK ){
   205    205         nByte = sizeof(Fts3Expr) + sizeof(Fts3Phrase) + nToken;
   206    206         pRet = (Fts3Expr *)fts3MallocZero(nByte);
   207    207         if( !pRet ){
   208    208           rc = SQLITE_NOMEM;
................................................................................
   248    248   }
   249    249   
   250    250   
   251    251   /*
   252    252   ** Enlarge a memory allocation.  If an out-of-memory allocation occurs,
   253    253   ** then free the old allocation.
   254    254   */
   255         -static void *fts3ReallocOrFree(void *pOrig, int nNew){
   256         -  void *pRet = sqlite3_realloc(pOrig, nNew);
          255  +static void *fts3ReallocOrFree(void *pOrig, sqlite3_int64 nNew){
          256  +  void *pRet = sqlite3_realloc64(pOrig, nNew);
   257    257     if( !pRet ){
   258    258       sqlite3_free(pOrig);
   259    259     }
   260    260     return pRet;
   261    261   }
   262    262   
   263    263   /*
................................................................................
   493    493     }
   494    494   
   495    495     if( sqlite3_fts3_enable_parentheses ){
   496    496       if( *zInput=='(' ){
   497    497         int nConsumed = 0;
   498    498         pParse->nNest++;
   499    499         rc = fts3ExprParse(pParse, zInput+1, nInput-1, ppExpr, &nConsumed);
   500         -      if( rc==SQLITE_OK && !*ppExpr ){ rc = SQLITE_DONE; }
   501    500         *pnConsumed = (int)(zInput - z) + 1 + nConsumed;
   502    501         return rc;
   503    502       }else if( *zInput==')' ){
   504    503         pParse->nNest--;
   505    504         *pnConsumed = (int)((zInput - z) + 1);
   506    505         *ppExpr = 0;
   507    506         return SQLITE_DONE;
................................................................................
   792    791     if( nMaxDepth==0 ){
   793    792       rc = SQLITE_ERROR;
   794    793     }
   795    794   
   796    795     if( rc==SQLITE_OK ){
   797    796       if( (eType==FTSQUERY_AND || eType==FTSQUERY_OR) ){
   798    797         Fts3Expr **apLeaf;
   799         -      apLeaf = (Fts3Expr **)sqlite3_malloc(sizeof(Fts3Expr *) * nMaxDepth);
          798  +      apLeaf = (Fts3Expr **)sqlite3_malloc64(sizeof(Fts3Expr *) * nMaxDepth);
   800    799         if( 0==apLeaf ){
   801    800           rc = SQLITE_NOMEM;
   802    801         }else{
   803    802           memset(apLeaf, 0, sizeof(Fts3Expr *) * nMaxDepth);
   804    803         }
   805    804   
   806    805         if( rc==SQLITE_OK ){
................................................................................
  1212   1211       sqlite3_free(zErr);
  1213   1212       return;
  1214   1213     }
  1215   1214   
  1216   1215     zExpr = (const char *)sqlite3_value_text(argv[1]);
  1217   1216     nExpr = sqlite3_value_bytes(argv[1]);
  1218   1217     nCol = argc-2;
  1219         -  azCol = (char **)sqlite3_malloc(nCol*sizeof(char *));
         1218  +  azCol = (char **)sqlite3_malloc64(nCol*sizeof(char *));
  1220   1219     if( !azCol ){
  1221   1220       sqlite3_result_error_nomem(context);
  1222   1221       goto exprtest_out;
  1223   1222     }
  1224   1223     for(ii=0; ii<nCol; ii++){
  1225   1224       azCol[ii] = (char *)sqlite3_value_text(argv[ii+2]);
  1226   1225     }

Changes to ext/fts3/fts3_hash.c.

    31     31   #include <string.h>
    32     32   
    33     33   #include "fts3_hash.h"
    34     34   
    35     35   /*
    36     36   ** Malloc and Free functions
    37     37   */
    38         -static void *fts3HashMalloc(int n){
    39         -  void *p = sqlite3_malloc(n);
           38  +static void *fts3HashMalloc(sqlite3_int64 n){
           39  +  void *p = sqlite3_malloc64(n);
    40     40     if( p ){
    41     41       memset(p, 0, n);
    42     42     }
    43     43     return p;
    44     44   }
    45     45   static void fts3HashFree(void *p){
    46     46     sqlite3_free(p);

Changes to ext/fts3/fts3_icu.c.

    56     56   ){
    57     57     IcuTokenizer *p;
    58     58     int n = 0;
    59     59   
    60     60     if( argc>0 ){
    61     61       n = strlen(argv[0])+1;
    62     62     }
    63         -  p = (IcuTokenizer *)sqlite3_malloc(sizeof(IcuTokenizer)+n);
           63  +  p = (IcuTokenizer *)sqlite3_malloc64(sizeof(IcuTokenizer)+n);
    64     64     if( !p ){
    65     65       return SQLITE_NOMEM;
    66     66     }
    67     67     memset(p, 0, sizeof(IcuTokenizer));
    68     68   
    69     69     if( n ){
    70     70       p->zLocale = (char *)&p[1];
................................................................................
   113    113     if( zInput==0 ){
   114    114       nInput = 0;
   115    115       zInput = "";
   116    116     }else if( nInput<0 ){
   117    117       nInput = strlen(zInput);
   118    118     }
   119    119     nChar = nInput+1;
   120         -  pCsr = (IcuCursor *)sqlite3_malloc(
          120  +  pCsr = (IcuCursor *)sqlite3_malloc64(
   121    121         sizeof(IcuCursor) +                /* IcuCursor */
   122    122         ((nChar+3)&~3) * sizeof(UChar) +   /* IcuCursor.aChar[] */
   123    123         (nChar+1) * sizeof(int)            /* IcuCursor.aOffset[] */
   124    124     );
   125    125     if( !pCsr ){
   126    126       return SQLITE_NOMEM;
   127    127     }

Changes to ext/fts3/fts3_snippet.c.

   174    174       xRet = fts3MIBufferFree;
   175    175     }
   176    176     else if( p->aRef[2]==0 ){
   177    177       p->aRef[2] = 1;
   178    178       aOut = &p->aMatchinfo[p->nElem+2];
   179    179       xRet = fts3MIBufferFree;
   180    180     }else{
   181         -    aOut = (u32*)sqlite3_malloc(p->nElem * sizeof(u32));
          181  +    aOut = (u32*)sqlite3_malloc64(p->nElem * sizeof(u32));
   182    182       if( aOut ){
   183    183         xRet = sqlite3_free;
   184    184         if( p->bGlobal ) memcpy(aOut, &p->aMatchinfo[1], p->nElem*sizeof(u32));
   185    185       }
   186    186     }
   187    187   
   188    188     *paOut = aOut;
................................................................................
   429    429         char *pCsr = pPhrase->pTail;
   430    430         int iCsr = pPhrase->iTail;
   431    431   
   432    432         while( iCsr<(iStart+pIter->nSnippet) ){
   433    433           int j;
   434    434           u64 mPhrase = (u64)1 << i;
   435    435           u64 mPos = (u64)1 << (iCsr - iStart);
   436         -        assert( iCsr>=iStart );
          436  +        assert( iCsr>=iStart && (iCsr - iStart)<=64 );
          437  +        assert( i>=0 && i<=64 );
   437    438           if( (mCover|mCovered)&mPhrase ){
   438    439             iScore++;
   439    440           }else{
   440    441             iScore += 1000;
   441    442           }
   442    443           mCover |= mPhrase;
   443    444   
................................................................................
   471    472     pPhrase->nToken = pExpr->pPhrase->nToken;
   472    473     rc = sqlite3Fts3EvalPhrasePoslist(p->pCsr, pExpr, p->iCol, &pCsr);
   473    474     assert( rc==SQLITE_OK || pCsr==0 );
   474    475     if( pCsr ){
   475    476       int iFirst = 0;
   476    477       pPhrase->pList = pCsr;
   477    478       fts3GetDeltaPosition(&pCsr, &iFirst);
   478         -    assert( iFirst>=0 );
   479         -    pPhrase->pHead = pCsr;
   480         -    pPhrase->pTail = pCsr;
   481         -    pPhrase->iHead = iFirst;
   482         -    pPhrase->iTail = iFirst;
          479  +    if( iFirst<0 ){
          480  +      rc = FTS_CORRUPT_VTAB;
          481  +    }else{
          482  +      pPhrase->pHead = pCsr;
          483  +      pPhrase->pTail = pCsr;
          484  +      pPhrase->iHead = iFirst;
          485  +      pPhrase->iTail = iFirst;
          486  +    }
   483    487     }else{
   484    488       assert( rc!=SQLITE_OK || (
   485    489          pPhrase->pList==0 && pPhrase->pHead==0 && pPhrase->pTail==0 
   486    490       ));
   487    491     }
   488    492   
   489    493     return rc;
................................................................................
   512    516     u64 *pmSeen,                    /* IN/OUT: Mask of phrases seen */
   513    517     SnippetFragment *pFragment,     /* OUT: Best snippet found */
   514    518     int *piScore                    /* OUT: Score of snippet pFragment */
   515    519   ){
   516    520     int rc;                         /* Return Code */
   517    521     int nList;                      /* Number of phrases in expression */
   518    522     SnippetIter sIter;              /* Iterates through snippet candidates */
   519         -  int nByte;                      /* Number of bytes of space to allocate */
          523  +  sqlite3_int64 nByte;            /* Number of bytes of space to allocate */
   520    524     int iBestScore = -1;            /* Best snippet score found so far */
   521    525     int i;                          /* Loop counter */
   522    526   
   523    527     memset(&sIter, 0, sizeof(sIter));
   524    528   
   525    529     /* Iterate through the phrases in the expression to count them. The same
   526    530     ** callback makes sure the doclists are loaded for each phrase.
................................................................................
   530    534       return rc;
   531    535     }
   532    536   
   533    537     /* Now that it is known how many phrases there are, allocate and zero
   534    538     ** the required space using malloc().
   535    539     */
   536    540     nByte = sizeof(SnippetPhrase) * nList;
   537         -  sIter.aPhrase = (SnippetPhrase *)sqlite3_malloc(nByte);
          541  +  sIter.aPhrase = (SnippetPhrase *)sqlite3_malloc64(nByte);
   538    542     if( !sIter.aPhrase ){
   539    543       return SQLITE_NOMEM;
   540    544     }
   541    545     memset(sIter.aPhrase, 0, nByte);
   542    546   
   543    547     /* Initialize the contents of the SnippetIter object. Then iterate through
   544    548     ** the set of phrases in the expression to populate the aPhrase[] array.
................................................................................
   600    604     }
   601    605   
   602    606     /* If there is insufficient space allocated at StrBuffer.z, use realloc()
   603    607     ** to grow the buffer until so that it is big enough to accomadate the
   604    608     ** appended data.
   605    609     */
   606    610     if( pStr->n+nAppend+1>=pStr->nAlloc ){
   607         -    int nAlloc = pStr->nAlloc+nAppend+100;
   608         -    char *zNew = sqlite3_realloc(pStr->z, nAlloc);
          611  +    sqlite3_int64 nAlloc = pStr->nAlloc+(sqlite3_int64)nAppend+100;
          612  +    char *zNew = sqlite3_realloc64(pStr->z, nAlloc);
   609    613       if( !zNew ){
   610    614         return SQLITE_NOMEM;
   611    615       }
   612    616       pStr->z = zNew;
   613    617       pStr->nAlloc = nAlloc;
   614    618     }
   615    619     assert( pStr->z!=0 && (pStr->nAlloc >= pStr->n+nAppend+1) );
................................................................................
   656    660     if( hlmask ){
   657    661       int nLeft;                    /* Tokens to the left of first highlight */
   658    662       int nRight;                   /* Tokens to the right of last highlight */
   659    663       int nDesired;                 /* Ideal number of tokens to shift forward */
   660    664   
   661    665       for(nLeft=0; !(hlmask & ((u64)1 << nLeft)); nLeft++);
   662    666       for(nRight=0; !(hlmask & ((u64)1 << (nSnippet-1-nRight))); nRight++);
          667  +    assert( (nSnippet-1-nRight)<=63 && (nSnippet-1-nRight)>=0 );
   663    668       nDesired = (nLeft-nRight)/2;
   664    669   
   665    670       /* Ideally, the start of the snippet should be pushed forward in the
   666    671       ** document nDesired tokens. This block checks if there are actually
   667    672       ** nDesired tokens to the right of the snippet. If so, *piPos and
   668    673       ** *pHlMask are updated to shift the snippet nDesired tokens to the
   669    674       ** right. Otherwise, the snippet is shifted by the number of tokens
................................................................................
   848    853     *ppCollist = pEnd;
   849    854     return nEntry;
   850    855   }
   851    856   
   852    857   /*
   853    858   ** This function gathers 'y' or 'b' data for a single phrase.
   854    859   */
   855         -static void fts3ExprLHits(
          860  +static int fts3ExprLHits(
   856    861     Fts3Expr *pExpr,                /* Phrase expression node */
   857    862     MatchInfo *p                    /* Matchinfo context */
   858    863   ){
   859    864     Fts3Table *pTab = (Fts3Table *)p->pCursor->base.pVtab;
   860    865     int iStart;
   861    866     Fts3Phrase *pPhrase = pExpr->pPhrase;
   862    867     char *pIter = pPhrase->doclist.pList;
................................................................................
   878    883           p->aMatchinfo[iStart + (iCol+1)/32] |= (1 << (iCol&0x1F));
   879    884         }
   880    885       }
   881    886       assert( *pIter==0x00 || *pIter==0x01 );
   882    887       if( *pIter!=0x01 ) break;
   883    888       pIter++;
   884    889       pIter += fts3GetVarint32(pIter, &iCol);
          890  +    if( iCol>=p->nCol ) return FTS_CORRUPT_VTAB;
   885    891     }
          892  +  return SQLITE_OK;
   886    893   }
   887    894   
   888    895   /*
   889    896   ** Gather the results for matchinfo directives 'y' and 'b'.
   890    897   */
   891         -static void fts3ExprLHitGather(
          898  +static int fts3ExprLHitGather(
   892    899     Fts3Expr *pExpr,
   893    900     MatchInfo *p
   894    901   ){
          902  +  int rc = SQLITE_OK;
   895    903     assert( (pExpr->pLeft==0)==(pExpr->pRight==0) );
   896    904     if( pExpr->bEof==0 && pExpr->iDocid==p->pCursor->iPrevId ){
   897    905       if( pExpr->pLeft ){
   898         -      fts3ExprLHitGather(pExpr->pLeft, p);
   899         -      fts3ExprLHitGather(pExpr->pRight, p);
          906  +      rc = fts3ExprLHitGather(pExpr->pLeft, p);
          907  +      if( rc==SQLITE_OK ) rc = fts3ExprLHitGather(pExpr->pRight, p);
   900    908       }else{
   901         -      fts3ExprLHits(pExpr, p);
          909  +      rc = fts3ExprLHits(pExpr, p);
   902    910       }
   903    911     }
          912  +  return rc;
   904    913   }
   905    914   
   906    915   /*
   907    916   ** fts3ExprIterate() callback used to collect the "global" matchinfo stats
   908    917   ** for a single query. 
   909    918   **
   910    919   ** fts3ExprIterate() callback to load the 'global' elements of a
................................................................................
  1113   1122   ** undefined.
  1114   1123   */
  1115   1124   static int fts3MatchinfoLcs(Fts3Cursor *pCsr, MatchInfo *pInfo){
  1116   1125     LcsIterator *aIter;
  1117   1126     int i;
  1118   1127     int iCol;
  1119   1128     int nToken = 0;
         1129  +  int rc = SQLITE_OK;
  1120   1130   
  1121   1131     /* Allocate and populate the array of LcsIterator objects. The array
  1122   1132     ** contains one element for each matchable phrase in the query.
  1123   1133     **/
  1124         -  aIter = sqlite3_malloc(sizeof(LcsIterator) * pCsr->nPhrase);
         1134  +  aIter = sqlite3_malloc64(sizeof(LcsIterator) * pCsr->nPhrase);
  1125   1135     if( !aIter ) return SQLITE_NOMEM;
  1126   1136     memset(aIter, 0, sizeof(LcsIterator) * pCsr->nPhrase);
  1127   1137     (void)fts3ExprIterate(pCsr->pExpr, fts3MatchinfoLcsCb, (void*)aIter);
  1128   1138   
  1129   1139     for(i=0; i<pInfo->nPhrase; i++){
  1130   1140       LcsIterator *pIter = &aIter[i];
  1131   1141       nToken -= pIter->pExpr->pPhrase->nToken;
................................................................................
  1133   1143     }
  1134   1144   
  1135   1145     for(iCol=0; iCol<pInfo->nCol; iCol++){
  1136   1146       int nLcs = 0;                 /* LCS value for this column */
  1137   1147       int nLive = 0;                /* Number of iterators in aIter not at EOF */
  1138   1148   
  1139   1149       for(i=0; i<pInfo->nPhrase; i++){
  1140         -      int rc;
  1141   1150         LcsIterator *pIt = &aIter[i];
  1142   1151         rc = sqlite3Fts3EvalPhrasePoslist(pCsr, pIt->pExpr, iCol, &pIt->pRead);
  1143         -      if( rc!=SQLITE_OK ) return rc;
         1152  +      if( rc!=SQLITE_OK ) goto matchinfo_lcs_out;
  1144   1153         if( pIt->pRead ){
  1145   1154           pIt->iPos = pIt->iPosOffset;
  1146         -        fts3LcsIteratorAdvance(&aIter[i]);
         1155  +        fts3LcsIteratorAdvance(pIt);
         1156  +        if( pIt->pRead==0 ){
         1157  +          rc = FTS_CORRUPT_VTAB;
         1158  +          goto matchinfo_lcs_out;
         1159  +        }
  1147   1160           nLive++;
  1148   1161         }
  1149   1162       }
  1150   1163   
  1151   1164       while( nLive>0 ){
  1152   1165         LcsIterator *pAdv = 0;      /* The iterator to advance by one position */
  1153   1166         int nThisLcs = 0;           /* LCS for the current iterator positions */
................................................................................
  1171   1184         }
  1172   1185         if( fts3LcsIteratorAdvance(pAdv) ) nLive--;
  1173   1186       }
  1174   1187   
  1175   1188       pInfo->aMatchinfo[iCol] = nLcs;
  1176   1189     }
  1177   1190   
         1191  + matchinfo_lcs_out:
  1178   1192     sqlite3_free(aIter);
  1179         -  return SQLITE_OK;
         1193  +  return rc;
  1180   1194   }
  1181   1195   
  1182   1196   /*
  1183   1197   ** Populate the buffer pInfo->aMatchinfo[] with an array of integers to
  1184   1198   ** be returned by the matchinfo() function. Argument zArg contains the 
  1185   1199   ** format string passed as the second argument to matchinfo (or the
  1186   1200   ** default value "pcx" if no second argument was specified). The format
................................................................................
  1268   1282           }
  1269   1283           break;
  1270   1284   
  1271   1285         case FTS3_MATCHINFO_LHITS_BM:
  1272   1286         case FTS3_MATCHINFO_LHITS: {
  1273   1287           int nZero = fts3MatchinfoSize(pInfo, zArg[i]) * sizeof(u32);
  1274   1288           memset(pInfo->aMatchinfo, 0, nZero);
  1275         -        fts3ExprLHitGather(pCsr->pExpr, pInfo);
         1289  +        rc = fts3ExprLHitGather(pCsr->pExpr, pInfo);
  1276   1290           break;
  1277   1291         }
  1278   1292   
  1279   1293         default: {
  1280   1294           Fts3Expr *pExpr;
  1281   1295           assert( zArg[i]==FTS3_MATCHINFO_HITS );
  1282   1296           pExpr = pCsr->pExpr;
................................................................................
  1419   1433     SnippetFragment aSnippet[4];    /* Maximum of 4 fragments per snippet */
  1420   1434     int nFToken = -1;               /* Number of tokens in each fragment */
  1421   1435   
  1422   1436     if( !pCsr->pExpr ){
  1423   1437       sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC);
  1424   1438       return;
  1425   1439     }
         1440  +
         1441  +  /* Limit the snippet length to 64 tokens. */
         1442  +  if( nToken<-64 ) nToken = -64;
         1443  +  if( nToken>+64 ) nToken = +64;
  1426   1444   
  1427   1445     for(nSnippet=1; 1; nSnippet++){
  1428   1446   
  1429   1447       int iSnip;                    /* Loop counter 0..nSnippet-1 */
  1430   1448       u64 mCovered = 0;             /* Bitmask of phrases covered by snippet */
  1431   1449       u64 mSeen = 0;                /* Bitmask of phrases seen by BestSnippet() */
  1432   1450   
................................................................................
  1562   1580     assert( pCsr->isRequireSeek==0 );
  1563   1581   
  1564   1582     /* Count the number of terms in the query */
  1565   1583     rc = fts3ExprLoadDoclists(pCsr, 0, &nToken);
  1566   1584     if( rc!=SQLITE_OK ) goto offsets_out;
  1567   1585   
  1568   1586     /* Allocate the array of TermOffset iterators. */
  1569         -  sCtx.aTerm = (TermOffset *)sqlite3_malloc(sizeof(TermOffset)*nToken);
         1587  +  sCtx.aTerm = (TermOffset *)sqlite3_malloc64(sizeof(TermOffset)*nToken);
  1570   1588     if( 0==sCtx.aTerm ){
  1571   1589       rc = SQLITE_NOMEM;
  1572   1590       goto offsets_out;
  1573   1591     }
  1574   1592     sCtx.iDocid = pCsr->iPrevId;
  1575   1593     sCtx.pCsr = pCsr;
  1576   1594   

Changes to ext/fts3/fts3_term.c.

    64     64     sqlite3_vtab **ppVtab,          /* OUT: New sqlite3_vtab object */
    65     65     char **pzErr                    /* OUT: sqlite3_malloc'd error message */
    66     66   ){
    67     67     char const *zDb;                /* Name of database (e.g. "main") */
    68     68     char const *zFts3;              /* Name of fts3 table */
    69     69     int nDb;                        /* Result of strlen(zDb) */
    70     70     int nFts3;                      /* Result of strlen(zFts3) */
    71         -  int nByte;                      /* Bytes of space to allocate here */
           71  +  sqlite3_int64 nByte;            /* Bytes of space to allocate here */
    72     72     int rc;                         /* value returned by declare_vtab() */
    73         -  Fts3termTable *p;                /* Virtual table object to return */
           73  +  Fts3termTable *p;               /* Virtual table object to return */
    74     74     int iIndex = 0;
    75     75   
    76     76     UNUSED_PARAMETER(pCtx);
    77     77     if( argc==5 ){
    78     78       iIndex = atoi(argv[4]);
    79     79       argc--;
    80     80     }
................................................................................
    92     92     zFts3 = argv[3];
    93     93     nFts3 = (int)strlen(zFts3);
    94     94   
    95     95     rc = sqlite3_declare_vtab(db, FTS3_TERMS_SCHEMA);
    96     96     if( rc!=SQLITE_OK ) return rc;
    97     97   
    98     98     nByte = sizeof(Fts3termTable) + sizeof(Fts3Table) + nDb + nFts3 + 2;
    99         -  p = (Fts3termTable *)sqlite3_malloc(nByte);
           99  +  p = (Fts3termTable *)sqlite3_malloc64(nByte);
   100    100     if( !p ) return SQLITE_NOMEM;
   101    101     memset(p, 0, nByte);
   102    102   
   103    103     p->pFts3Tab = (Fts3Table *)&p[1];
   104    104     p->pFts3Tab->zDb = (char *)&p->pFts3Tab[1];
   105    105     p->pFts3Tab->zName = &p->pFts3Tab->zDb[nDb+1];
   106    106     p->pFts3Tab->db = db;
................................................................................
   357    357        0,                           /* xSync         */
   358    358        0,                           /* xCommit       */
   359    359        0,                           /* xRollback     */
   360    360        0,                           /* xFindFunction */
   361    361        0,                           /* xRename       */
   362    362        0,                           /* xSavepoint    */
   363    363        0,                           /* xRelease      */
   364         -     0                            /* xRollbackTo   */
          364  +     0,                           /* xRollbackTo   */
          365  +     0                            /* xShadowName   */
   365    366     };
   366    367     int rc;                         /* Return code */
   367    368   
   368    369     rc = sqlite3_create_module(db, "fts4term", &fts3term_module, 0);
   369    370     return rc;
   370    371   }
   371    372   
   372    373   #endif
   373    374   #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */

Changes to ext/fts3/fts3_test.c.

   569    569     UNUSED_PARAMETER(clientData);
   570    570     return TCL_OK;
   571    571   }
   572    572   
   573    573   /* 
   574    574   ** End of tokenizer code.
   575    575   **************************************************************************/ 
          576  +
          577  +/*
          578  +**      sqlite3_fts3_may_be_corrupt BOOLEAN
          579  +**
          580  +** Set or clear the global "may-be-corrupt" flag. Return the old value.
          581  +*/
          582  +static int SQLITE_TCLAPI fts3_may_be_corrupt(
          583  +  void * clientData,
          584  +  Tcl_Interp *interp,
          585  +  int objc,
          586  +  Tcl_Obj *CONST objv[]
          587  +){
          588  +  int bOld = sqlite3_fts3_may_be_corrupt;
          589  +
          590  +  if( objc!=2 && objc!=1 ){
          591  +    Tcl_WrongNumArgs(interp, 1, objv, "?BOOLEAN?");
          592  +    return TCL_ERROR;
          593  +  }
          594  +  if( objc==2 ){
          595  +    int bNew;
          596  +    if( Tcl_GetBooleanFromObj(interp, objv[1], &bNew) ) return TCL_ERROR;
          597  +    sqlite3_fts3_may_be_corrupt = bNew;
          598  +  }
          599  +
          600  +  Tcl_SetObjResult(interp, Tcl_NewIntObj(bOld));
          601  +  return TCL_OK;
          602  +}
   576    603   
   577    604   int Sqlitetestfts3_Init(Tcl_Interp *interp){
   578    605     Tcl_CreateObjCommand(interp, "fts3_near_match", fts3_near_match_cmd, 0, 0);
   579    606     Tcl_CreateObjCommand(interp, 
   580    607         "fts3_configure_incr_load", fts3_configure_incr_load_cmd, 0, 0
   581    608     );
   582    609     Tcl_CreateObjCommand(
   583    610         interp, "fts3_test_tokenizer", fts3_test_tokenizer_cmd, 0, 0
   584    611     );
   585         -
   586    612     Tcl_CreateObjCommand(
   587    613         interp, "fts3_test_varint", fts3_test_varint_cmd, 0, 0
   588    614     );
          615  +  Tcl_CreateObjCommand(
          616  +      interp, "sqlite3_fts3_may_be_corrupt", fts3_may_be_corrupt, 0, 0
          617  +  );
   589    618     return TCL_OK;
   590    619   }
   591    620   #endif                  /* SQLITE_ENABLE_FTS3 || SQLITE_ENABLE_FTS4 */
   592    621   #endif                  /* ifdef SQLITE_TEST */

Changes to ext/fts3/fts3_tokenize_vtab.c.

   118    118       int nByte = 0;
   119    119       char **azDequote;
   120    120   
   121    121       for(i=0; i<argc; i++){
   122    122         nByte += (int)(strlen(argv[i]) + 1);
   123    123       }
   124    124   
   125         -    *pazDequote = azDequote = sqlite3_malloc(sizeof(char *)*argc + nByte);
          125  +    *pazDequote = azDequote = sqlite3_malloc64(sizeof(char *)*argc + nByte);
   126    126       if( azDequote==0 ){
   127    127         rc = SQLITE_NOMEM;
   128    128       }else{
   129    129         char *pSpace = (char *)&azDequote[argc];
   130    130         for(i=0; i<argc; i++){
   131    131           int n = (int)strlen(argv[i]);
   132    132           azDequote[i] = pSpace;
................................................................................
   439    439        0,                           /* xSync         */
   440    440        0,                           /* xCommit       */
   441    441        0,                           /* xRollback     */
   442    442        0,                           /* xFindFunction */
   443    443        0,                           /* xRename       */
   444    444        0,                           /* xSavepoint    */
   445    445        0,                           /* xRelease      */
   446         -     0                            /* xRollbackTo   */
          446  +     0,                           /* xRollbackTo   */
          447  +     0                            /* xShadowName   */
   447    448     };
   448    449     int rc;                         /* Return code */
   449    450   
   450    451     rc = sqlite3_create_module(db, "fts3tokenize", &fts3tok_module, (void*)pHash);
   451    452     return rc;
   452    453   }
   453    454   
   454    455   #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_FTS3) */

Changes to ext/fts3/fts3_unicode.c.

    78     78   #endif /* ifndef SQLITE_AMALGAMATION */
    79     79   
    80     80   typedef struct unicode_tokenizer unicode_tokenizer;
    81     81   typedef struct unicode_cursor unicode_cursor;
    82     82   
    83     83   struct unicode_tokenizer {
    84     84     sqlite3_tokenizer base;
    85         -  int bRemoveDiacritic;
           85  +  int eRemoveDiacritic;
    86     86     int nException;
    87     87     int *aiException;
    88     88   };
    89     89   
    90     90   struct unicode_cursor {
    91     91     sqlite3_tokenizer_cursor base;
    92     92     const unsigned char *aInput;    /* Input text being tokenized */
................................................................................
   151    151       }
   152    152     }
   153    153   
   154    154     if( nEntry ){
   155    155       int *aNew;                    /* New aiException[] array */
   156    156       int nNew;                     /* Number of valid entries in array aNew[] */
   157    157   
   158         -    aNew = sqlite3_realloc(p->aiException, (p->nException+nEntry)*sizeof(int));
          158  +    aNew = sqlite3_realloc64(p->aiException,(p->nException+nEntry)*sizeof(int));
   159    159       if( aNew==0 ) return SQLITE_NOMEM;
   160    160       nNew = p->nException;
   161    161   
   162    162       z = (const unsigned char *)zIn;
   163    163       while( z<zTerm ){
   164    164         READ_UTF8(z, zTerm, iCode);
   165    165         if( sqlite3FtsUnicodeIsalnum((int)iCode)!=bAlnum 
................................................................................
   223    223     unicode_tokenizer *pNew;        /* New tokenizer object */
   224    224     int i;
   225    225     int rc = SQLITE_OK;
   226    226   
   227    227     pNew = (unicode_tokenizer *) sqlite3_malloc(sizeof(unicode_tokenizer));
   228    228     if( pNew==NULL ) return SQLITE_NOMEM;
   229    229     memset(pNew, 0, sizeof(unicode_tokenizer));
   230         -  pNew->bRemoveDiacritic = 1;
          230  +  pNew->eRemoveDiacritic = 1;
   231    231   
   232    232     for(i=0; rc==SQLITE_OK && i<nArg; i++){
   233    233       const char *z = azArg[i];
   234    234       int n = (int)strlen(z);
   235    235   
   236    236       if( n==19 && memcmp("remove_diacritics=1", z, 19)==0 ){
   237         -      pNew->bRemoveDiacritic = 1;
          237  +      pNew->eRemoveDiacritic = 1;
   238    238       }
   239    239       else if( n==19 && memcmp("remove_diacritics=0", z, 19)==0 ){
   240         -      pNew->bRemoveDiacritic = 0;
          240  +      pNew->eRemoveDiacritic = 0;
          241  +    }
          242  +    else if( n==19 && memcmp("remove_diacritics=2", z, 19)==0 ){
          243  +      pNew->eRemoveDiacritic = 2;
   241    244       }
   242    245       else if( n>=11 && memcmp("tokenchars=", z, 11)==0 ){
   243    246         rc = unicodeAddExceptions(pNew, 1, &z[11], n-11);
   244    247       }
   245    248       else if( n>=11 && memcmp("separators=", z, 11)==0 ){
   246    249         rc = unicodeAddExceptions(pNew, 0, &z[11], n-11);
   247    250       }
................................................................................
   337    340   
   338    341     zOut = pCsr->zToken;
   339    342     do {
   340    343       int iOut;
   341    344   
   342    345       /* Grow the output buffer if required. */
   343    346       if( (zOut-pCsr->zToken)>=(pCsr->nAlloc-4) ){
   344         -      char *zNew = sqlite3_realloc(pCsr->zToken, pCsr->nAlloc+64);
          347  +      char *zNew = sqlite3_realloc64(pCsr->zToken, pCsr->nAlloc+64);
   345    348         if( !zNew ) return SQLITE_NOMEM;
   346    349         zOut = &zNew[zOut - pCsr->zToken];
   347    350         pCsr->zToken = zNew;
   348    351         pCsr->nAlloc += 64;
   349    352       }
   350    353   
   351    354       /* Write the folded case of the last character read to the output */
   352    355       zEnd = z;
   353         -    iOut = sqlite3FtsUnicodeFold((int)iCode, p->bRemoveDiacritic);
          356  +    iOut = sqlite3FtsUnicodeFold((int)iCode, p->eRemoveDiacritic);
   354    357       if( iOut ){
   355    358         WRITE_UTF8(zOut, iOut);
   356    359       }
   357    360   
   358    361       /* If the cursor is not at EOF, read the next character */
   359    362       if( z>=zTerm ) break;
   360    363       READ_UTF8(z, zTerm, iCode);

Changes to ext/fts3/fts3_unicode2.c.

     1      1   /*
     2         -** 2012 May 25
            2  +** 2012-05-25
     3      3   **
     4      4   ** The author disclaims copyright to this source code.  In place of
     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
................................................................................
   155    155   ** If the argument is a codepoint corresponding to a lowercase letter
   156    156   ** in the ASCII range with a diacritic added, return the codepoint
   157    157   ** of the ASCII letter only. For example, if passed 235 - "LATIN
   158    158   ** SMALL LETTER E WITH DIAERESIS" - return 65 ("LATIN SMALL LETTER
   159    159   ** E"). The resuls of passing a codepoint that corresponds to an
   160    160   ** uppercase letter are undefined.
   161    161   */
   162         -static int remove_diacritic(int c){
          162  +static int remove_diacritic(int c, int bComplex){
   163    163     unsigned short aDia[] = {
   164    164           0,  1797,  1848,  1859,  1891,  1928,  1940,  1995, 
   165    165        2024,  2040,  2060,  2110,  2168,  2206,  2264,  2286, 
   166    166        2344,  2383,  2472,  2488,  2516,  2596,  2668,  2732, 
   167    167        2782,  2842,  2894,  2954,  2984,  3000,  3028,  3336, 
   168         -     3456,  3696,  3712,  3728,  3744,  3896,  3912,  3928, 
   169         -     3968,  4008,  4040,  4106,  4138,  4170,  4202,  4234, 
   170         -     4266,  4296,  4312,  4344,  4408,  4424,  4472,  4504, 
   171         -     6148,  6198,  6264,  6280,  6360,  6429,  6505,  6529, 
   172         -    61448, 61468, 61534, 61592, 61642, 61688, 61704, 61726, 
   173         -    61784, 61800, 61836, 61880, 61914, 61948, 61998, 62122, 
   174         -    62154, 62200, 62218, 62302, 62364, 62442, 62478, 62536, 
   175         -    62554, 62584, 62604, 62640, 62648, 62656, 62664, 62730, 
   176         -    62924, 63050, 63082, 63274, 63390, 
          168  +     3456,  3696,  3712,  3728,  3744,  3766,  3832,  3896, 
          169  +     3912,  3928,  3944,  3968,  4008,  4040,  4056,  4106, 
          170  +     4138,  4170,  4202,  4234,  4266,  4296,  4312,  4344, 
          171  +     4408,  4424,  4442,  4472,  4488,  4504,  6148,  6198, 
          172  +     6264,  6280,  6360,  6429,  6505,  6529, 61448, 61468, 
          173  +    61512, 61534, 61592, 61610, 61642, 61672, 61688, 61704, 
          174  +    61726, 61784, 61800, 61816, 61836, 61880, 61896, 61914, 
          175  +    61948, 61998, 62062, 62122, 62154, 62184, 62200, 62218, 
          176  +    62252, 62302, 62364, 62410, 62442, 62478, 62536, 62554, 
          177  +    62584, 62604, 62640, 62648, 62656, 62664, 62730, 62766, 
          178  +    62830, 62890, 62924, 62974, 63032, 63050, 63082, 63118, 
          179  +    63182, 63242, 63274, 63310, 63368, 63390, 
   177    180     };
   178         -  char aChar[] = {
   179         -    '\0', 'a',  'c',  'e',  'i',  'n',  'o',  'u',  'y',  'y',  'a',  'c',  
   180         -    'd',  'e',  'e',  'g',  'h',  'i',  'j',  'k',  'l',  'n',  'o',  'r',  
   181         -    's',  't',  'u',  'u',  'w',  'y',  'z',  'o',  'u',  'a',  'i',  'o',  
   182         -    'u',  'g',  'k',  'o',  'j',  'g',  'n',  'a',  'e',  'i',  'o',  'r',  
   183         -    'u',  's',  't',  'h',  'a',  'e',  'o',  'y',  '\0', '\0', '\0', '\0', 
   184         -    '\0', '\0', '\0', '\0', 'a',  'b',  'd',  'd',  'e',  'f',  'g',  'h',  
   185         -    'h',  'i',  'k',  'l',  'l',  'm',  'n',  'p',  'r',  'r',  's',  't',  
   186         -    'u',  'v',  'w',  'w',  'x',  'y',  'z',  'h',  't',  'w',  'y',  'a',  
   187         -    'e',  'i',  'o',  'u',  'y',  
          181  +#define HIBIT ((unsigned char)0x80)
          182  +  unsigned char aChar[] = {
          183  +    '\0',      'a',       'c',       'e',       'i',       'n',       
          184  +    'o',       'u',       'y',       'y',       'a',       'c',       
          185  +    'd',       'e',       'e',       'g',       'h',       'i',       
          186  +    'j',       'k',       'l',       'n',       'o',       'r',       
          187  +    's',       't',       'u',       'u',       'w',       'y',       
          188  +    'z',       'o',       'u',       'a',       'i',       'o',       
          189  +    'u',       'u'|HIBIT, 'a'|HIBIT, 'g',       'k',       'o',       
          190  +    'o'|HIBIT, 'j',       'g',       'n',       'a'|HIBIT, 'a',       
          191  +    'e',       'i',       'o',       'r',       'u',       's',       
          192  +    't',       'h',       'a',       'e',       'o'|HIBIT, 'o',       
          193  +    'o'|HIBIT, 'y',       '\0',      '\0',      '\0',      '\0',      
          194  +    '\0',      '\0',      '\0',      '\0',      'a',       'b',       
          195  +    'c'|HIBIT, 'd',       'd',       'e'|HIBIT, 'e',       'e'|HIBIT, 
          196  +    'f',       'g',       'h',       'h',       'i',       'i'|HIBIT, 
          197  +    'k',       'l',       'l'|HIBIT, 'l',       'm',       'n',       
          198  +    'o'|HIBIT, 'p',       'r',       'r'|HIBIT, 'r',       's',       
          199  +    's'|HIBIT, 't',       'u',       'u'|HIBIT, 'v',       'w',       
          200  +    'w',       'x',       'y',       'z',       'h',       't',       
          201  +    'w',       'y',       'a',       'a'|HIBIT, 'a'|HIBIT, 'a'|HIBIT, 
          202  +    'e',       'e'|HIBIT, 'e'|HIBIT, 'i',       'o',       'o'|HIBIT, 
          203  +    'o'|HIBIT, 'o'|HIBIT, 'u',       'u'|HIBIT, 'u'|HIBIT, 'y',       
   188    204     };
   189    205   
   190    206     unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
   191    207     int iRes = 0;
   192    208     int iHi = sizeof(aDia)/sizeof(aDia[0]) - 1;
   193    209     int iLo = 0;
   194    210     while( iHi>=iLo ){
................................................................................
   197    213         iRes = iTest;
   198    214         iLo = iTest+1;
   199    215       }else{
   200    216         iHi = iTest-1;
   201    217       }
   202    218     }
   203    219     assert( key>=aDia[iRes] );
   204         -  return ((c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : (int)aChar[iRes]);
          220  +  if( bComplex==0 && (aChar[iRes] & 0x80) ) return c;
          221  +  return (c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : ((int)aChar[iRes] & 0x7F);
   205    222   }
   206    223   
   207    224   
   208    225   /*
   209    226   ** Return true if the argument interpreted as a unicode codepoint
   210    227   ** is a diacritical modifier character.
   211    228   */
   212    229   int sqlite3FtsUnicodeIsdiacritic(int c){
   213    230     unsigned int mask0 = 0x08029FDF;
   214    231     unsigned int mask1 = 0x000361F8;
   215    232     if( c<768 || c>817 ) return 0;
   216    233     return (c < 768+32) ?
   217         -      (mask0 & (1 << (c-768))) :
   218         -      (mask1 & (1 << (c-768-32)));
          234  +      (mask0 & ((unsigned int)1 << (c-768))) :
          235  +      (mask1 & ((unsigned int)1 << (c-768-32)));
   219    236   }
   220    237   
   221    238   
   222    239   /*
   223    240   ** Interpret the argument as a unicode codepoint. If the codepoint
   224    241   ** is an upper case character that has a lower case equivalent,
   225    242   ** return the codepoint corresponding to the lower case version.
   226    243   ** Otherwise, return a copy of the argument.
   227    244   **
   228    245   ** The results are undefined if the value passed to this function
   229    246   ** is less than zero.
   230    247   */
   231         -int sqlite3FtsUnicodeFold(int c, int bRemoveDiacritic){
          248  +int sqlite3FtsUnicodeFold(int c, int eRemoveDiacritic){
   232    249     /* Each entry in the following array defines a rule for folding a range
   233    250     ** of codepoints to lower case. The rule applies to a range of nRange
   234    251     ** codepoints starting at codepoint iCode.
   235    252     **
   236    253     ** If the least significant bit in flags is clear, then the rule applies
   237    254     ** to all nRange codepoints (i.e. all nRange codepoints are upper case and
   238    255     ** need to be folded). Or, if it is set, then the rule only applies to
................................................................................
   347    364       assert( iRes>=0 && c>=aEntry[iRes].iCode );
   348    365       p = &aEntry[iRes];
   349    366       if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){
   350    367         ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF;
   351    368         assert( ret>0 );
   352    369       }
   353    370   
   354         -    if( bRemoveDiacritic ) ret = remove_diacritic(ret);
          371  +    if( eRemoveDiacritic ){
          372  +      ret = remove_diacritic(ret, eRemoveDiacritic==2);
          373  +    }
   355    374     }
   356    375     
   357    376     else if( c>=66560 && c<66600 ){
   358    377       ret = c + 40;
   359    378     }
   360    379   
   361    380     return ret;
   362    381   }
   363    382   #endif /* defined(SQLITE_ENABLE_FTS3) || defined(SQLITE_ENABLE_FTS4) */
   364    383   #endif /* !defined(SQLITE_DISABLE_FTS3_UNICODE) */

Changes to ext/fts3/fts3_write.c.

   392    392     sqlite3_stmt *pStmt;
   393    393   
   394    394     assert( SizeofArray(azSql)==SizeofArray(p->aStmt) );
   395    395     assert( eStmt<SizeofArray(azSql) && eStmt>=0 );
   396    396     
   397    397     pStmt = p->aStmt[eStmt];
   398    398     if( !pStmt ){
          399  +    int f = SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_NO_VTAB;
   399    400       char *zSql;
   400    401       if( eStmt==SQL_CONTENT_INSERT ){
   401    402         zSql = sqlite3_mprintf(azSql[eStmt], p->zDb, p->zName, p->zWriteExprlist);
   402    403       }else if( eStmt==SQL_SELECT_CONTENT_BY_ROWID ){
          404  +      f &= ~SQLITE_PREPARE_NO_VTAB;
   403    405         zSql = sqlite3_mprintf(azSql[eStmt], p->zReadExprlist);
   404    406       }else{
   405    407         zSql = sqlite3_mprintf(azSql[eStmt], p->zDb, p->zName);
   406    408       }
   407    409       if( !zSql ){
   408    410         rc = SQLITE_NOMEM;
   409    411       }else{
   410         -      rc = sqlite3_prepare_v3(p->db, zSql, -1, SQLITE_PREPARE_PERSISTENT,
   411         -                              &pStmt, NULL);
          412  +      rc = sqlite3_prepare_v3(p->db, zSql, -1, f, &pStmt, NULL);
   412    413         sqlite3_free(zSql);
   413    414         assert( rc==SQLITE_OK || pStmt==0 );
   414    415         p->aStmt[eStmt] = pStmt;
   415    416       }
   416    417     }
   417    418     if( apVal ){
   418    419       int i;
................................................................................
   562    563   static sqlite3_int64 getAbsoluteLevel(
   563    564     Fts3Table *p,                   /* FTS3 table handle */
   564    565     int iLangid,                    /* Language id */
   565    566     int iIndex,                     /* Index in p->aIndex[] */
   566    567     int iLevel                      /* Level of segments */
   567    568   ){
   568    569     sqlite3_int64 iBase;            /* First absolute level for iLangid/iIndex */
   569         -  assert( iLangid>=0 );
          570  +  assert_fts3_nc( iLangid>=0 );
   570    571     assert( p->nIndex>0 );
   571    572     assert( iIndex>=0 && iIndex<p->nIndex );
   572    573   
   573    574     iBase = ((sqlite3_int64)iLangid * p->nIndex + iIndex) * FTS3_SEGDIR_MAXLEVEL;
   574    575     return iBase + iLevel;
   575    576   }
   576    577   
................................................................................
  1404   1405     pReader->aDoclist = pNext;
  1405   1406     pReader->pOffsetList = 0;
  1406   1407   
  1407   1408     /* Check that the doclist does not appear to extend past the end of the
  1408   1409     ** b-tree node. And that the final byte of the doclist is 0x00. If either 
  1409   1410     ** of these statements is untrue, then the data structure is corrupt.
  1410   1411     */
  1411         -  if( (&pReader->aNode[pReader->nNode] - pReader->aDoclist)<pReader->nDoclist
         1412  +  if( pReader->nDoclist > pReader->nNode-(pReader->aDoclist-pReader->aNode)
  1412   1413      || (pReader->nPopulate==0 && pReader->aDoclist[pReader->nDoclist-1])
  1413   1414     ){
  1414   1415       return FTS_CORRUPT_VTAB;
  1415   1416     }
  1416   1417     return SQLITE_OK;
  1417   1418   }
  1418   1419   
................................................................................
  1604   1605     const char *zRoot,              /* Buffer containing root node */
  1605   1606     int nRoot,                      /* Size of buffer containing root node */
  1606   1607     Fts3SegReader **ppReader        /* OUT: Allocated Fts3SegReader */
  1607   1608   ){
  1608   1609     Fts3SegReader *pReader;         /* Newly allocated SegReader object */
  1609   1610     int nExtra = 0;                 /* Bytes to allocate segment root node */
  1610   1611   
  1611         -  assert( iStartLeaf<=iEndLeaf );
         1612  +  assert( zRoot!=0 || nRoot==0 );
         1613  +#ifdef CORRUPT_DB
         1614  +  assert( zRoot!=0 || CORRUPT_DB );
         1615  +#endif
         1616  +
  1612   1617     if( iStartLeaf==0 ){
         1618  +    if( iEndLeaf!=0 ) return FTS_CORRUPT_VTAB;
  1613   1619       nExtra = nRoot + FTS3_NODE_PADDING;
  1614   1620     }
  1615   1621   
  1616   1622     pReader = (Fts3SegReader *)sqlite3_malloc(sizeof(Fts3SegReader) + nExtra);
  1617   1623     if( !pReader ){
  1618   1624       return SQLITE_NOMEM;
  1619   1625     }
................................................................................
  1625   1631     pReader->iEndBlock = iEndBlock;
  1626   1632   
  1627   1633     if( nExtra ){
  1628   1634       /* The entire segment is stored in the root node. */
  1629   1635       pReader->aNode = (char *)&pReader[1];
  1630   1636       pReader->rootOnly = 1;
  1631   1637       pReader->nNode = nRoot;
  1632         -    memcpy(pReader->aNode, zRoot, nRoot);
         1638  +    if( nRoot ) memcpy(pReader->aNode, zRoot, nRoot);
  1633   1639       memset(&pReader->aNode[nRoot], 0, FTS3_NODE_PADDING);
  1634   1640     }else{
  1635   1641       pReader->iCurrentBlock = iStartLeaf-1;
  1636   1642     }
  1637   1643     *ppReader = pReader;
  1638   1644     return SQLITE_OK;
  1639   1645   }
................................................................................
  2244   2250       rc = sqlite3_reset(pStmt);
  2245   2251       if( rc!=SQLITE_OK ) return rc;
  2246   2252     }
  2247   2253     nData = pWriter->nData;
  2248   2254   
  2249   2255     nPrefix = fts3PrefixCompress(pWriter->zTerm, pWriter->nTerm, zTerm, nTerm);
  2250   2256     nSuffix = nTerm-nPrefix;
         2257  +
         2258  +  /* If nSuffix is zero or less, then zTerm/nTerm must be a prefix of 
         2259  +  ** pWriter->zTerm/pWriter->nTerm. i.e. must be equal to or less than when
         2260  +  ** compared with BINARY collation. This indicates corruption.  */
         2261  +  if( nSuffix<=0 ) return FTS_CORRUPT_VTAB;
  2251   2262   
  2252   2263     /* Figure out how many bytes are required by this new entry */
  2253   2264     nReq = sqlite3Fts3VarintLen(nPrefix) +    /* varint containing prefix size */
  2254   2265       sqlite3Fts3VarintLen(nSuffix) +         /* varint containing suffix size */
  2255   2266       nSuffix +                               /* Term suffix */
  2256   2267       sqlite3Fts3VarintLen(nDoclist) +        /* Size of doclist */
  2257   2268       nDoclist;                               /* Doclist data */
................................................................................
  2952   2963             ** doclist. */
  2953   2964             sqlite3_int64 iDelta;
  2954   2965             if( p->bDescIdx && nDoclist>0 ){
  2955   2966               iDelta = iPrev - iDocid;
  2956   2967             }else{
  2957   2968               iDelta = iDocid - iPrev;
  2958   2969             }
  2959         -          assert( iDelta>0 || (nDoclist==0 && iDelta==iDocid) );
         2970  +          if( iDelta<=0 && (nDoclist>0 || iDelta!=iDocid) ){
         2971  +            return FTS_CORRUPT_VTAB;
         2972  +          }
  2960   2973             assert( nDoclist>0 || iDelta==iDocid );
  2961   2974   
  2962   2975             nByte = sqlite3Fts3VarintLen(iDelta) + (isRequirePos?nList+1:0);
  2963   2976             if( nDoclist+nByte>pCsr->nBuffer ){
  2964   2977               char *aNew;
  2965   2978               pCsr->nBuffer = (nDoclist+nByte)*2;
  2966   2979               aNew = sqlite3_realloc(pCsr->aBuffer, pCsr->nBuffer);
................................................................................
  3318   3331   */
  3319   3332   static void fts3DecodeIntArray(
  3320   3333     int N,             /* The number of integers to decode */
  3321   3334     u32 *a,            /* Write the integer values */
  3322   3335     const char *zBuf,  /* The BLOB containing the varints */
  3323   3336     int nBuf           /* size of the BLOB */
  3324   3337   ){
  3325         -  int i, j;
  3326         -  UNUSED_PARAMETER(nBuf);
  3327         -  for(i=j=0; i<N; i++){
  3328         -    sqlite3_int64 x;
  3329         -    j += sqlite3Fts3GetVarint(&zBuf[j], &x);
  3330         -    assert(j<=nBuf);
  3331         -    a[i] = (u32)(x & 0xffffffff);
         3338  +  int i = 0;
         3339  +  if( nBuf && (zBuf[nBuf-1]&0x80)==0 ){
         3340  +    int j;
         3341  +    for(i=j=0; i<N && j<nBuf; i++){
         3342  +      sqlite3_int64 x;
         3343  +      j += sqlite3Fts3GetVarint(&zBuf[j], &x);
         3344  +      a[i] = (u32)(x & 0xffffffff);
         3345  +    }
  3332   3346     }
         3347  +  while( i<N ) a[i++] = 0;
  3333   3348   }
  3334   3349   
  3335   3350   /*
  3336   3351   ** Insert the sizes (in tokens) for each column of the document
  3337   3352   ** with docid equal to p->iPrevDocid.  The sizes are encoded as
  3338   3353   ** a blob of varints.
  3339   3354   */
................................................................................
  3731   3746     }else{
  3732   3747       if( bFirst==0 ){
  3733   3748         p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &nPrefix);
  3734   3749       }
  3735   3750       p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &nSuffix);
  3736   3751   
  3737   3752       if( nPrefix>p->iOff || nSuffix>p->nNode-p->iOff ){
  3738         -      return SQLITE_CORRUPT_VTAB;
         3753  +      return FTS_CORRUPT_VTAB;
  3739   3754       }
  3740   3755       blobGrowBuffer(&p->term, nPrefix+nSuffix, &rc);
  3741   3756       if( rc==SQLITE_OK ){
  3742   3757         memcpy(&p->term.a[nPrefix], &p->aNode[p->iOff], nSuffix);
  3743   3758         p->term.n = nPrefix+nSuffix;
  3744   3759         p->iOff += nSuffix;
  3745   3760         if( p->iChild==0 ){
  3746   3761           p->iOff += fts3GetVarint32(&p->aNode[p->iOff], &p->nDoclist);
  3747   3762           if( (p->nNode-p->iOff)<p->nDoclist ){
  3748         -          return SQLITE_CORRUPT_VTAB;
         3763  +          return FTS_CORRUPT_VTAB;
  3749   3764           }
  3750   3765           p->aDoclist = &p->aNode[p->iOff];
  3751   3766           p->iOff += p->nDoclist;
  3752   3767         }
  3753   3768       }
  3754   3769     }
  3755   3770   

Changes to ext/fts3/unicode/mkunicode.tcl.

     5      5     global tl_lookup_table
     6      6     set aChar [list]
     7      7     set lRange [list]
     8      8   
     9      9     set nRange 1
    10     10     set iFirst  [lindex $map 0 0]
    11     11     set cPrev   [lindex $map 0 1]
           12  +  set fPrev   [lindex $map 0 2]
    12     13   
    13     14     foreach m [lrange $map 1 end] {
    14         -    foreach {i c} $m {}
           15  +    foreach {i c f} $m {}
    15     16   
    16         -    if {$cPrev == $c} {
           17  +    if {$cPrev == $c && $fPrev==$f} {
    17     18         for {set j [expr $iFirst+$nRange]} {$j<$i} {incr j} {
    18     19           if {[info exists tl_lookup_table($j)]==0} break
    19     20         }
    20     21   
    21     22         if {$j==$i} {
    22     23           set nNew [expr {(1 + $i - $iFirst)}]
    23     24           if {$nNew<=8} {
................................................................................
    25     26             continue
    26     27           }
    27     28         }
    28     29       }
    29     30   
    30     31       lappend lRange [list $iFirst $nRange]
    31     32       lappend aChar  $cPrev
           33  +    lappend aFlag  $fPrev
    32     34   
    33     35       set iFirst $i
    34     36       set cPrev  $c
           37  +    set fPrev  $f
    35     38       set nRange 1
    36     39     }
    37     40     lappend lRange [list $iFirst $nRange]
    38     41     lappend aChar $cPrev
           42  +  lappend aFlag $fPrev
    39     43   
    40     44     puts "/*"
    41     45     puts "** If the argument is a codepoint corresponding to a lowercase letter"
    42     46     puts "** in the ASCII range with a diacritic added, return the codepoint"
    43     47     puts "** of the ASCII letter only. For example, if passed 235 - \"LATIN"
    44     48     puts "** SMALL LETTER E WITH DIAERESIS\" - return 65 (\"LATIN SMALL LETTER"
    45     49     puts "** E\"). The resuls of passing a codepoint that corresponds to an"
    46     50     puts "** uppercase letter are undefined."
    47     51     puts "*/"
    48         -  puts "static int ${::remove_diacritic}(int c)\{"
           52  +  puts "static int ${::remove_diacritic}(int c, int bComplex)\{"
    49     53     puts "  unsigned short aDia\[\] = \{"
    50     54     puts -nonewline "        0, "
    51     55     set i 1
    52     56     foreach r $lRange {
    53     57       foreach {iCode nRange} $r {}
    54     58       if {($i % 8)==0} {puts "" ; puts -nonewline "    " }
    55     59       incr i
    56     60   
    57     61       puts -nonewline [format "%5d" [expr ($iCode<<3) + $nRange-1]]
    58     62       puts -nonewline ", "
    59     63     }
    60     64     puts ""
    61     65     puts "  \};"
    62         -  puts "  char aChar\[\] = \{"
    63         -  puts -nonewline "    '\\0', "
           66  +  puts "#define HIBIT ((unsigned char)0x80)"
           67  +  puts "  unsigned char aChar\[\] = \{"
           68  +  puts -nonewline "    '\\0',      "
    64     69     set i 1
    65         -  foreach c $aChar {
    66         -    set str "'$c',  "
    67         -    if {$c == ""} { set str "'\\0', " }
           70  +  foreach c $aChar f $aFlag {
           71  +    if { $f } {
           72  +      set str "'$c'|HIBIT, "
           73  +    } else {
           74  +      set str "'$c',       "
           75  +    }
           76  +    if {$c == ""} { set str "'\\0',      " }
    68     77   
    69         -    if {($i % 12)==0} {puts "" ; puts -nonewline "    " }
           78  +    if {($i % 6)==0} {puts "" ; puts -nonewline "    " }
    70     79       incr i
    71     80       puts -nonewline "$str"
    72     81     }
    73     82     puts ""
    74     83     puts "  \};"
    75     84     puts {
    76     85     unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
................................................................................
    83     92         iRes = iTest;
    84     93         iLo = iTest+1;
    85     94       }else{
    86     95         iHi = iTest-1;
    87     96       }
    88     97     }
    89     98     assert( key>=aDia[iRes] );
    90         -  return ((c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : (int)aChar[iRes]);}
           99  +  if( bComplex==0 && (aChar[iRes] & 0x80) ) return c;
          100  +  return (c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : ((int)aChar[iRes] & 0x7F);}
    91    101     puts "\}"
    92    102   }
    93    103   
    94    104   proc print_isdiacritic {zFunc map} {
    95    105   
    96    106     set lCode [list]
    97    107     foreach m $map {
    98         -    foreach {code char} $m {}
          108  +    foreach {code char flag} $m {}
          109  +    if {$flag} continue
    99    110       if {$code && $char == ""} { lappend lCode $code }
   100    111     }
   101    112     set lCode [lsort -integer $lCode]
   102    113     set iFirst [lindex $lCode 0]
   103    114     set iLast [lindex $lCode end]
   104    115   
   105    116     set i1 0
................................................................................
   120    131     puts "*/"
   121    132     puts "int ${zFunc}\(int c)\{"
   122    133     puts "  unsigned int mask0 = [format "0x%08X" $i1];"
   123    134     puts "  unsigned int mask1 = [format "0x%08X" $i2];"
   124    135   
   125    136     puts "  if( c<$iFirst || c>$iLast ) return 0;"
   126    137     puts "  return (c < $iFirst+32) ?"
   127         -  puts "      (mask0 & (1 << (c-$iFirst))) :"
   128         -  puts "      (mask1 & (1 << (c-$iFirst-32)));"
          138  +  puts "      (mask0 & ((unsigned int)1 << (c-$iFirst))) :"
          139  +  puts "      (mask1 & ((unsigned int)1 << (c-$iFirst-32)));"
   129    140     puts "\}"
   130    141   }
   131    142   
   132    143   
   133    144   #-------------------------------------------------------------------------
   134    145   
   135    146   proc an_load_separator_ranges {} {
................................................................................
   468    479     puts "** is an upper case character that has a lower case equivalent,"
   469    480     puts "** return the codepoint corresponding to the lower case version."
   470    481     puts "** Otherwise, return a copy of the argument."
   471    482     puts "**"
   472    483     puts "** The results are undefined if the value passed to this function"
   473    484     puts "** is less than zero."
   474    485     puts "*/"
   475         -  puts "int ${zFunc}\(int c, int bRemoveDiacritic)\{"
          486  +  puts "int ${zFunc}\(int c, int eRemoveDiacritic)\{"
   476    487   
   477    488     set liOff [tl_generate_ioff_table $lRecord]
   478    489     tl_print_table_header
   479    490     foreach entry $lRecord { 
   480    491       if {[tl_print_table_entry toggle $entry $liOff]} { 
   481    492         lappend lHigh $entry 
   482    493       } 
................................................................................
   512    523       assert( iRes>=0 && c>=aEntry[iRes].iCode );
   513    524       p = &aEntry[iRes];
   514    525       if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){
   515    526         ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF;
   516    527         assert( ret>0 );
   517    528       }
   518    529   
   519         -    if( bRemoveDiacritic ) ret = ${::remove_diacritic}(ret);
          530  +    if( eRemoveDiacritic ){
          531  +      ret = ${::remove_diacritic}(ret, eRemoveDiacritic==2);
          532  +    }
   520    533     }
   521    534     }]
   522    535   
   523    536     foreach entry $lHigh {
   524    537       tl_print_if_entry $entry
   525    538     }
   526    539   
................................................................................
   601    614     set caseN [categories_switch C N {d l o}]
   602    615     set caseP [categories_switch C P {c d e f i o s}]
   603    616     set caseS [categories_switch C S {c k m o}]
   604    617     set caseZ [categories_switch C Z {l p s}]
   605    618   
   606    619     set nCat [expr [llength [array names C]] + 1]
   607    620     puts [code {
   608         -    int sqlite3Fts5UnicodeNCat(void) { 
   609         -      return $nCat;
   610         -    }
   611         -
   612    621       int sqlite3Fts5UnicodeCatParse(const char *zCat, u8 *aArray){ 
   613    622         aArray[0] = 1;
   614    623         switch( zCat[0] ){
   615    624           $caseC
   616    625           $caseL
   617    626           $caseM
   618    627           $caseN
................................................................................
   687    696     set aMapArray [intarray $aMap]
   688    697     set aDataArray [intarray $aData]
   689    698     puts [code {
   690    699       static u16 aFts5UnicodeBlock[] = {$aBlockArray};
   691    700       static u16 aFts5UnicodeMap[] = {$aMapArray};
   692    701       static u16 aFts5UnicodeData[] = {$aDataArray};
   693    702   
   694         -    int sqlite3Fts5UnicodeCategory(int iCode) { 
          703  +    int sqlite3Fts5UnicodeCategory(u32 iCode) { 
   695    704         int iRes = -1;
   696    705         int iHi;
   697    706         int iLo;
   698    707         int ret;
   699    708         u16 iKey;
   700    709   
   701    710         if( iCode>=(1<<20) ){
................................................................................
   770    779           if( aCP[iCP].iCode==i ){
   771    780             sqlite3Fts5UnicodeCatParse(aCP[iCP].zCat, aArray);
   772    781             iCP++;
   773    782           }else{
   774    783             aArray[0] = 1;
   775    784           }
   776    785   
   777         -        c = sqlite3Fts5UnicodeCategory(i);
          786  +        c = sqlite3Fts5UnicodeCategory((u32)i);
   778    787           if( aArray[c]==0 ){
   779    788             *piCode = i;
   780    789             return 1;
   781    790           }
   782    791         }
   783    792   
   784    793         return 0;
................................................................................
   825    834     puts "\}"
   826    835   }
   827    836   
   828    837   
   829    838   proc print_fileheader {} {
   830    839     puts [string trim {
   831    840   /*
   832         -** 2012 May 25
          841  +** 2012-05-25
   833    842   **
   834    843   ** The author disclaims copyright to this source code.  In place of
   835    844   ** a legal notice, here is a blessing:
   836    845   **
   837    846   **    May you do good and not evil.
   838    847   **    May you find forgiveness for yourself and forgive others.
   839    848   **    May you share freely, never taking more than you give.

Changes to ext/fts3/unicode/parseunicode.tcl.

     3      3   # Parameter $zName must be a path to the file UnicodeData.txt. This command
     4      4   # reads the file and returns a list of mappings required to remove all
     5      5   # diacritical marks from a unicode string. Each mapping is itself a list
     6      6   # consisting of two elements - the unicode codepoint and the single ASCII
     7      7   # character that it should be replaced with, or an empty string if the 
     8      8   # codepoint should simply be removed from the input. Examples:
     9      9   #
    10         -#   { 224 a  }     (replace codepoint 224 to "a")
    11         -#   { 769 "" }     (remove codepoint 769 from input)
           10  +#   { 224 a  0 }     (replace codepoint 224 to "a")
           11  +#   { 769 "" 0 }     (remove codepoint 769 from input)
    12     12   #
    13     13   # Mappings are only returned for non-upper case codepoints. It is assumed
    14     14   # that the input has already been folded to lower case.
           15  +#
           16  +# The third value in the list is always either 0 or 1. 0 if the 
           17  +# UnicodeData.txt file maps the codepoint to a single ASCII character and
           18  +# a diacritic, or 1 if the mapping is indirect. For example, consider the 
           19  +# two entries:
           20  +#
           21  +# 1ECD;LATIN SMALL LETTER O WITH DOT BELOW;Ll;0;L;006F 0323;;;;N;;;1ECC;;1ECC
           22  +# 1ED9;LATIN SMALL LETTER O WITH CIRCUMFLEX AND DOT BELOW;Ll;0;L;1ECD 0302;;;;N;;;1ED8;;1ED8
           23  +#
           24  +# The first codepoint is a direct mapping (as 006F is ASCII and 0323 is a 
           25  +# diacritic). The second is an indirect mapping, as it maps to the
           26  +# first codepoint plus 0302 (a diacritic).
    15     27   #
    16     28   proc rd_load_unicodedata_text {zName} {
    17     29     global tl_lookup_table
    18     30   
    19     31     set fd [open $zName]
    20     32     set lField {
    21     33       code
................................................................................
    49     61         continue
    50     62       }
    51     63   
    52     64       set iCode  [expr "0x$code"]
    53     65       set iAscii [expr "0x[lindex $character_decomposition_mapping 0]"]
    54     66       set iDia   [expr "0x[lindex $character_decomposition_mapping 1]"]
    55     67   
           68  +    # Filter out upper-case characters, as they will be mapped to their
           69  +    # lower-case equivalents before this data is used.
    56     70       if {[info exists tl_lookup_table($iCode)]} continue
           71  +
           72  +    # Check if this is an indirect mapping. If so, set bIndirect to true
           73  +    # and change $iAscii to the indirectly mappped ASCII character.
           74  +    set bIndirect 0
           75  +    if {[info exists dia($iDia)] && [info exists mapping($iAscii)]} {
           76  +      set iAscii $mapping($iAscii)
           77  +      set bIndirect 1
           78  +    }
    57     79   
    58     80       if { ($iAscii >= 97 && $iAscii <= 122)
    59     81         || ($iAscii >= 65 && $iAscii <= 90)
    60     82       } {
    61         -      lappend lRet [list $iCode [string tolower [format %c $iAscii]]]
           83  +      lappend lRet [list $iCode [string tolower [format %c $iAscii]] $bIndirect]
           84  +      set mapping($iCode) $iAscii
    62     85         set dia($iDia) 1
    63     86       }
    64     87     }
    65     88   
    66     89     foreach d [array names dia] {
    67         -    lappend lRet [list $d ""]
           90  +    lappend lRet [list $d "" 0]
    68     91     }
    69     92     set lRet [lsort -integer -index 0 $lRet]
    70     93   
    71     94     close $fd
    72     95     set lRet
    73     96   }
    74     97   

Changes to ext/fts5/fts5.h.

   116    116   **   Query for the details of phrase match iIdx within the current row.
   117    117   **   Phrase matches are numbered starting from zero, so the iIdx argument
   118    118   **   should be greater than or equal to zero and smaller than the value
   119    119   **   output by xInstCount().
   120    120   **
   121    121   **   Usually, output parameter *piPhrase is set to the phrase number, *piCol
   122    122   **   to the column in which it occurs and *piOff the token offset of the
   123         -**   first token of the phrase. The exception is if the table was created
   124         -**   with the offsets=0 option specified. In this case *piOff is always
   125         -**   set to -1.
   126         -**
   127         -**   Returns SQLITE_OK if successful, or an error code (i.e. SQLITE_NOMEM) 
   128         -**   if an error occurs.
          123  +**   first token of the phrase. Returns SQLITE_OK if successful, or an error
          124  +**   code (i.e. SQLITE_NOMEM) if an error occurs.
   129    125   **
   130    126   **   This API can be quite slow if used with an FTS5 table created with the
   131    127   **   "detail=none" or "detail=column" option. 
   132    128   **
   133    129   ** xRowid:
   134    130   **   Returns the rowid of the current row.
   135    131   **
................................................................................
   410    406   **            same token for inputs "first" and "1st". Say that token is in
   411    407   **            fact "first", so that when the user inserts the document "I won
   412    408   **            1st place" entries are added to the index for tokens "i", "won",
   413    409   **            "first" and "place". If the user then queries for '1st + place',
   414    410   **            the tokenizer substitutes "first" for "1st" and the query works
   415    411   **            as expected.
   416    412   **
   417         -**       <li> By adding multiple synonyms for a single term to the FTS index.
   418         -**            In this case, when tokenizing query text, the tokenizer may 
   419         -**            provide multiple synonyms for a single term within the document.
   420         -**            FTS5 then queries the index for each synonym individually. For
   421         -**            example, faced with the query:
          413  +**       <li> By querying the index for all synonyms of each query term
          414  +**            separately. In this case, when tokenizing query text, the
          415  +**            tokenizer may provide multiple synonyms for a single term 
          416  +**            within the document. FTS5 then queries the index for each 
          417  +**            synonym individually. For example, faced with the query:
   422    418   **
   423    419   **   <codeblock>
   424    420   **     ... MATCH 'first place'</codeblock>
   425    421   **
   426    422   **            the tokenizer offers both "1st" and "first" as synonyms for the
   427    423   **            first token in the MATCH query and FTS5 effectively runs a query 
   428    424   **            similar to:
................................................................................
   438    434   **            Using this method, when tokenizing document text, the tokenizer
   439    435   **            provides multiple synonyms for each token. So that when a 
   440    436   **            document such as "I won first place" is tokenized, entries are
   441    437   **            added to the FTS index for "i", "won", "first", "1st" and
   442    438   **            "place".
   443    439   **
   444    440   **            This way, even if the tokenizer does not provide synonyms
   445         -**            when tokenizing query text (it should not - to do would be
          441  +**            when tokenizing query text (it should not - to do so would be
   446    442   **            inefficient), it doesn't matter if the user queries for 
   447    443   **            'first + place' or '1st + place', as there are entries in the
   448    444   **            FTS index corresponding to both forms of the first token.
   449    445   **   </ol>
   450    446   **
   451    447   **   Whether it is parsing document or query text, any call to xToken that
   452    448   **   specifies a <i>tflags</i> argument with the FTS5_TOKEN_COLOCATED bit

Changes to ext/fts5/fts5Int.h.

    83     83   #ifdef SQLITE_DEBUG
    84     84   extern int sqlite3_fts5_may_be_corrupt;
    85     85   # define assert_nc(x) assert(sqlite3_fts5_may_be_corrupt || (x))
    86     86   #else
    87     87   # define assert_nc(x) assert(x)
    88     88   #endif
    89     89   
           90  +/*
           91  +** A version of memcmp() that does not cause asan errors if one of the pointer
           92  +** parameters is NULL and the number of bytes to compare is zero.
           93  +*/
           94  +#define fts5Memcmp(s1, s2, n) ((n)==0 ? 0 : memcmp((s1), (s2), (n)))
           95  +
    90     96   /* Mark a function parameter as unused, to suppress nuisance compiler
    91     97   ** warnings. */
    92     98   #ifndef UNUSED_PARAM
    93     99   # define UNUSED_PARAM(X)  (void)(X)
    94    100   #endif
    95    101   
    96    102   #ifndef UNUSED_PARAM2
................................................................................
   270    276   )
   271    277   
   272    278   /* Write and decode big-endian 32-bit integer values */
   273    279   void sqlite3Fts5Put32(u8*, int);
   274    280   int sqlite3Fts5Get32(const u8*);
   275    281   
   276    282   #define FTS5_POS2COLUMN(iPos) (int)(iPos >> 32)
   277         -#define FTS5_POS2OFFSET(iPos) (int)(iPos & 0xFFFFFFFF)
          283  +#define FTS5_POS2OFFSET(iPos) (int)(iPos & 0x7FFFFFFF)
   278    284   
   279    285   typedef struct Fts5PoslistReader Fts5PoslistReader;
   280    286   struct Fts5PoslistReader {
   281    287     /* Variables used only by sqlite3Fts5PoslistIterXXX() functions. */
   282    288     const u8 *a;                    /* Position list to iterate through */
   283    289     int n;                          /* Size of buffer at a[] in bytes */
   284    290     int i;                          /* Current offset in a[] */
................................................................................
   305    311   int sqlite3Fts5PoslistNext64(
   306    312     const u8 *a, int n,             /* Buffer containing poslist */
   307    313     int *pi,                        /* IN/OUT: Offset within a[] */
   308    314     i64 *piOff                      /* IN/OUT: Current offset */
   309    315   );
   310    316   
   311    317   /* Malloc utility */
   312         -void *sqlite3Fts5MallocZero(int *pRc, int nByte);
          318  +void *sqlite3Fts5MallocZero(int *pRc, sqlite3_int64 nByte);
   313    319   char *sqlite3Fts5Strndup(int *pRc, const char *pIn, int nIn);
   314    320   
   315    321   /* Character set tests (like isspace(), isalpha() etc.) */
   316    322   int sqlite3Fts5IsBareword(char t);
   317    323   
   318    324   
   319    325   /* Bucket of terms object used by the integrity-check in offsets=0 mode. */
................................................................................
   516    522   
   517    523   /*
   518    524   ** End of interface to code in fts5_varint.c.
   519    525   **************************************************************************/
   520    526   
   521    527   
   522    528   /**************************************************************************
   523         -** Interface to code in fts5.c. 
          529  +** Interface to code in fts5_main.c. 
          530  +*/
          531  +
          532  +/*
          533  +** Virtual-table object.
   524    534   */
          535  +typedef struct Fts5Table Fts5Table;
          536  +struct Fts5Table {
          537  +  sqlite3_vtab base;              /* Base class used by SQLite core */
          538  +  Fts5Config *pConfig;            /* Virtual table configuration */
          539  +  Fts5Index *pIndex;              /* Full-text index */
          540  +};
   525    541   
   526    542   int sqlite3Fts5GetTokenizer(
   527    543     Fts5Global*, 
   528    544     const char **azArg,
   529    545     int nArg,
   530    546     Fts5Tokenizer**,
   531    547     fts5_tokenizer**,
   532    548     char **pzErr
   533    549   );
   534    550   
   535         -Fts5Index *sqlite3Fts5IndexFromCsrid(Fts5Global*, i64, Fts5Config **);
          551  +Fts5Table *sqlite3Fts5TableFromCsrid(Fts5Global*, i64);
          552  +
          553  +int sqlite3Fts5FlushToDisk(Fts5Table*);
   536    554   
   537    555   /*
   538    556   ** End of interface to code in fts5.c.
   539    557   **************************************************************************/
   540    558   
   541    559   /**************************************************************************
   542    560   ** Interface to code in fts5_hash.c. 
................................................................................
   784    802   /**************************************************************************
   785    803   ** Interface to automatically generated code in fts5_unicode2.c. 
   786    804   */
   787    805   int sqlite3Fts5UnicodeIsdiacritic(int c);
   788    806   int sqlite3Fts5UnicodeFold(int c, int bRemoveDiacritic);
   789    807   
   790    808   int sqlite3Fts5UnicodeCatParse(const char*, u8*);
   791         -int sqlite3Fts5UnicodeCategory(int iCode);
          809  +int sqlite3Fts5UnicodeCategory(u32 iCode);
   792    810   void sqlite3Fts5UnicodeAscii(u8*, u8*);
   793    811   /*
   794    812   ** End of interface to code in fts5_unicode2.c.
   795    813   **************************************************************************/
   796    814   
   797    815   #endif

Changes to ext/fts5/fts5_aux.c.

   132    132   ** *pRc is set to an error code before returning. 
   133    133   */
   134    134   static void fts5HighlightAppend(
   135    135     int *pRc, 
   136    136     HighlightContext *p, 
   137    137     const char *z, int n
   138    138   ){
   139         -  if( *pRc==SQLITE_OK ){
          139  +  if( *pRc==SQLITE_OK && z ){
   140    140       if( n<0 ) n = (int)strlen(z);
   141    141       p->zOut = sqlite3_mprintf("%z%.*s", p->zOut, n, z);
   142    142       if( p->zOut==0 ) *pRc = SQLITE_NOMEM;
   143    143     }
   144    144   }
   145    145   
   146    146   /*
................................................................................
   264    264   ** error occurs.
   265    265   */
   266    266   static int fts5SentenceFinderAdd(Fts5SFinder *p, int iAdd){
   267    267     if( p->nFirstAlloc==p->nFirst ){
   268    268       int nNew = p->nFirstAlloc ? p->nFirstAlloc*2 : 64;
   269    269       int *aNew;
   270    270   
   271         -    aNew = (int*)sqlite3_realloc(p->aFirst, nNew*sizeof(int));
          271  +    aNew = (int*)sqlite3_realloc64(p->aFirst, nNew*sizeof(int));
   272    272       if( aNew==0 ) return SQLITE_NOMEM;
   273    273       p->aFirst = aNew;
   274    274       p->nFirstAlloc = nNew;
   275    275     }
   276    276     p->aFirst[p->nFirst++] = iAdd;
   277    277     return SQLITE_OK;
   278    278   }
................................................................................
   331    331     int ip = 0;
   332    332     int ic = 0;
   333    333     int iOff = 0;
   334    334     int iFirst = -1;
   335    335     int nInst;
   336    336     int nScore = 0;
   337    337     int iLast = 0;
          338  +  sqlite3_int64 iEnd = (sqlite3_int64)iPos + nToken;
   338    339   
   339    340     rc = pApi->xInstCount(pFts, &nInst);
   340    341     for(i=0; i<nInst && rc==SQLITE_OK; i++){
   341    342       rc = pApi->xInst(pFts, i, &ip, &ic, &iOff);
   342         -    if( rc==SQLITE_OK && ic==iCol && iOff>=iPos && iOff<(iPos+nToken) ){
          343  +    if( rc==SQLITE_OK && ic==iCol && iOff>=iPos && iOff<iEnd ){
   343    344         nScore += (aSeen[ip] ? 1 : 1000);
   344    345         aSeen[ip] = 1;
   345    346         if( iFirst<0 ) iFirst = iOff;
   346    347         iLast = iOff + pApi->xPhraseSize(pFts, ip);
   347    348       }
   348    349     }
   349    350   
   350    351     *pnScore = nScore;
   351    352     if( piPos ){
   352         -    int iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;
          353  +    sqlite3_int64 iAdj = iFirst - (nToken - (iLast-iFirst)) / 2;
   353    354       if( (iAdj+nToken)>nDocsize ) iAdj = nDocsize - nToken;
   354    355       if( iAdj<0 ) iAdj = 0;
   355    356       *piPos = iAdj;
   356    357     }
   357    358   
   358    359     return rc;
   359    360   }
................................................................................
   438    439         for(ii=0; rc==SQLITE_OK && ii<nInst; ii++){
   439    440           int ip, ic, io;
   440    441           int iAdj;
   441    442           int nScore;
   442    443           int jj;
   443    444   
   444    445           rc = pApi->xInst(pFts, ii, &ip, &ic, &io);
   445         -        if( ic!=i || rc!=SQLITE_OK ) continue;
          446  +        if( ic!=i ) continue;
          447  +        if( io>nDocsize ) rc = FTS5_CORRUPT;
          448  +        if( rc!=SQLITE_OK ) continue;
   446    449           memset(aSeen, 0, nPhrase);
   447    450           rc = fts5SnippetScore(pApi, pFts, nDocsize, aSeen, i,
   448    451               io, nToken, &nScore, &iAdj
   449    452           );
   450    453           if( rc==SQLITE_OK && nScore>nBestScore ){
   451    454             nBestScore = nScore;
   452    455             iBestCol = i;
................................................................................
   564    567     Fts5Bm25Data *p;                /* Object to return */
   565    568   
   566    569     p = pApi->xGetAuxdata(pFts, 0);
   567    570     if( p==0 ){
   568    571       int nPhrase;                  /* Number of phrases in query */
   569    572       sqlite3_int64 nRow = 0;       /* Number of rows in table */
   570    573       sqlite3_int64 nToken = 0;     /* Number of tokens in table */
   571         -    int nByte;                    /* Bytes of space to allocate */
          574  +    sqlite3_int64 nByte;          /* Bytes of space to allocate */
   572    575       int i;
   573    576   
   574    577       /* Allocate the Fts5Bm25Data object */
   575    578       nPhrase = pApi->xPhraseCount(pFts);
   576    579       nByte = sizeof(Fts5Bm25Data) + nPhrase*2*sizeof(double);
   577         -    p = (Fts5Bm25Data*)sqlite3_malloc(nByte);
          580  +    p = (Fts5Bm25Data*)sqlite3_malloc64(nByte);
   578    581       if( p==0 ){
   579    582         rc = SQLITE_NOMEM;
   580    583       }else{
   581    584         memset(p, 0, nByte);
   582    585         p->nPhrase = nPhrase;
   583    586         p->aIDF = (double*)&p[1];
   584    587         p->aFreq = &p->aIDF[nPhrase];
   585    588       }
   586    589   
   587    590       /* Calculate the average document length for this FTS5 table */
   588    591       if( rc==SQLITE_OK ) rc = pApi->xRowCount(pFts, &nRow);
          592  +    assert( rc!=SQLITE_OK || nRow>0 );
   589    593       if( rc==SQLITE_OK ) rc = pApi->xColumnTotalSize(pFts, -1, &nToken);
   590    594       if( rc==SQLITE_OK ) p->avgdl = (double)nToken  / (double)nRow;
   591    595   
   592    596       /* Calculate an IDF for each phrase in the query */
   593    597       for(i=0; rc==SQLITE_OK && i<nPhrase; i++){
   594    598         sqlite3_int64 nHit = 0;
   595    599         rc = pApi->xQueryPhrase(pFts, i, (void*)&nHit, fts5CountCb);
................................................................................
   706    710           aBuiltin[i].xFunc,
   707    711           aBuiltin[i].xDestroy
   708    712       );
   709    713     }
   710    714   
   711    715     return rc;
   712    716   }
   713         -
   714         -

Changes to ext/fts5/fts5_buffer.c.

    13     13   
    14     14   
    15     15   
    16     16   #include "fts5Int.h"
    17     17   
    18     18   int sqlite3Fts5BufferSize(int *pRc, Fts5Buffer *pBuf, u32 nByte){
    19     19     if( (u32)pBuf->nSpace<nByte ){
    20         -    u32 nNew = pBuf->nSpace ? pBuf->nSpace : 64;
           20  +    u64 nNew = pBuf->nSpace ? pBuf->nSpace : 64;
    21     21       u8 *pNew;
    22     22       while( nNew<nByte ){
    23     23         nNew = nNew * 2;
    24     24       }
    25         -    pNew = sqlite3_realloc(pBuf->p, nNew);
           25  +    pNew = sqlite3_realloc64(pBuf->p, nNew);
    26     26       if( pNew==0 ){
    27     27         *pRc = SQLITE_NOMEM;
    28     28         return 1;
    29     29       }else{
    30     30         pBuf->nSpace = nNew;
    31     31         pBuf->p = pNew;
    32     32       }
................................................................................
    48     48     aBuf[0] = (iVal>>24) & 0x00FF;
    49     49     aBuf[1] = (iVal>>16) & 0x00FF;
    50     50     aBuf[2] = (iVal>> 8) & 0x00FF;
    51     51     aBuf[3] = (iVal>> 0) & 0x00FF;
    52     52   }
    53     53   
    54     54   int sqlite3Fts5Get32(const u8 *aBuf){
    55         -  return (aBuf[0] << 24) + (aBuf[1] << 16) + (aBuf[2] << 8) + aBuf[3];
           55  +  return (int)((((u32)aBuf[0])<<24) + (aBuf[1]<<16) + (aBuf[2]<<8) + aBuf[3]);
    56     56   }
    57     57   
    58     58   /*
    59     59   ** Append buffer nData/pData to buffer pBuf. If an OOM error occurs, set 
    60     60   ** the error code in p. If an error has already occurred when this function
    61     61   ** is called, it is a no-op.
    62     62   */
................................................................................
   179    179       int iVal;
   180    180       fts5FastGetVarint32(a, i, iVal);
   181    181       if( iVal==1 ){
   182    182         fts5FastGetVarint32(a, i, iVal);
   183    183         iOff = ((i64)iVal) << 32;
   184    184         fts5FastGetVarint32(a, i, iVal);
   185    185       }
   186         -    *piOff = iOff + (iVal-2);
          186  +    *piOff = iOff + ((iVal-2) & 0x7FFFFFFF);
   187    187       *pi = i;
   188    188       return 0;
   189    189     }
   190    190   }
   191    191   
   192    192   
   193    193   /*
................................................................................
   240    240   ){
   241    241     int rc = 0;   /* Initialized only to suppress erroneous warning from Clang */
   242    242     if( fts5BufferGrow(&rc, pBuf, 5+5+5) ) return rc;
   243    243     sqlite3Fts5PoslistSafeAppend(pBuf, &pWriter->iPrev, iPos);
   244    244     return SQLITE_OK;
   245    245   }
   246    246   
   247         -void *sqlite3Fts5MallocZero(int *pRc, int nByte){
          247  +void *sqlite3Fts5MallocZero(int *pRc, sqlite3_int64 nByte){
   248    248     void *pRet = 0;
   249    249     if( *pRc==SQLITE_OK ){
   250         -    pRet = sqlite3_malloc(nByte);
          250  +    pRet = sqlite3_malloc64(nByte);
   251    251       if( pRet==0 ){
   252    252         if( nByte>0 ) *pRc = SQLITE_NOMEM;
   253    253       }else{
   254    254         memset(pRet, 0, nByte);
   255    255       }
   256    256     }
   257    257     return pRet;

Changes to ext/fts5/fts5_config.c.

   291    291       }
   292    292       assert( pConfig->nPrefix<=FTS5_MAX_PREFIX_INDEXES );
   293    293       return rc;
   294    294     }
   295    295   
   296    296     if( sqlite3_strnicmp("tokenize", zCmd, nCmd)==0 ){
   297    297       const char *p = (const char*)zArg;
   298         -    int nArg = (int)strlen(zArg) + 1;
          298  +    sqlite3_int64 nArg = strlen(zArg) + 1;
   299    299       char **azArg = sqlite3Fts5MallocZero(&rc, sizeof(char*) * nArg);
   300    300       char *pDel = sqlite3Fts5MallocZero(&rc, nArg * 2);
   301    301       char *pSpace = pDel;
   302    302   
   303    303       if( azArg && pSpace ){
   304    304         if( pConfig->pTok ){
   305    305           *pzErr = sqlite3_mprintf("multiple tokenize=... directives");
................................................................................
   421    421     int *pRc,                       /* IN/OUT: Error code */
   422    422     const char *zIn,                /* Buffer to gobble string/bareword from */
   423    423     char **pzOut,                   /* OUT: malloc'd buffer containing str/bw */
   424    424     int *pbQuoted                   /* OUT: Set to true if dequoting required */
   425    425   ){
   426    426     const char *zRet = 0;
   427    427   
   428         -  int nIn = (int)strlen(zIn);
   429         -  char *zOut = sqlite3_malloc(nIn+1);
          428  +  sqlite3_int64 nIn = strlen(zIn);
          429  +  char *zOut = sqlite3_malloc64(nIn+1);
   430    430   
   431    431     assert( *pRc==SQLITE_OK );
   432    432     *pbQuoted = 0;
   433    433     *pzOut = 0;
   434    434   
   435    435     if( zOut==0 ){
   436    436       *pRc = SQLITE_NOMEM;
................................................................................
   525    525     const char **azArg,             /* Array of nArg CREATE VIRTUAL TABLE args */
   526    526     Fts5Config **ppOut,             /* OUT: Results of parse */
   527    527     char **pzErr                    /* OUT: Error message */
   528    528   ){
   529    529     int rc = SQLITE_OK;             /* Return code */
   530    530     Fts5Config *pRet;               /* New object to return */
   531    531     int i;
   532         -  int nByte;
          532  +  sqlite3_int64 nByte;
   533    533   
   534    534     *ppOut = pRet = (Fts5Config*)sqlite3_malloc(sizeof(Fts5Config));
   535    535     if( pRet==0 ) return SQLITE_NOMEM;
   536    536     memset(pRet, 0, sizeof(Fts5Config));
   537    537     pRet->db = db;
   538    538     pRet->iCookie = -1;
   539    539   

Changes to ext/fts5/fts5_expr.c.

   207    207       }
   208    208     }
   209    209   
   210    210     *pz = &pToken->p[pToken->n];
   211    211     return tok;
   212    212   }
   213    213   
   214         -static void *fts5ParseAlloc(u64 t){ return sqlite3_malloc((int)t); }
          214  +static void *fts5ParseAlloc(u64 t){ return sqlite3_malloc64((sqlite3_int64)t);}
   215    215   static void fts5ParseFree(void *p){ sqlite3_free(p); }
   216    216   
   217    217   int sqlite3Fts5ExprNew(
   218    218     Fts5Config *pConfig,            /* FTS5 Configuration */
   219    219     int iCol,
   220    220     const char *zExpr,              /* Expression text */
   221    221     Fts5Expr **ppNew, 
................................................................................
   352    352   
   353    353     assert( pTerm->pSynonym );
   354    354     for(p=pTerm; p; p=p->pSynonym){
   355    355       Fts5IndexIter *pIter = p->pIter;
   356    356       if( sqlite3Fts5IterEof(pIter)==0 && pIter->iRowid==iRowid ){
   357    357         if( pIter->nData==0 ) continue;
   358    358         if( nIter==nAlloc ){
   359         -        int nByte = sizeof(Fts5PoslistReader) * nAlloc * 2;
   360         -        Fts5PoslistReader *aNew = (Fts5PoslistReader*)sqlite3_malloc(nByte);
          359  +        sqlite3_int64 nByte = sizeof(Fts5PoslistReader) * nAlloc * 2;
          360  +        Fts5PoslistReader *aNew = (Fts5PoslistReader*)sqlite3_malloc64(nByte);
   361    361           if( aNew==0 ){
   362    362             rc = SQLITE_NOMEM;
   363    363             goto synonym_poslist_out;
   364    364           }
   365    365           memcpy(aNew, aIter, sizeof(Fts5PoslistReader) * nIter);
   366    366           nAlloc = nAlloc*2;
   367    367           if( aIter!=aStatic ) sqlite3_free(aIter);
................................................................................
   433    433     int bFirst = pPhrase->aTerm[0].bFirst;
   434    434     
   435    435     fts5BufferZero(&pPhrase->poslist);
   436    436   
   437    437     /* If the aStatic[] array is not large enough, allocate a large array
   438    438     ** using sqlite3_malloc(). This approach could be improved upon. */
   439    439     if( pPhrase->nTerm>ArraySize(aStatic) ){
   440         -    int nByte = sizeof(Fts5PoslistReader) * pPhrase->nTerm;
   441         -    aIter = (Fts5PoslistReader*)sqlite3_malloc(nByte);
          440  +    sqlite3_int64 nByte = sizeof(Fts5PoslistReader) * pPhrase->nTerm;
          441  +    aIter = (Fts5PoslistReader*)sqlite3_malloc64(nByte);
   442    442       if( !aIter ) return SQLITE_NOMEM;
   443    443     }
   444    444     memset(aIter, 0, sizeof(Fts5PoslistReader) * pPhrase->nTerm);
   445    445   
   446    446     /* Initialize a term iterator for each term in the phrase */
   447    447     for(i=0; i<pPhrase->nTerm; i++){
   448    448       Fts5ExprTerm *pTerm = &pPhrase->aTerm[i];
................................................................................
   568    568     int bMatch;
   569    569   
   570    570     assert( pNear->nPhrase>1 );
   571    571   
   572    572     /* If the aStatic[] array is not large enough, allocate a large array
   573    573     ** using sqlite3_malloc(). This approach could be improved upon. */
   574    574     if( pNear->nPhrase>ArraySize(aStatic) ){
   575         -    int nByte = sizeof(Fts5NearTrimmer) * pNear->nPhrase;
          575  +    sqlite3_int64 nByte = sizeof(Fts5NearTrimmer) * pNear->nPhrase;
   576    576       a = (Fts5NearTrimmer*)sqlite3Fts5MallocZero(&rc, nByte);
   577    577     }else{
   578    578       memset(aStatic, 0, sizeof(aStatic));
   579    579     }
   580    580     if( rc!=SQLITE_OK ){
   581    581       *pRc = rc;
   582    582       return 0;
................................................................................
  1477   1477     Fts5ExprNearset *pRet = 0;
  1478   1478   
  1479   1479     if( pParse->rc==SQLITE_OK ){
  1480   1480       if( pPhrase==0 ){
  1481   1481         return pNear;
  1482   1482       }
  1483   1483       if( pNear==0 ){
  1484         -      int nByte = sizeof(Fts5ExprNearset) + SZALLOC * sizeof(Fts5ExprPhrase*);
  1485         -      pRet = sqlite3_malloc(nByte);
         1484  +      sqlite3_int64 nByte;
         1485  +      nByte = sizeof(Fts5ExprNearset) + SZALLOC * sizeof(Fts5ExprPhrase*);
         1486  +      pRet = sqlite3_malloc64(nByte);
  1486   1487         if( pRet==0 ){
  1487   1488           pParse->rc = SQLITE_NOMEM;
  1488   1489         }else{
  1489   1490           memset(pRet, 0, nByte);
  1490   1491         }
  1491   1492       }else if( (pNear->nPhrase % SZALLOC)==0 ){
  1492   1493         int nNew = pNear->nPhrase + SZALLOC;
  1493         -      int nByte = sizeof(Fts5ExprNearset) + nNew * sizeof(Fts5ExprPhrase*);
         1494  +      sqlite3_int64 nByte;
  1494   1495   
  1495         -      pRet = (Fts5ExprNearset*)sqlite3_realloc(pNear, nByte);
         1496  +      nByte = sizeof(Fts5ExprNearset) + nNew * sizeof(Fts5ExprPhrase*);
         1497  +      pRet = (Fts5ExprNearset*)sqlite3_realloc64(pNear, nByte);
  1496   1498         if( pRet==0 ){
  1497   1499           pParse->rc = SQLITE_NOMEM;
  1498   1500         }
  1499   1501       }else{
  1500   1502         pRet = pNear;
  1501   1503       }
  1502   1504     }
................................................................................
  1552   1554   
  1553   1555     /* If an error has already occurred, this is a no-op */
  1554   1556     if( pCtx->rc!=SQLITE_OK ) return pCtx->rc;
  1555   1557     if( nToken>FTS5_MAX_TOKEN_SIZE ) nToken = FTS5_MAX_TOKEN_SIZE;
  1556   1558   
  1557   1559     if( pPhrase && pPhrase->nTerm>0 && (tflags & FTS5_TOKEN_COLOCATED) ){
  1558   1560       Fts5ExprTerm *pSyn;
  1559         -    int nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1;
  1560         -    pSyn = (Fts5ExprTerm*)sqlite3_malloc(nByte);
         1561  +    sqlite3_int64 nByte = sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer) + nToken+1;
         1562  +    pSyn = (Fts5ExprTerm*)sqlite3_malloc64(nByte);
  1561   1563       if( pSyn==0 ){
  1562   1564         rc = SQLITE_NOMEM;
  1563   1565       }else{
  1564   1566         memset(pSyn, 0, nByte);
  1565   1567         pSyn->zTerm = ((char*)pSyn) + sizeof(Fts5ExprTerm) + sizeof(Fts5Buffer);
  1566   1568         memcpy(pSyn->zTerm, pToken, nToken);
  1567   1569         pSyn->pSynonym = pPhrase->aTerm[pPhrase->nTerm-1].pSynonym;
................................................................................
  1569   1571       }
  1570   1572     }else{
  1571   1573       Fts5ExprTerm *pTerm;
  1572   1574       if( pPhrase==0 || (pPhrase->nTerm % SZALLOC)==0 ){
  1573   1575         Fts5ExprPhrase *pNew;
  1574   1576         int nNew = SZALLOC + (pPhrase ? pPhrase->nTerm : 0);
  1575   1577   
  1576         -      pNew = (Fts5ExprPhrase*)sqlite3_realloc(pPhrase, 
         1578  +      pNew = (Fts5ExprPhrase*)sqlite3_realloc64(pPhrase, 
  1577   1579             sizeof(Fts5ExprPhrase) + sizeof(Fts5ExprTerm) * nNew
  1578   1580         );
  1579   1581         if( pNew==0 ){
  1580   1582           rc = SQLITE_NOMEM;
  1581   1583         }else{
  1582   1584           if( pPhrase==0 ) memset(pNew, 0, sizeof(Fts5ExprPhrase));
  1583   1585           pCtx->pPhrase = pPhrase = pNew;
................................................................................
  1655   1657       pParse->rc = rc;
  1656   1658       fts5ExprPhraseFree(sCtx.pPhrase);
  1657   1659       sCtx.pPhrase = 0;
  1658   1660     }else{
  1659   1661   
  1660   1662       if( pAppend==0 ){
  1661   1663         if( (pParse->nPhrase % 8)==0 ){
  1662         -        int nByte = sizeof(Fts5ExprPhrase*) * (pParse->nPhrase + 8);
         1664  +        sqlite3_int64 nByte = sizeof(Fts5ExprPhrase*) * (pParse->nPhrase + 8);
  1663   1665           Fts5ExprPhrase **apNew;
  1664         -        apNew = (Fts5ExprPhrase**)sqlite3_realloc(pParse->apPhrase, nByte);
         1666  +        apNew = (Fts5ExprPhrase**)sqlite3_realloc64(pParse->apPhrase, nByte);
  1665   1667           if( apNew==0 ){
  1666   1668             pParse->rc = SQLITE_NOMEM;
  1667   1669             fts5ExprPhraseFree(sCtx.pPhrase);
  1668   1670             return 0;
  1669   1671           }
  1670   1672           pParse->apPhrase = apNew;
  1671   1673         }
................................................................................
  1712   1714     if( rc==SQLITE_OK ){
  1713   1715       pNew->pRoot->pNear = (Fts5ExprNearset*)sqlite3Fts5MallocZero(&rc, 
  1714   1716           sizeof(Fts5ExprNearset) + sizeof(Fts5ExprPhrase*));
  1715   1717     }
  1716   1718     if( rc==SQLITE_OK ){
  1717   1719       Fts5Colset *pColsetOrig = pOrig->pNode->pNear->pColset;
  1718   1720       if( pColsetOrig ){
  1719         -      int nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
  1720         -      Fts5Colset *pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
         1721  +      sqlite3_int64 nByte;
         1722  +      Fts5Colset *pColset;
         1723  +      nByte = sizeof(Fts5Colset) + (pColsetOrig->nCol-1) * sizeof(int);
         1724  +      pColset = (Fts5Colset*)sqlite3Fts5MallocZero(&rc, nByte);
  1721   1725         if( pColset ){ 
  1722   1726           memcpy(pColset, pColsetOrig, nByte);
  1723   1727         }
  1724   1728         pNew->pRoot->pNear->pColset = pColset;
  1725   1729       }
  1726   1730     }
  1727   1731   
................................................................................
  1833   1837   ){
  1834   1838     int nCol = p ? p->nCol : 0;     /* Num. columns already in colset object */
  1835   1839     Fts5Colset *pNew;               /* New colset object to return */
  1836   1840   
  1837   1841     assert( pParse->rc==SQLITE_OK );
  1838   1842     assert( iCol>=0 && iCol<pParse->pConfig->nCol );
  1839   1843   
  1840         -  pNew = sqlite3_realloc(p, sizeof(Fts5Colset) + sizeof(int)*nCol);
         1844  +  pNew = sqlite3_realloc64(p, sizeof(Fts5Colset) + sizeof(int)*nCol);
  1841   1845     if( pNew==0 ){
  1842   1846       pParse->rc = SQLITE_NOMEM;
  1843   1847     }else{
  1844   1848       int *aiCol = pNew->aiCol;
  1845   1849       int i, j;
  1846   1850       for(i=0; i<nCol; i++){
  1847   1851         if( aiCol[i]==iCol ) return pNew;
................................................................................
  1929   1933   ** Otherwise, a copy of (*pOrig) is made into memory obtained from
  1930   1934   ** sqlite3Fts5MallocZero() and a pointer to it returned. If the allocation
  1931   1935   ** fails, (*pRc) is set to SQLITE_NOMEM and NULL is returned.
  1932   1936   */
  1933   1937   static Fts5Colset *fts5CloneColset(int *pRc, Fts5Colset *pOrig){
  1934   1938     Fts5Colset *pRet;
  1935   1939     if( pOrig ){
  1936         -    int nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
         1940  +    sqlite3_int64 nByte = sizeof(Fts5Colset) + (pOrig->nCol-1) * sizeof(int);
  1937   1941       pRet = (Fts5Colset*)sqlite3Fts5MallocZero(pRc, nByte);
  1938   1942       if( pRet ){ 
  1939   1943         memcpy(pRet, pOrig, nByte);
  1940   1944       }
  1941   1945     }else{
  1942   1946       pRet = 0;
  1943   1947     }
................................................................................
  2083   2087     Fts5ExprNode *pRight,           /* Right hand child expression */
  2084   2088     Fts5ExprNearset *pNear          /* For STRING expressions, the near cluster */
  2085   2089   ){
  2086   2090     Fts5ExprNode *pRet = 0;
  2087   2091   
  2088   2092     if( pParse->rc==SQLITE_OK ){
  2089   2093       int nChild = 0;               /* Number of children of returned node */
  2090         -    int nByte;                    /* Bytes of space to allocate for this node */
         2094  +    sqlite3_int64 nByte;          /* Bytes of space to allocate for this node */
  2091   2095    
  2092   2096       assert( (eType!=FTS5_STRING && !pNear)
  2093   2097            || (eType==FTS5_STRING && !pLeft && !pRight)
  2094   2098       );
  2095   2099       if( eType==FTS5_STRING && pNear==0 ) return 0;
  2096   2100       if( eType!=FTS5_STRING && pLeft==0 ) return pRight;
  2097   2101       if( eType!=FTS5_STRING && pRight==0 ) return pLeft;
................................................................................
  2215   2219       }
  2216   2220     }
  2217   2221   
  2218   2222     return pRet;
  2219   2223   }
  2220   2224   
  2221   2225   static char *fts5ExprTermPrint(Fts5ExprTerm *pTerm){
  2222         -  int nByte = 0;
         2226  +  sqlite3_int64 nByte = 0;
  2223   2227     Fts5ExprTerm *p;
  2224   2228     char *zQuoted;
  2225   2229   
  2226   2230     /* Determine the maximum amount of space required. */
  2227   2231     for(p=pTerm; p; p=p->pSynonym){
  2228   2232       nByte += (int)strlen(pTerm->zTerm) * 2 + 3 + 2;
  2229   2233     }
  2230         -  zQuoted = sqlite3_malloc(nByte);
         2234  +  zQuoted = sqlite3_malloc64(nByte);
  2231   2235   
  2232   2236     if( zQuoted ){
  2233   2237       int i = 0;
  2234   2238       for(p=pTerm; p; p=p->pSynonym){
  2235   2239         char *zIn = p->zTerm;
  2236   2240         zQuoted[i++] = '"';
  2237   2241         while( *zIn ){
................................................................................
  2463   2467   
  2464   2468     if( bTcl && nArg>1 ){
  2465   2469       zNearsetCmd = (const char*)sqlite3_value_text(apVal[1]);
  2466   2470       iArg = 2;
  2467   2471     }
  2468   2472   
  2469   2473     nConfig = 3 + (nArg-iArg);
  2470         -  azConfig = (const char**)sqlite3_malloc(sizeof(char*) * nConfig);
         2474  +  azConfig = (const char**)sqlite3_malloc64(sizeof(char*) * nConfig);
  2471   2475     if( azConfig==0 ){
  2472   2476       sqlite3_result_error_nomem(pCtx);
  2473   2477       return;
  2474   2478     }
  2475   2479     azConfig[0] = 0;
  2476   2480     azConfig[1] = "main";
  2477   2481     azConfig[2] = "tbl";
................................................................................
  2549   2553       return;
  2550   2554     }
  2551   2555     memset(aArr, 0, sizeof(aArr));
  2552   2556     sqlite3Fts5UnicodeCatParse("L*", aArr);
  2553   2557     sqlite3Fts5UnicodeCatParse("N*", aArr);
  2554   2558     sqlite3Fts5UnicodeCatParse("Co", aArr);
  2555   2559     iCode = sqlite3_value_int(apVal[0]);
  2556         -  sqlite3_result_int(pCtx, aArr[sqlite3Fts5UnicodeCategory(iCode)]);
         2560  +  sqlite3_result_int(pCtx, aArr[sqlite3Fts5UnicodeCategory((u32)iCode)]);
  2557   2561   }
  2558   2562   
  2559   2563   static void fts5ExprFold(
  2560   2564     sqlite3_context *pCtx,          /* Function call context */
  2561   2565     int nArg,                       /* Number of args */
  2562   2566     sqlite3_value **apVal           /* Function arguments */
  2563   2567   ){
................................................................................
  2644   2648     Fts5PoslistWriter writer;
  2645   2649     int bOk;                        /* True if ok to populate */
  2646   2650     int bMiss;
  2647   2651   };
  2648   2652   
  2649   2653   Fts5PoslistPopulator *sqlite3Fts5ExprClearPoslists(Fts5Expr *pExpr, int bLive){
  2650   2654     Fts5PoslistPopulator *pRet;
  2651         -  pRet = sqlite3_malloc(sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
         2655  +  pRet = sqlite3_malloc64(sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
  2652   2656     if( pRet ){
  2653   2657       int i;
  2654   2658       memset(pRet, 0, sizeof(Fts5PoslistPopulator)*pExpr->nPhrase);
  2655   2659       for(i=0; i<pExpr->nPhrase; i++){
  2656   2660         Fts5Buffer *pBuf = &pExpr->apExprPhrase[i]->poslist;
  2657   2661         Fts5ExprNode *pNode = pExpr->apExprPhrase[i]->pNode;
  2658   2662         assert( pExpr->apExprPhrase[i]->nTerm==1 );
................................................................................
  2843   2847     }else{
  2844   2848       *ppCollist = 0;
  2845   2849       *pnCollist = 0;
  2846   2850     }
  2847   2851   
  2848   2852     return rc;
  2849   2853   }
  2850         -

Changes to ext/fts5/fts5_hash.c.

    86     86     int rc = SQLITE_OK;
    87     87     Fts5Hash *pNew;
    88     88   
    89     89     *ppNew = pNew = (Fts5Hash*)sqlite3_malloc(sizeof(Fts5Hash));
    90     90     if( pNew==0 ){
    91     91       rc = SQLITE_NOMEM;
    92     92     }else{
    93         -    int nByte;
           93  +    sqlite3_int64 nByte;
    94     94       memset(pNew, 0, sizeof(Fts5Hash));
    95     95       pNew->pnByte = pnByte;
    96     96       pNew->eDetail = pConfig->eDetail;
    97     97   
    98     98       pNew->nSlot = 1024;
    99     99       nByte = sizeof(Fts5HashEntry*) * pNew->nSlot;
   100         -    pNew->aSlot = (Fts5HashEntry**)sqlite3_malloc(nByte);
          100  +    pNew->aSlot = (Fts5HashEntry**)sqlite3_malloc64(nByte);
   101    101       if( pNew->aSlot==0 ){
   102    102         sqlite3_free(pNew);
   103    103         *ppNew = 0;
   104    104         rc = SQLITE_NOMEM;
   105    105       }else{
   106    106         memset(pNew->aSlot, 0, nByte);
   107    107       }
................................................................................
   161    161   */
   162    162   static int fts5HashResize(Fts5Hash *pHash){
   163    163     int nNew = pHash->nSlot*2;
   164    164     int i;
   165    165     Fts5HashEntry **apNew;
   166    166     Fts5HashEntry **apOld = pHash->aSlot;
   167    167   
   168         -  apNew = (Fts5HashEntry**)sqlite3_malloc(nNew*sizeof(Fts5HashEntry*));
          168  +  apNew = (Fts5HashEntry**)sqlite3_malloc64(nNew*sizeof(Fts5HashEntry*));
   169    169     if( !apNew ) return SQLITE_NOMEM;
   170    170     memset(apNew, 0, nNew*sizeof(Fts5HashEntry*));
   171    171   
   172    172     for(i=0; i<pHash->nSlot; i++){
   173    173       while( apOld[i] ){
   174    174         unsigned int iHash;
   175    175         Fts5HashEntry *p = apOld[i];
................................................................................
   255    255       }
   256    256     }
   257    257   
   258    258     /* If an existing hash entry cannot be found, create a new one. */
   259    259     if( p==0 ){
   260    260       /* Figure out how much space to allocate */
   261    261       char *zKey;
   262         -    int nByte = sizeof(Fts5HashEntry) + (nToken+1) + 1 + 64;
          262  +    sqlite3_int64 nByte = sizeof(Fts5HashEntry) + (nToken+1) + 1 + 64;
   263    263       if( nByte<128 ) nByte = 128;
   264    264   
   265    265       /* Grow the Fts5Hash.aSlot[] array if necessary. */
   266    266       if( (pHash->nEntry*2)>=pHash->nSlot ){
   267    267         int rc = fts5HashResize(pHash);
   268    268         if( rc!=SQLITE_OK ) return rc;
   269    269         iHash = fts5HashKey2(pHash->nSlot, (u8)bByte, (const u8*)pToken, nToken);
   270    270       }
   271    271   
   272    272       /* Allocate new Fts5HashEntry and add it to the hash table. */
   273         -    p = (Fts5HashEntry*)sqlite3_malloc(nByte);
          273  +    p = (Fts5HashEntry*)sqlite3_malloc64(nByte);
   274    274       if( !p ) return SQLITE_NOMEM;
   275    275       memset(p, 0, sizeof(Fts5HashEntry));
   276    276       p->nAlloc = nByte;
   277    277       zKey = fts5EntryKey(p);
   278    278       zKey[0] = bByte;
   279    279       memcpy(&zKey[1], pToken, nToken);
   280    280       assert( iHash==fts5HashKey(pHash->nSlot, (u8*)zKey, nToken+1) );
................................................................................
   305    305       **     + 9 bytes for a new rowid,
   306    306       **     + 4 byte reserved for the "poslist size" varint.
   307    307       **     + 1 byte for a "new column" byte,
   308    308       **     + 3 bytes for a new column number (16-bit max) as a varint,
   309    309       **     + 5 bytes for the new position offset (32-bit max).
   310    310       */
   311    311       if( (p->nAlloc - p->nData) < (9 + 4 + 1 + 3 + 5) ){
   312         -      int nNew = p->nAlloc * 2;
          312  +      sqlite3_int64 nNew = p->nAlloc * 2;
   313    313         Fts5HashEntry *pNew;
   314    314         Fts5HashEntry **pp;
   315         -      pNew = (Fts5HashEntry*)sqlite3_realloc(p, nNew);
          315  +      pNew = (Fts5HashEntry*)sqlite3_realloc64(p, nNew);
   316    316         if( pNew==0 ) return SQLITE_NOMEM;
   317         -      pNew->nAlloc = nNew;
          317  +      pNew->nAlloc = (int)nNew;
   318    318         for(pp=&pHash->aSlot[iHash]; *pp!=p; pp=&(*pp)->pHashNext);
   319    319         *pp = pNew;
   320    320         p = pNew;
   321    321       }
   322    322       nIncr -= p->nData;
   323    323     }
   324    324     assert( (p->nAlloc - p->nData) >= (9 + 4 + 1 + 3 + 5) );
................................................................................
   434    434     const int nMergeSlot = 32;
   435    435     Fts5HashEntry **ap;
   436    436     Fts5HashEntry *pList;
   437    437     int iSlot;
   438    438     int i;
   439    439   
   440    440     *ppSorted = 0;
   441         -  ap = sqlite3_malloc(sizeof(Fts5HashEntry*) * nMergeSlot);
          441  +  ap = sqlite3_malloc64(sizeof(Fts5HashEntry*) * nMergeSlot);
   442    442     if( !ap ) return SQLITE_NOMEM;
   443    443     memset(ap, 0, sizeof(Fts5HashEntry*) * nMergeSlot);
   444    444   
   445    445     for(iSlot=0; iSlot<pHash->nSlot; iSlot++){
   446    446       Fts5HashEntry *pIter;
   447    447       for(pIter=pHash->aSlot[iSlot]; pIter; pIter=pIter->pHashNext){
   448    448         if( pTerm==0 || 0==memcmp(fts5EntryKey(pIter), pTerm, nTerm) ){
................................................................................
   479    479   ){
   480    480     unsigned int iHash = fts5HashKey(pHash->nSlot, (const u8*)pTerm, nTerm);
   481    481     char *zKey = 0;
   482    482     Fts5HashEntry *p;
   483    483   
   484    484     for(p=pHash->aSlot[iHash]; p; p=p->pHashNext){
   485    485       zKey = fts5EntryKey(p);
   486         -    if( memcmp(zKey, pTerm, nTerm)==0 && zKey[nTerm]==0 ) break;
          486  +    assert( p->nKey+1==(int)strlen(zKey) );
          487  +    if( nTerm==p->nKey+1 && memcmp(zKey, pTerm, nTerm)==0 ) break;
   487    488     }
   488    489   
   489    490     if( p ){
   490    491       fts5HashAddPoslistSize(pHash, p);
   491    492       *ppDoclist = (const u8*)&zKey[nTerm+1];
   492    493       *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
   493    494     }else{
................................................................................
   530    531       *pnDoclist = p->nData - (sizeof(Fts5HashEntry) + nTerm + 1);
   531    532     }else{
   532    533       *pzTerm = 0;
   533    534       *ppDoclist = 0;
   534    535       *pnDoclist = 0;
   535    536     }
   536    537   }
   537         -

Changes to ext/fts5/fts5_index.c.

   508    508   **   Used by sqlite3Fts5IterPoslist() when the poslist needs to be buffered.
   509    509   **   There is no way to tell if this is populated or not.
   510    510   */
   511    511   struct Fts5Iter {
   512    512     Fts5IndexIter base;             /* Base class containing output vars */
   513    513   
   514    514     Fts5Index *pIndex;              /* Index that owns this iterator */
   515         -  Fts5Structure *pStruct;         /* Database structure for this iterator */
   516    515     Fts5Buffer poslist;             /* Buffer containing current poslist */
   517    516     Fts5Colset *pColset;            /* Restrict matches to these columns */
   518    517   
   519    518     /* Invoked to set output variables. */
   520    519     void (*xSetOutputs)(Fts5Iter*, Fts5SegIter*);
   521    520   
   522    521     int nSeg;                       /* Size of aSeg[] array */
................................................................................
   569    568   
   570    569   /*
   571    570   ** Allocate and return a buffer at least nByte bytes in size.
   572    571   **
   573    572   ** If an OOM error is encountered, return NULL and set the error code in
   574    573   ** the Fts5Index handle passed as the first argument.
   575    574   */
   576         -static void *fts5IdxMalloc(Fts5Index *p, int nByte){
          575  +static void *fts5IdxMalloc(Fts5Index *p, sqlite3_int64 nByte){
   577    576     return sqlite3Fts5MallocZero(&p->rc, nByte);
   578    577   }
   579    578   
   580    579   /*
   581    580   ** Compare the contents of the pLeft buffer with the pRight/nRight blob.
   582    581   **
   583    582   ** Return -ve if pLeft is smaller than pRight, 0 if they are equal or
................................................................................
   603    602   ** Return -ve if pLeft is smaller than pRight, 0 if they are equal or
   604    603   ** +ve if pRight is smaller than pLeft. In other words:
   605    604   **
   606    605   **     res = *pLeft - *pRight
   607    606   */
   608    607   static int fts5BufferCompare(Fts5Buffer *pLeft, Fts5Buffer *pRight){
   609    608     int nCmp = MIN(pLeft->n, pRight->n);
   610         -  int res = memcmp(pLeft->p, pRight->p, nCmp);
          609  +  int res = fts5Memcmp(pLeft->p, pRight->p, nCmp);
   611    610     return (res==0 ? (pLeft->n - pRight->n) : res);
   612    611   }
   613    612   
   614    613   static int fts5LeafFirstTermOff(Fts5Data *pLeaf){
   615    614     int ret;
   616    615     fts5GetVarint32(&pLeaf->p[pLeaf->szLeaf], ret);
   617    616     return ret;
................................................................................
   669    668       ** table, missing row, non-blob/text in block column - indicate 
   670    669       ** backing store corruption.  */
   671    670       if( rc==SQLITE_ERROR ) rc = FTS5_CORRUPT;
   672    671   
   673    672       if( rc==SQLITE_OK ){
   674    673         u8 *aOut = 0;               /* Read blob data into this buffer */
   675    674         int nByte = sqlite3_blob_bytes(p->pReader);
   676         -      int nAlloc = sizeof(Fts5Data) + nByte + FTS5_DATA_PADDING;
   677         -      pRet = (Fts5Data*)sqlite3_malloc(nAlloc);
          675  +      sqlite3_int64 nAlloc = sizeof(Fts5Data) + nByte + FTS5_DATA_PADDING;
          676  +      pRet = (Fts5Data*)sqlite3_malloc64(nAlloc);
   678    677         if( pRet ){
   679    678           pRet->nn = nByte;
   680    679           aOut = pRet->p = (u8*)&pRet[1];
   681    680         }else{
   682    681           rc = SQLITE_NOMEM;
   683    682         }
   684    683   
................................................................................
   686    685           rc = sqlite3_blob_read(p->pReader, aOut, nByte, 0);
   687    686         }
   688    687         if( rc!=SQLITE_OK ){
   689    688           sqlite3_free(pRet);
   690    689           pRet = 0;
   691    690         }else{
   692    691           /* TODO1: Fix this */
          692  +        pRet->p[nByte] = 0x00;
   693    693           pRet->szLeaf = fts5GetU16(&pRet->p[2]);
   694    694         }
   695    695       }
   696    696       p->rc = rc;
   697    697       p->nRead++;
   698    698     }
   699    699   
................................................................................
   725    725     Fts5Index *p,
   726    726     sqlite3_stmt **ppStmt,
   727    727     char *zSql
   728    728   ){
   729    729     if( p->rc==SQLITE_OK ){
   730    730       if( zSql ){
   731    731         p->rc = sqlite3_prepare_v3(p->pConfig->db, zSql, -1,
   732         -                                 SQLITE_PREPARE_PERSISTENT, ppStmt, 0);
          732  +          SQLITE_PREPARE_PERSISTENT|SQLITE_PREPARE_NO_VTAB,
          733  +          ppStmt, 0);
   733    734       }else{
   734    735         p->rc = SQLITE_NOMEM;
   735    736       }
   736    737     }
   737    738     sqlite3_free(zSql);
   738    739     return p->rc;
   739    740   }
................................................................................
   766    767   **
   767    768   **     DELETE FROM %_data WHERE id BETWEEN $iFirst AND $iLast
   768    769   */
   769    770   static void fts5DataDelete(Fts5Index *p, i64 iFirst, i64 iLast){
   770    771     if( p->rc!=SQLITE_OK ) return;
   771    772   
   772    773     if( p->pDeleter==0 ){
   773         -    int rc;
   774    774       Fts5Config *pConfig = p->pConfig;
   775    775       char *zSql = sqlite3_mprintf(
   776    776           "DELETE FROM '%q'.'%q_data' WHERE id>=? AND id<=?", 
   777    777             pConfig->zDb, pConfig->zName
   778    778       );
   779         -    if( zSql==0 ){
   780         -      rc = SQLITE_NOMEM;
   781         -    }else{
   782         -      rc = sqlite3_prepare_v3(pConfig->db, zSql, -1,
   783         -                              SQLITE_PREPARE_PERSISTENT, &p->pDeleter, 0);
   784         -      sqlite3_free(zSql);
   785         -    }
   786         -    if( rc!=SQLITE_OK ){
   787         -      p->rc = rc;
   788         -      return;
   789         -    }
          779  +    if( fts5IndexPrepareStmt(p, &p->pDeleter, zSql) ) return;
   790    780     }
   791    781   
   792    782     sqlite3_bind_int64(p->pDeleter, 1, iFirst);
   793    783     sqlite3_bind_int64(p->pDeleter, 2, iLast);
   794    784     sqlite3_step(p->pDeleter);
   795    785     p->rc = sqlite3_reset(p->pDeleter);
   796    786   }
................................................................................
   854    844     Fts5Structure **ppOut           /* OUT: Deserialized object */
   855    845   ){
   856    846     int rc = SQLITE_OK;
   857    847     int i = 0;
   858    848     int iLvl;
   859    849     int nLevel = 0;
   860    850     int nSegment = 0;
   861         -  int nByte;                      /* Bytes of space to allocate at pRet */
          851  +  sqlite3_int64 nByte;            /* Bytes of space to allocate at pRet */
   862    852     Fts5Structure *pRet = 0;        /* Structure object to return */
   863    853   
   864    854     /* Grab the cookie value */
   865    855     if( piCookie ) *piCookie = sqlite3Fts5Get32(pData);
   866    856     i = 4;
   867    857   
   868    858     /* Read the total number of levels and segments from the start of the
   869    859     ** structure record.  */
   870    860     i += fts5GetVarint32(&pData[i], nLevel);
   871    861     i += fts5GetVarint32(&pData[i], nSegment);
          862  +  if( nLevel>FTS5_MAX_SEGMENT   || nLevel<0
          863  +   || nSegment>FTS5_MAX_SEGMENT || nSegment<0
          864  +  ){
          865  +    return FTS5_CORRUPT;
          866  +  }
   872    867     nByte = (
   873    868         sizeof(Fts5Structure) +                    /* Main structure */
   874    869         sizeof(Fts5StructureLevel) * (nLevel-1)    /* aLevel[] array */
   875    870     );
   876    871     pRet = (Fts5Structure*)sqlite3Fts5MallocZero(&rc, nByte);
   877    872   
   878    873     if( pRet ){
................................................................................
   887    882         int iSeg;
   888    883   
   889    884         if( i>=nData ){
   890    885           rc = FTS5_CORRUPT;
   891    886         }else{
   892    887           i += fts5GetVarint32(&pData[i], pLvl->nMerge);
   893    888           i += fts5GetVarint32(&pData[i], nTotal);
   894         -        assert( nTotal>=pLvl->nMerge );
          889  +        if( nTotal<pLvl->nMerge ) rc = FTS5_CORRUPT;
   895    890           pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(&rc, 
   896    891               nTotal * sizeof(Fts5StructureSegment)
   897    892           );
          893  +        nSegment -= nTotal;
   898    894         }
   899    895   
   900    896         if( rc==SQLITE_OK ){
   901    897           pLvl->nSeg = nTotal;
   902    898           for(iSeg=0; iSeg<nTotal; iSeg++){
          899  +          Fts5StructureSegment *pSeg = &pLvl->aSeg[iSeg];
   903    900             if( i>=nData ){
   904    901               rc = FTS5_CORRUPT;
   905    902               break;
   906    903             }
   907         -          i += fts5GetVarint32(&pData[i], pLvl->aSeg[iSeg].iSegid);
   908         -          i += fts5GetVarint32(&pData[i], pLvl->aSeg[iSeg].pgnoFirst);
   909         -          i += fts5GetVarint32(&pData[i], pLvl->aSeg[iSeg].pgnoLast);
          904  +          i += fts5GetVarint32(&pData[i], pSeg->iSegid);
          905  +          i += fts5GetVarint32(&pData[i], pSeg->pgnoFirst);
          906  +          i += fts5GetVarint32(&pData[i], pSeg->pgnoLast);
          907  +          if( pSeg->pgnoLast<pSeg->pgnoFirst ){
          908  +            rc = FTS5_CORRUPT;
          909  +            break;
          910  +          }
   910    911           }
          912  +        if( iLvl>0 && pLvl[-1].nMerge && nTotal==0 ) rc = FTS5_CORRUPT;
          913  +        if( iLvl==nLevel-1 && pLvl->nMerge ) rc = FTS5_CORRUPT;
   911    914         }
   912    915       }
          916  +    if( nSegment!=0 && rc==SQLITE_OK ) rc = FTS5_CORRUPT;
          917  +
   913    918       if( rc!=SQLITE_OK ){
   914    919         fts5StructureRelease(pRet);
   915    920         pRet = 0;
   916    921       }
   917    922     }
   918    923   
   919    924     *ppOut = pRet;
................................................................................
   923    928   /*
   924    929   **
   925    930   */
   926    931   static void fts5StructureAddLevel(int *pRc, Fts5Structure **ppStruct){
   927    932     if( *pRc==SQLITE_OK ){
   928    933       Fts5Structure *pStruct = *ppStruct;
   929    934       int nLevel = pStruct->nLevel;
   930         -    int nByte = (
          935  +    sqlite3_int64 nByte = (
   931    936           sizeof(Fts5Structure) +                  /* Main structure */
   932    937           sizeof(Fts5StructureLevel) * (nLevel+1)  /* aLevel[] array */
   933    938       );
   934    939   
   935         -    pStruct = sqlite3_realloc(pStruct, nByte);
          940  +    pStruct = sqlite3_realloc64(pStruct, nByte);
   936    941       if( pStruct ){
   937    942         memset(&pStruct->aLevel[nLevel], 0, sizeof(Fts5StructureLevel));
   938    943         pStruct->nLevel++;
   939    944         *ppStruct = pStruct;
   940    945       }else{
   941    946         *pRc = SQLITE_NOMEM;
   942    947       }
................................................................................
   953    958     int iLvl, 
   954    959     int nExtra, 
   955    960     int bInsert
   956    961   ){
   957    962     if( *pRc==SQLITE_OK ){
   958    963       Fts5StructureLevel *pLvl = &pStruct->aLevel[iLvl];
   959    964       Fts5StructureSegment *aNew;
   960         -    int nByte;
          965  +    sqlite3_int64 nByte;
   961    966   
   962    967       nByte = (pLvl->nSeg + nExtra) * sizeof(Fts5StructureSegment);
   963         -    aNew = sqlite3_realloc(pLvl->aSeg, nByte);
          968  +    aNew = sqlite3_realloc64(pLvl->aSeg, nByte);
   964    969       if( aNew ){
   965    970         if( bInsert==0 ){
   966    971           memset(&aNew[pLvl->nSeg], 0, sizeof(Fts5StructureSegment) * nExtra);
   967    972         }else{
   968    973           int nMove = pLvl->nSeg * sizeof(Fts5StructureSegment);
   969    974           memmove(&aNew[nExtra], aNew, nMove);
   970    975           memset(aNew, 0, sizeof(Fts5StructureSegment) * nExtra);
................................................................................
  1470   1475     int iLeafPg                     /* Leaf page number to load dlidx for */
  1471   1476   ){
  1472   1477     Fts5DlidxIter *pIter = 0;
  1473   1478     int i;
  1474   1479     int bDone = 0;
  1475   1480   
  1476   1481     for(i=0; p->rc==SQLITE_OK && bDone==0; i++){
  1477         -    int nByte = sizeof(Fts5DlidxIter) + i * sizeof(Fts5DlidxLvl);
         1482  +    sqlite3_int64 nByte = sizeof(Fts5DlidxIter) + i * sizeof(Fts5DlidxLvl);
  1478   1483       Fts5DlidxIter *pNew;
  1479   1484   
  1480         -    pNew = (Fts5DlidxIter*)sqlite3_realloc(pIter, nByte);
         1485  +    pNew = (Fts5DlidxIter*)sqlite3_realloc64(pIter, nByte);
  1481   1486       if( pNew==0 ){
  1482   1487         p->rc = SQLITE_NOMEM;
  1483   1488       }else{
  1484   1489         i64 iRowid = FTS5_DLIDX_ROWID(iSegid, i, iLeafPg);
  1485   1490         Fts5DlidxLvl *pLvl = &pNew->aLvl[i];
  1486   1491         pIter = pNew;
  1487   1492         memset(pLvl, 0, sizeof(Fts5DlidxLvl));
................................................................................
  1643   1648   */
  1644   1649   static void fts5SegIterLoadTerm(Fts5Index *p, Fts5SegIter *pIter, int nKeep){
  1645   1650     u8 *a = pIter->pLeaf->p;        /* Buffer to read data from */
  1646   1651     int iOff = pIter->iLeafOffset;  /* Offset to read at */
  1647   1652     int nNew;                       /* Bytes of new data */
  1648   1653   
  1649   1654     iOff += fts5GetVarint32(&a[iOff], nNew);
  1650         -  if( iOff+nNew>pIter->pLeaf->nn ){
         1655  +  if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n || nNew==0 ){
  1651   1656       p->rc = FTS5_CORRUPT;
  1652   1657       return;
  1653   1658     }
  1654   1659     pIter->term.n = nKeep;
  1655   1660     fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
         1661  +  assert( pIter->term.n<=pIter->term.nSpace );
  1656   1662     iOff += nNew;
  1657   1663     pIter->iTermLeafOffset = iOff;
  1658   1664     pIter->iTermLeafPgno = pIter->iLeafPgno;
  1659   1665     pIter->iLeafOffset = iOff;
  1660   1666   
  1661   1667     if( pIter->iPgidxOff>=pIter->pLeaf->nn ){
  1662   1668       pIter->iEndofDoclist = pIter->pLeaf->nn+1;
................................................................................
  1713   1719       pIter->iLeafPgno = pSeg->pgnoFirst-1;
  1714   1720       fts5SegIterNextPage(p, pIter);
  1715   1721     }
  1716   1722   
  1717   1723     if( p->rc==SQLITE_OK ){
  1718   1724       pIter->iLeafOffset = 4;
  1719   1725       assert_nc( pIter->pLeaf->nn>4 );
  1720         -    assert( fts5LeafFirstTermOff(pIter->pLeaf)==4 );
         1726  +    assert_nc( fts5LeafFirstTermOff(pIter->pLeaf)==4 );
  1721   1727       pIter->iPgidxOff = pIter->pLeaf->szLeaf+1;
  1722   1728       fts5SegIterLoadTerm(p, pIter, 0);
  1723   1729       fts5SegIterLoadNPos(p, pIter);
  1724   1730     }
  1725   1731   }
  1726   1732   
  1727   1733   /*
................................................................................
  1769   1775       if( i>=n ) break;
  1770   1776       i += fts5GetVarint(&a[i], (u64*)&iDelta);
  1771   1777       pIter->iRowid += iDelta;
  1772   1778   
  1773   1779       /* If necessary, grow the pIter->aRowidOffset[] array. */
  1774   1780       if( iRowidOffset>=pIter->nRowidOffset ){
  1775   1781         int nNew = pIter->nRowidOffset + 8;
  1776         -      int *aNew = (int*)sqlite3_realloc(pIter->aRowidOffset, nNew*sizeof(int));
         1782  +      int *aNew = (int*)sqlite3_realloc64(pIter->aRowidOffset,nNew*sizeof(int));
  1777   1783         if( aNew==0 ){
  1778   1784           p->rc = SQLITE_NOMEM;
  1779   1785           break;
  1780   1786         }
  1781   1787         pIter->aRowidOffset = aNew;
  1782   1788         pIter->nRowidOffset = nNew;
  1783   1789       }
................................................................................
  2223   2229     const u8 *pTerm, int nTerm      /* Term to search for */
  2224   2230   ){
  2225   2231     int iOff;
  2226   2232     const u8 *a = pIter->pLeaf->p;
  2227   2233     int szLeaf = pIter->pLeaf->szLeaf;
  2228   2234     int n = pIter->pLeaf->nn;
  2229   2235   
  2230         -  int nMatch = 0;
  2231         -  int nKeep = 0;
  2232         -  int nNew = 0;
  2233         -  int iTermOff;
         2236  +  u32 nMatch = 0;
         2237  +  u32 nKeep = 0;
         2238  +  u32 nNew = 0;
         2239  +  u32 iTermOff;
  2234   2240     int iPgidx;                     /* Current offset in pgidx */
  2235   2241     int bEndOfPage = 0;
  2236   2242   
  2237   2243     assert( p->rc==SQLITE_OK );
  2238   2244   
  2239   2245     iPgidx = szLeaf;
  2240   2246     iPgidx += fts5GetVarint32(&a[iPgidx], iTermOff);
................................................................................
  2250   2256       fts5FastGetVarint32(a, iOff, nNew);
  2251   2257       if( nKeep<nMatch ){
  2252   2258         goto search_failed;
  2253   2259       }
  2254   2260   
  2255   2261       assert( nKeep>=nMatch );
  2256   2262       if( nKeep==nMatch ){
  2257         -      int nCmp;
  2258         -      int i;
  2259         -      nCmp = MIN(nNew, nTerm-nMatch);
         2263  +      u32 nCmp;
         2264  +      u32 i;
         2265  +      nCmp = (u32)MIN(nNew, nTerm-nMatch);
  2260   2266         for(i=0; i<nCmp; i++){
  2261   2267           if( a[iOff+i]!=pTerm[nMatch+i] ) break;
  2262   2268         }
  2263   2269         nMatch += i;
  2264   2270   
  2265         -      if( nTerm==nMatch ){
         2271  +      if( (u32)nTerm==nMatch ){
  2266   2272           if( i==nNew ){
  2267   2273             goto search_success;
  2268   2274           }else{
  2269   2275             goto search_failed;
  2270   2276           }
  2271   2277         }else if( i<nNew && a[iOff+i]>pTerm[nMatch] ){
  2272   2278           goto search_failed;
................................................................................
  2302   2308         if( pIter->pLeaf==0 ) return;
  2303   2309         a = pIter->pLeaf->p;
  2304   2310         if( fts5LeafIsTermless(pIter->pLeaf)==0 ){
  2305   2311           iPgidx = pIter->pLeaf->szLeaf;
  2306   2312           iPgidx += fts5GetVarint32(&pIter->pLeaf->p[iPgidx], iOff);
  2307   2313           if( iOff<4 || iOff>=pIter->pLeaf->szLeaf ){
  2308   2314             p->rc = FTS5_CORRUPT;
         2315  +          return;
  2309   2316           }else{
  2310   2317             nKeep = 0;
  2311   2318             iTermOff = iOff;
  2312   2319             n = pIter->pLeaf->nn;
  2313   2320             iOff += fts5GetVarint32(&a[iOff], nNew);
  2314   2321             break;
  2315   2322           }
  2316   2323         }
  2317   2324       }while( 1 );
  2318   2325     }
  2319   2326   
  2320   2327    search_success:
  2321         -
  2322   2328     pIter->iLeafOffset = iOff + nNew;
         2329  +  if( pIter->iLeafOffset>n || nNew<1 ){
         2330  +    p->rc = FTS5_CORRUPT;
         2331  +    return;
         2332  +  }
  2323   2333     pIter->iTermLeafOffset = pIter->iLeafOffset;
  2324   2334     pIter->iTermLeafPgno = pIter->iLeafPgno;
  2325   2335   
  2326   2336     fts5BufferSet(&p->rc, &pIter->term, nKeep, pTerm);
  2327   2337     fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
  2328   2338   
  2329   2339     if( iPgidx>=n ){
................................................................................
  2422   2432     **
  2423   2433     **   1) an error has occurred, or
  2424   2434     **   2) the iterator points to EOF, or
  2425   2435     **   3) the iterator points to an entry with term (pTerm/nTerm), or
  2426   2436     **   4) the FTS5INDEX_QUERY_SCAN flag was set and the iterator points
  2427   2437     **      to an entry with a term greater than or equal to (pTerm/nTerm).
  2428   2438     */
  2429         -  assert( p->rc!=SQLITE_OK                                          /* 1 */
         2439  +  assert_nc( p->rc!=SQLITE_OK                                       /* 1 */
  2430   2440      || pIter->pLeaf==0                                               /* 2 */
  2431   2441      || fts5BufferCompareBlob(&pIter->term, pTerm, nTerm)==0          /* 3 */
  2432   2442      || (bGe && fts5BufferCompareBlob(&pIter->term, pTerm, nTerm)>0)  /* 4 */
  2433   2443     );
  2434   2444   }
  2435   2445   
  2436   2446   /*
................................................................................
  2520   2530     if( p1->pLeaf || p2->pLeaf ){
  2521   2531       if( p1->pLeaf==0 ){
  2522   2532         assert( pRes->iFirst==i2 );
  2523   2533       }else if( p2->pLeaf==0 ){
  2524   2534         assert( pRes->iFirst==i1 );
  2525   2535       }else{
  2526   2536         int nMin = MIN(p1->term.n, p2->term.n);
  2527         -      int res = memcmp(p1->term.p, p2->term.p, nMin);
         2537  +      int res = fts5Memcmp(p1->term.p, p2->term.p, nMin);
  2528   2538         if( res==0 ) res = p1->term.n - p2->term.n;
  2529   2539   
  2530   2540         if( res==0 ){
  2531   2541           assert( pRes->bTermEq==1 );
  2532   2542           assert( p1->iRowid!=p2->iRowid );
  2533   2543           res = ((p1->iRowid > p2->iRowid)==pIter->bRev) ? -1 : 1;
  2534   2544         }else{
................................................................................
  2743   2753   */
  2744   2754   static void fts5MultiIterFree(Fts5Iter *pIter){
  2745   2755     if( pIter ){
  2746   2756       int i;
  2747   2757       for(i=0; i<pIter->nSeg; i++){
  2748   2758         fts5SegIterClear(&pIter->aSeg[i]);
  2749   2759       }
  2750         -    fts5StructureRelease(pIter->pStruct);
  2751   2760       fts5BufferFree(&pIter->poslist);
  2752   2761       sqlite3_free(pIter);
  2753   2762     }
  2754   2763   }
  2755   2764   
  2756   2765   static void fts5MultiIterAdvanced(
  2757   2766     Fts5Index *p,                   /* FTS5 backend to iterate within */
................................................................................
  3091   3100   */
  3092   3101   static void fts5SegiterPoslist(
  3093   3102     Fts5Index *p,
  3094   3103     Fts5SegIter *pSeg,
  3095   3104     Fts5Colset *pColset,
  3096   3105     Fts5Buffer *pBuf
  3097   3106   ){
  3098         -  if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos) ){
         3107  +  if( 0==fts5BufferGrow(&p->rc, pBuf, pSeg->nPos+FTS5_DATA_ZERO_PADDING) ){
         3108  +    memset(&pBuf->p[pBuf->n+pSeg->nPos], 0, FTS5_DATA_ZERO_PADDING);
  3099   3109       if( pColset==0 ){
  3100   3110         fts5ChunkIterate(p, pSeg, (void*)pBuf, fts5PoslistCallback);
  3101   3111       }else{
  3102   3112         if( p->pConfig->eDetail==FTS5_DETAIL_FULL ){
  3103   3113           PoslistCallbackCtx sCtx;
  3104   3114           sCtx.pBuf = pBuf;
  3105   3115           sCtx.pColset = pColset;
................................................................................
  3389   3399         nSeg = MIN(pStruct->aLevel[iLevel].nSeg, nSegment);
  3390   3400       }
  3391   3401     }
  3392   3402     *ppOut = pNew = fts5MultiIterAlloc(p, nSeg);
  3393   3403     if( pNew==0 ) return;
  3394   3404     pNew->bRev = (0!=(flags & FTS5INDEX_QUERY_DESC));
  3395   3405     pNew->bSkipEmpty = (0!=(flags & FTS5INDEX_QUERY_SKIPEMPTY));
  3396         -  pNew->pStruct = pStruct;
  3397   3406     pNew->pColset = pColset;
  3398         -  fts5StructureRef(pStruct);
  3399   3407     if( (flags & FTS5INDEX_QUERY_NOOUTPUT)==0 ){
  3400   3408       fts5IterSetOutputCb(&p->rc, pNew);
  3401   3409     }
  3402   3410   
  3403   3411     /* Initialize each of the component segment iterators. */
  3404   3412     if( p->rc==SQLITE_OK ){
  3405   3413       if( iLevel<0 ){
................................................................................
  3569   3577         int iLvl, iSeg;
  3570   3578         int i;
  3571   3579         u32 mask;
  3572   3580         memset(aUsed, 0, sizeof(aUsed));
  3573   3581         for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
  3574   3582           for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
  3575   3583             int iId = pStruct->aLevel[iLvl].aSeg[iSeg].iSegid;
  3576         -          if( iId<=FTS5_MAX_SEGMENT ){
  3577         -            aUsed[(iId-1) / 32] |= 1 << ((iId-1) % 32);
         3584  +          if( iId<=FTS5_MAX_SEGMENT && iId>0 ){
         3585  +            aUsed[(iId-1) / 32] |= (u32)1 << ((iId-1) % 32);
  3578   3586             }
  3579   3587           }
  3580   3588         }
  3581   3589   
  3582   3590         for(i=0; aUsed[i]==0xFFFFFFFF; i++);
  3583   3591         mask = aUsed[i];
  3584         -      for(iSegid=0; mask & (1 << iSegid); iSegid++);
         3592  +      for(iSegid=0; mask & ((u32)1 << iSegid); iSegid++);
  3585   3593         iSegid += 1 + i*32;
  3586   3594   
  3587   3595   #ifdef SQLITE_DEBUG
  3588   3596         for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
  3589   3597           for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
  3590         -          assert( iSegid!=pStruct->aLevel[iLvl].aSeg[iSeg].iSegid );
         3598  +          assert_nc( iSegid!=pStruct->aLevel[iLvl].aSeg[iSeg].iSegid );
  3591   3599           }
  3592   3600         }
  3593         -      assert( iSegid>0 && iSegid<=FTS5_MAX_SEGMENT );
         3601  +      assert_nc( iSegid>0 && iSegid<=FTS5_MAX_SEGMENT );
  3594   3602   
  3595   3603         {
  3596   3604           sqlite3_stmt *pIdxSelect = fts5IdxSelectStmt(p);
  3597   3605           if( p->rc==SQLITE_OK ){
  3598   3606             u8 aBlob[2] = {0xff, 0xff};
  3599   3607             sqlite3_bind_int(pIdxSelect, 1, iSegid);
  3600   3608             sqlite3_bind_blob(pIdxSelect, 2, aBlob, 2, SQLITE_STATIC);
  3601         -          assert( sqlite3_step(pIdxSelect)!=SQLITE_ROW );
         3609  +          assert_nc( sqlite3_step(pIdxSelect)!=SQLITE_ROW );
  3602   3610             p->rc = sqlite3_reset(pIdxSelect);
  3603   3611             sqlite3_bind_null(pIdxSelect, 2);
  3604   3612           }
  3605   3613         }
  3606   3614   #endif
  3607   3615       }
  3608   3616     }
................................................................................
  3664   3672   */
  3665   3673   static int fts5WriteDlidxGrow(
  3666   3674     Fts5Index *p,
  3667   3675     Fts5SegWriter *pWriter,
  3668   3676     int nLvl
  3669   3677   ){
  3670   3678     if( p->rc==SQLITE_OK && nLvl>=pWriter->nDlidx ){
  3671         -    Fts5DlidxWriter *aDlidx = (Fts5DlidxWriter*)sqlite3_realloc(
         3679  +    Fts5DlidxWriter *aDlidx = (Fts5DlidxWriter*)sqlite3_realloc64(
  3672   3680           pWriter->aDlidx, sizeof(Fts5DlidxWriter) * nLvl
  3673   3681       );
  3674   3682       if( aDlidx==0 ){
  3675   3683         p->rc = SQLITE_NOMEM;
  3676   3684       }else{
  3677   3685         int nByte = sizeof(Fts5DlidxWriter) * (nLvl - pWriter->nDlidx);
  3678   3686         memset(&aDlidx[pWriter->nDlidx], 0, nByte);
................................................................................
  3743   3751   */
  3744   3752   static void fts5WriteBtreeTerm(
  3745   3753     Fts5Index *p,                   /* FTS5 backend object */
  3746   3754     Fts5SegWriter *pWriter,         /* Writer object */
  3747   3755     int nTerm, const u8 *pTerm      /* First term on new page */
  3748   3756   ){
  3749   3757     fts5WriteFlushBtree(p, pWriter);
  3750         -  fts5BufferSet(&p->rc, &pWriter->btterm, nTerm, pTerm);
  3751         -  pWriter->iBtPage = pWriter->writer.pgno;
         3758  +  if( p->rc==SQLITE_OK ){
         3759  +    fts5BufferSet(&p->rc, &pWriter->btterm, nTerm, pTerm);
         3760  +    pWriter->iBtPage = pWriter->writer.pgno;
         3761  +  }
  3752   3762   }
  3753   3763   
  3754   3764   /*
  3755   3765   ** This function is called when flushing a leaf page that contains no
  3756   3766   ** terms at all to disk.
  3757   3767   */
  3758   3768   static void fts5WriteBtreeNoTerm(
................................................................................
  3895   3905     Fts5Index *p, 
  3896   3906     Fts5SegWriter *pWriter,
  3897   3907     int nTerm, const u8 *pTerm 
  3898   3908   ){
  3899   3909     int nPrefix;                    /* Bytes of prefix compression for term */
  3900   3910     Fts5PageWriter *pPage = &pWriter->writer;
  3901   3911     Fts5Buffer *pPgidx = &pWriter->writer.pgidx;
         3912  +  int nMin = MIN(pPage->term.n, nTerm);
  3902   3913   
  3903   3914     assert( p->rc==SQLITE_OK );
  3904   3915     assert( pPage->buf.n>=4 );
  3905   3916     assert( pPage->buf.n>4 || pWriter->bFirstTermInPage );
  3906   3917   
  3907   3918     /* If the current leaf page is full, flush it to disk. */
  3908   3919     if( (pPage->buf.n + pPgidx->n + nTerm + 2)>=p->pConfig->pgsz ){
  3909   3920       if( pPage->buf.n>4 ){
  3910   3921         fts5WriteFlushLeaf(p, pWriter);
         3922  +      if( p->rc!=SQLITE_OK ) return;
  3911   3923       }
  3912   3924       fts5BufferGrow(&p->rc, &pPage->buf, nTerm+FTS5_DATA_PADDING);
  3913   3925     }
  3914   3926     
  3915   3927     /* TODO1: Updating pgidx here. */
  3916   3928     pPgidx->n += sqlite3Fts5PutVarint(
  3917   3929         &pPgidx->p[pPgidx->n], pPage->buf.n - pPage->iPrevPgidx
................................................................................
  3936   3948         ** Usually, the previous term is available in pPage->term. The exception
  3937   3949         ** is if this is the first term written in an incremental-merge step.
  3938   3950         ** In this case the previous term is not available, so just write a
  3939   3951         ** copy of (pTerm/nTerm) into the parent node. This is slightly
  3940   3952         ** inefficient, but still correct.  */
  3941   3953         int n = nTerm;
  3942   3954         if( pPage->term.n ){
  3943         -        n = 1 + fts5PrefixCompress(pPage->term.n, pPage->term.p, pTerm);
         3955  +        n = 1 + fts5PrefixCompress(nMin, pPage->term.p, pTerm);
  3944   3956         }
  3945   3957         fts5WriteBtreeTerm(p, pWriter, n, pTerm);
         3958  +      if( p->rc!=SQLITE_OK ) return;
  3946   3959         pPage = &pWriter->writer;
  3947   3960       }
  3948   3961     }else{
  3949         -    nPrefix = fts5PrefixCompress(pPage->term.n, pPage->term.p, pTerm);
         3962  +    nPrefix = fts5PrefixCompress(nMin, pPage->term.p, pTerm);
  3950   3963       fts5BufferAppendVarint(&p->rc, &pPage->buf, nPrefix);
  3951   3964     }
  3952   3965   
  3953   3966     /* Append the number of bytes of new data, then the term data itself
  3954   3967     ** to the page. */
  3955   3968     fts5BufferAppendVarint(&p->rc, &pPage->buf, nTerm - nPrefix);
  3956   3969     fts5BufferAppendBlob(&p->rc, &pPage->buf, nTerm - nPrefix, &pTerm[nPrefix]);
................................................................................
  3989   4002         fts5WriteDlidxAppend(p, pWriter, iRowid);
  3990   4003       }
  3991   4004   
  3992   4005       /* Write the rowid. */
  3993   4006       if( pWriter->bFirstRowidInDoclist || pWriter->bFirstRowidInPage ){
  3994   4007         fts5BufferAppendVarint(&p->rc, &pPage->buf, iRowid);
  3995   4008       }else{
  3996         -      assert( p->rc || iRowid>pWriter->iPrevRowid );
         4009  +      assert_nc( p->rc || iRowid>pWriter->iPrevRowid );
  3997   4010         fts5BufferAppendVarint(&p->rc, &pPage->buf, iRowid - pWriter->iPrevRowid);
  3998   4011       }
  3999   4012       pWriter->iPrevRowid = iRowid;
  4000   4013       pWriter->bFirstRowidInDoclist = 0;
  4001   4014       pWriter->bFirstRowidInPage = 0;
  4002   4015     }
  4003   4016   }
................................................................................
  4111   4124   ** incremental merge operation. This function is called if the incremental
  4112   4125   ** merge step has finished but the input has not been completely exhausted.
  4113   4126   */
  4114   4127   static void fts5TrimSegments(Fts5Index *p, Fts5Iter *pIter){
  4115   4128     int i;
  4116   4129     Fts5Buffer buf;
  4117   4130     memset(&buf, 0, sizeof(Fts5Buffer));
  4118         -  for(i=0; i<pIter->nSeg; i++){
         4131  +  for(i=0; i<pIter->nSeg && p->rc==SQLITE_OK; i++){
  4119   4132       Fts5SegIter *pSeg = &pIter->aSeg[i];
  4120   4133       if( pSeg->pSeg==0 ){
  4121   4134         /* no-op */
  4122   4135       }else if( pSeg->pLeaf==0 ){
  4123   4136         /* All keys from this input segment have been transfered to the output.
  4124   4137         ** Set both the first and last page-numbers to 0 to indicate that the
  4125   4138         ** segment is now empty. */
................................................................................
  4129   4142         int iOff = pSeg->iTermLeafOffset;     /* Offset on new first leaf page */
  4130   4143         i64 iLeafRowid;
  4131   4144         Fts5Data *pData;
  4132   4145         int iId = pSeg->pSeg->iSegid;
  4133   4146         u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00};
  4134   4147   
  4135   4148         iLeafRowid = FTS5_SEGMENT_ROWID(iId, pSeg->iTermLeafPgno);
  4136         -      pData = fts5DataRead(p, iLeafRowid);
         4149  +      pData = fts5LeafRead(p, iLeafRowid);
  4137   4150         if( pData ){
  4138         -        fts5BufferZero(&buf);
  4139         -        fts5BufferGrow(&p->rc, &buf, pData->nn);
  4140         -        fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
  4141         -        fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
  4142         -        fts5BufferAppendBlob(&p->rc, &buf, pSeg->term.n, pSeg->term.p);
  4143         -        fts5BufferAppendBlob(&p->rc, &buf, pData->szLeaf-iOff, &pData->p[iOff]);
  4144         -        if( p->rc==SQLITE_OK ){
  4145         -          /* Set the szLeaf field */
  4146         -          fts5PutU16(&buf.p[2], (u16)buf.n);
  4147         -        }
  4148         -
  4149         -        /* Set up the new page-index array */
  4150         -        fts5BufferAppendVarint(&p->rc, &buf, 4);
  4151         -        if( pSeg->iLeafPgno==pSeg->iTermLeafPgno 
  4152         -         && pSeg->iEndofDoclist<pData->szLeaf 
  4153         -        ){
  4154         -          int nDiff = pData->szLeaf - pSeg->iEndofDoclist;
  4155         -          fts5BufferAppendVarint(&p->rc, &buf, buf.n - 1 - nDiff - 4);
  4156         -          fts5BufferAppendBlob(&p->rc, &buf, 
  4157         -              pData->nn - pSeg->iPgidxOff, &pData->p[pSeg->iPgidxOff]
  4158         -          );
  4159         -        }
  4160         -
  4161         -        fts5DataRelease(pData);
  4162         -        pSeg->pSeg->pgnoFirst = pSeg->iTermLeafPgno;
  4163         -        fts5DataDelete(p, FTS5_SEGMENT_ROWID(iId, 1), iLeafRowid);
  4164         -        fts5DataWrite(p, iLeafRowid, buf.p, buf.n);
         4151  +        if( iOff>pData->szLeaf ){
         4152  +          /* This can occur if the pages that the segments occupy overlap - if
         4153  +          ** a single page has been assigned to more than one segment. In
         4154  +          ** this case a prior iteration of this loop may have corrupted the
         4155  +          ** segment currently being trimmed.  */
         4156  +          p->rc = FTS5_CORRUPT;
         4157  +        }else{
         4158  +          fts5BufferZero(&buf);
         4159  +          fts5BufferGrow(&p->rc, &buf, pData->nn);
         4160  +          fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
         4161  +          fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
         4162  +          fts5BufferAppendBlob(&p->rc, &buf, pSeg->term.n, pSeg->term.p);
         4163  +          fts5BufferAppendBlob(&p->rc, &buf, pData->szLeaf-iOff,&pData->p[iOff]);
         4164  +          if( p->rc==SQLITE_OK ){
         4165  +            /* Set the szLeaf field */
         4166  +            fts5PutU16(&buf.p[2], (u16)buf.n);
         4167  +          }
         4168  +
         4169  +          /* Set up the new page-index array */
         4170  +          fts5BufferAppendVarint(&p->rc, &buf, 4);
         4171  +          if( pSeg->iLeafPgno==pSeg->iTermLeafPgno 
         4172  +              && pSeg->iEndofDoclist<pData->szLeaf 
         4173  +            ){
         4174  +            int nDiff = pData->szLeaf - pSeg->iEndofDoclist;
         4175  +            fts5BufferAppendVarint(&p->rc, &buf, buf.n - 1 - nDiff - 4);
         4176  +            fts5BufferAppendBlob(&p->rc, &buf, 
         4177  +                pData->nn - pSeg->iPgidxOff, &pData->p[pSeg->iPgidxOff]
         4178  +                );
         4179  +          }
         4180  +
         4181  +          pSeg->pSeg->pgnoFirst = pSeg->iTermLeafPgno;
         4182  +          fts5DataDelete(p, FTS5_SEGMENT_ROWID(iId, 1), iLeafRowid);
         4183  +          fts5DataWrite(p, iLeafRowid, buf.p, buf.n);
         4184  +        }
         4185  +        fts5DataRelease(pData);
  4165   4186         }
  4166   4187       }
  4167   4188     }
  4168   4189     fts5BufferFree(&buf);
  4169   4190   }
  4170   4191   
  4171   4192   static void fts5MergeChunkCallback(
................................................................................
  4249   4270     ){
  4250   4271       Fts5SegIter *pSegIter = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
  4251   4272       int nPos;                     /* position-list size field value */
  4252   4273       int nTerm;
  4253   4274       const u8 *pTerm;
  4254   4275   
  4255   4276       pTerm = fts5MultiIterTerm(pIter, &nTerm);
  4256         -    if( nTerm!=term.n || memcmp(pTerm, term.p, nTerm) ){
         4277  +    if( nTerm!=term.n || fts5Memcmp(pTerm, term.p, nTerm) ){
  4257   4278         if( pnRem && writer.nLeafWritten>nRem ){
  4258   4279           break;
  4259   4280         }
  4260   4281         fts5BufferSet(&p->rc, &term, nTerm, pTerm);
  4261   4282         bTermWritten =0;
  4262   4283       }
  4263   4284   
................................................................................
  4504   4525         const char *zTerm;          /* Buffer containing term */
  4505   4526         const u8 *pDoclist;         /* Pointer to doclist for this term */
  4506   4527         int nDoclist;               /* Size of doclist in bytes */
  4507   4528   
  4508   4529         /* Write the term for this entry to disk. */
  4509   4530         sqlite3Fts5HashScanEntry(pHash, &zTerm, &pDoclist, &nDoclist);
  4510   4531         fts5WriteAppendTerm(p, &writer, (int)strlen(zTerm), (const u8*)zTerm);
         4532  +      if( p->rc!=SQLITE_OK ) break;
  4511   4533   
  4512   4534         assert( writer.bFirstRowidInPage==0 );
  4513   4535         if( pgsz>=(pBuf->n + pPgidx->n + nDoclist + 1) ){
  4514   4536           /* The entire doclist will fit on the current leaf. */
  4515   4537           fts5BufferSafeAppendBlob(pBuf, pDoclist, nDoclist);
  4516   4538         }else{
  4517   4539           i64 iRowid = 0;
................................................................................
  4526   4548             iRowid += iDelta;
  4527   4549             
  4528   4550             if( writer.bFirstRowidInPage ){
  4529   4551               fts5PutU16(&pBuf->p[0], (u16)pBuf->n);   /* first rowid on page */
  4530   4552               pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iRowid);
  4531   4553               writer.bFirstRowidInPage = 0;
  4532   4554               fts5WriteDlidxAppend(p, &writer, iRowid);
         4555  +            if( p->rc!=SQLITE_OK ) break;
  4533   4556             }else{
  4534   4557               pBuf->n += sqlite3Fts5PutVarint(&pBuf->p[pBuf->n], iDelta);
  4535   4558             }
  4536   4559             assert( pBuf->n<=pBuf->nSpace );
  4537   4560   
  4538   4561             if( eDetail==FTS5_DETAIL_NONE ){
  4539   4562               if( iOff<nDoclist && pDoclist[iOff]==0 ){
................................................................................
  4583   4606             }
  4584   4607           }
  4585   4608         }
  4586   4609   
  4587   4610         /* TODO2: Doclist terminator written here. */
  4588   4611         /* pBuf->p[pBuf->n++] = '\0'; */
  4589   4612         assert( pBuf->n<=pBuf->nSpace );
  4590         -      sqlite3Fts5HashScanNext(pHash);
         4613  +      if( p->rc==SQLITE_OK ) sqlite3Fts5HashScanNext(pHash);
  4591   4614       }
  4592   4615       sqlite3Fts5HashClear(pHash);
  4593   4616       fts5WriteFinish(p, &writer, &pgnoLast);
  4594   4617   
  4595   4618       /* Update the Fts5Structure. It is written back to the database by the
  4596   4619       ** fts5StructureRelease() call below.  */
  4597   4620       if( pStruct->nLevel==0 ){
................................................................................
  4627   4650   }
  4628   4651   
  4629   4652   static Fts5Structure *fts5IndexOptimizeStruct(
  4630   4653     Fts5Index *p, 
  4631   4654     Fts5Structure *pStruct
  4632   4655   ){
  4633   4656     Fts5Structure *pNew = 0;
  4634         -  int nByte = sizeof(Fts5Structure);
         4657  +  sqlite3_int64 nByte = sizeof(Fts5Structure);
  4635   4658     int nSeg = pStruct->nSegment;
  4636   4659     int i;
  4637   4660   
  4638   4661     /* Figure out if this structure requires optimization. A structure does
  4639   4662     ** not require optimization if either:
  4640   4663     **
  4641   4664     **  + it consists of fewer than two segments, or 
................................................................................
  4757   4780   static void fts5AppendPoslist(
  4758   4781     Fts5Index *p,
  4759   4782     i64 iDelta,
  4760   4783     Fts5Iter *pMulti,
  4761   4784     Fts5Buffer *pBuf
  4762   4785   ){
  4763   4786     int nData = pMulti->base.nData;
         4787  +  int nByte = nData + 9 + 9 + FTS5_DATA_ZERO_PADDING;
  4764   4788     assert( nData>0 );
  4765         -  if( p->rc==SQLITE_OK && 0==fts5BufferGrow(&p->rc, pBuf, nData+9+9) ){
         4789  +  if( p->rc==SQLITE_OK && 0==fts5BufferGrow(&p->rc, pBuf, nByte) ){
  4766   4790       fts5BufferSafeAppendVarint(pBuf, iDelta);
  4767   4791       fts5BufferSafeAppendVarint(pBuf, nData*2);
  4768   4792       fts5BufferSafeAppendBlob(pBuf, pMulti->base.pData, nData);
         4793  +    memset(&pBuf->p[pBuf->n], 0, FTS5_DATA_ZERO_PADDING);
  4769   4794     }
  4770   4795   }
  4771   4796   
  4772   4797   
  4773   4798   static void fts5DoclistIterNext(Fts5DoclistIter *pIter){
  4774   4799     u8 *p = pIter->aPoslist + pIter->nSize + pIter->nPoslist;
  4775   4800   
................................................................................
  4942   4967           /* Merge the two position lists. */ 
  4943   4968           i64 iPos1 = 0;
  4944   4969           i64 iPos2 = 0;
  4945   4970           int iOff1 = 0;
  4946   4971           int iOff2 = 0;
  4947   4972           u8 *a1 = &i1.aPoslist[i1.nSize];
  4948   4973           u8 *a2 = &i2.aPoslist[i2.nSize];
         4974  +        int nCopy;
         4975  +        u8 *aCopy;
  4949   4976   
  4950   4977           i64 iPrev = 0;
  4951   4978           Fts5PoslistWriter writer;
  4952   4979           memset(&writer, 0, sizeof(writer));
  4953   4980   
  4954   4981           fts5MergeAppendDocid(&out, iLastRowid, i2.iRowid);
  4955   4982           fts5BufferZero(&tmp);
................................................................................
  4973   5000               if( iPos1<iPos2 ){
  4974   5001                 if( iPos1!=iPrev ){
  4975   5002                   sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos1);
  4976   5003                 }
  4977   5004                 sqlite3Fts5PoslistNext64(a1, i1.nPoslist, &iOff1, &iPos1);
  4978   5005                 if( iPos1<0 ) break;
  4979   5006               }else{
  4980         -              assert( iPos2!=iPrev );
         5007  +              assert_nc( iPos2!=iPrev );
  4981   5008                 sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos2);
  4982   5009                 sqlite3Fts5PoslistNext64(a2, i2.nPoslist, &iOff2, &iPos2);
  4983   5010                 if( iPos2<0 ) break;
  4984   5011               }
  4985   5012             }
  4986   5013           }
  4987   5014   
  4988   5015           if( iPos1>=0 ){
  4989   5016             if( iPos1!=iPrev ){
  4990   5017               sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos1);
  4991   5018             }
  4992         -          fts5BufferSafeAppendBlob(&tmp, &a1[iOff1], i1.nPoslist-iOff1);
         5019  +          aCopy = &a1[iOff1];
         5020  +          nCopy = i1.nPoslist - iOff1;
  4993   5021           }else{
  4994   5022             assert( iPos2>=0 && iPos2!=iPrev );
  4995   5023             sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos2);
  4996         -          fts5BufferSafeAppendBlob(&tmp, &a2[iOff2], i2.nPoslist-iOff2);
         5024  +          aCopy = &a2[iOff2];
         5025  +          nCopy = i2.nPoslist - iOff2;
         5026  +        }
         5027  +        if( nCopy>0 ){
         5028  +          fts5BufferSafeAppendBlob(&tmp, aCopy, nCopy);
  4997   5029           }
  4998   5030   
  4999   5031           /* WRITEPOSLISTSIZE */
  5000   5032           fts5BufferSafeAppendVarint(&out, tmp.n * 2);
  5001   5033           fts5BufferSafeAppendBlob(&out, tmp.p, tmp.n);
  5002   5034           fts5DoclistIterNext(&i1);
  5003   5035           fts5DoclistIterNext(&i2);
         5036  +        assert( out.n<=(p1->n+p2->n+9) );
  5004   5037           if( i1.aPoslist==0 || i2.aPoslist==0 ) break;
  5005   5038         }
  5006   5039       }
  5007   5040   
  5008   5041       if( i1.aPoslist ){
  5009   5042         fts5MergeAppendDocid(&out, iLastRowid, i1.iRowid);
  5010   5043         fts5BufferSafeAppendBlob(&out, i1.aPoslist, i1.aEof - i1.aPoslist);
................................................................................
  5098   5131         if( p->rc==SQLITE_OK ){
  5099   5132           xMerge(p, &doclist, &aBuf[i]);
  5100   5133         }
  5101   5134         fts5BufferFree(&aBuf[i]);
  5102   5135       }
  5103   5136       fts5MultiIterFree(p1);
  5104   5137   
  5105         -    pData = fts5IdxMalloc(p, sizeof(Fts5Data) + doclist.n);
         5138  +    pData = fts5IdxMalloc(p, sizeof(Fts5Data)+doclist.n+FTS5_DATA_ZERO_PADDING);
  5106   5139       if( pData ){
  5107   5140         pData->p = (u8*)&pData[1];
  5108   5141         pData->nn = pData->szLeaf = doclist.n;
  5109   5142         if( doclist.n ) memcpy(pData->p, doclist.p, doclist.n);
  5110   5143         fts5MultiIterNew2(p, pData, bDesc, ppIter);
  5111   5144       }
  5112   5145       fts5BufferFree(&doclist);
................................................................................
  5398   5431   
  5399   5432       if( p->rc ){
  5400   5433         sqlite3Fts5IterClose((Fts5IndexIter*)pRet);
  5401   5434         pRet = 0;
  5402   5435         fts5CloseReader(p);
  5403   5436       }
  5404   5437   
  5405         -    *ppIter = &pRet->base;
         5438  +    *ppIter = (Fts5IndexIter*)pRet;
  5406   5439       sqlite3Fts5BufferFree(&buf);
  5407   5440     }
  5408   5441     return fts5IndexReturn(p);
  5409   5442   }
  5410   5443   
  5411   5444   /*
  5412   5445   ** Return true if the iterator passed as the only argument is at EOF.
................................................................................
  5860   5893         int iOff;                   /* Offset of first term on leaf */
  5861   5894         int iRowidOff;              /* Offset of first rowid on leaf */
  5862   5895         int nTerm;                  /* Size of term on leaf in bytes */
  5863   5896         int res;                    /* Comparison of term and split-key */
  5864   5897   
  5865   5898         iOff = fts5LeafFirstTermOff(pLeaf);
  5866   5899         iRowidOff = fts5LeafFirstRowidOff(pLeaf);
  5867         -      if( iRowidOff>=iOff ){
         5900  +      if( iRowidOff>=iOff || iOff>=pLeaf->szLeaf ){
  5868   5901           p->rc = FTS5_CORRUPT;
  5869   5902         }else{
  5870   5903           iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
  5871         -        res = memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
         5904  +        res = fts5Memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
  5872   5905           if( res==0 ) res = nTerm - nIdxTerm;
  5873   5906           if( res<0 ) p->rc = FTS5_CORRUPT;
  5874   5907         }
  5875   5908   
  5876   5909         fts5IntegrityCheckPgidx(p, pLeaf);
  5877   5910       }
  5878   5911       fts5DataRelease(pLeaf);
................................................................................
  6259   6292   ){
  6260   6293     i64 iRowid;                     /* Rowid for record being decoded */
  6261   6294     int iSegid,iHeight,iPgno,bDlidx;/* Rowid components */
  6262   6295     const u8 *aBlob; int n;         /* Record to decode */
  6263   6296     u8 *a = 0;
  6264   6297     Fts5Buffer s;                   /* Build up text to return here */
  6265   6298     int rc = SQLITE_OK;             /* Return code */
  6266         -  int nSpace = 0;
         6299  +  sqlite3_int64 nSpace = 0;
  6267   6300     int eDetailNone = (sqlite3_user_data(pCtx)!=0);
  6268   6301   
  6269   6302     assert( nArg==2 );
  6270   6303     UNUSED_PARAM(nArg);
  6271   6304     memset(&s, 0, sizeof(Fts5Buffer));
  6272   6305     iRowid = sqlite3_value_int64(apVal[0]);
  6273   6306   
................................................................................
  6275   6308     ** copy is followed by FTS5_DATA_ZERO_PADDING 0x00 bytes, which prevents
  6276   6309     ** buffer overreads even if the record is corrupt.  */
  6277   6310     n = sqlite3_value_bytes(apVal[1]);
  6278   6311     aBlob = sqlite3_value_blob(apVal[1]);
  6279   6312     nSpace = n + FTS5_DATA_ZERO_PADDING;
  6280   6313     a = (u8*)sqlite3Fts5MallocZero(&rc, nSpace);
  6281   6314     if( a==0 ) goto decode_out;
  6282         -  memcpy(a, aBlob, n);
  6283         -
         6315  +  if( n>0 ) memcpy(a, aBlob, n);
  6284   6316   
  6285   6317     fts5DecodeRowid(iRowid, &iSegid, &bDlidx, &iHeight, &iPgno);
  6286   6318   
  6287   6319     fts5DebugRowid(&rc, &s, iRowid);
  6288   6320     if( bDlidx ){
  6289   6321       Fts5Data dlidx;
  6290   6322       Fts5DlidxLvl lvl;
................................................................................
  6371   6403         sqlite3Fts5BufferSet(&rc, &s, 7, (const u8*)"corrupt");
  6372   6404         goto decode_out;
  6373   6405       }else{
  6374   6406         iRowidOff = fts5GetU16(&a[0]);
  6375   6407         iPgidxOff = szLeaf = fts5GetU16(&a[2]);
  6376   6408         if( iPgidxOff<n ){
  6377   6409           fts5GetVarint32(&a[iPgidxOff], iTermOff);
         6410  +      }else if( iPgidxOff>n ){
         6411  +        rc = FTS5_CORRUPT;
         6412  +        goto decode_out;
  6378   6413         }
  6379   6414       }
  6380   6415   
  6381   6416       /* Decode the position list tail at the start of the page */
  6382   6417       if( iRowidOff!=0 ){
  6383   6418         iOff = iRowidOff;
  6384   6419       }else if( iTermOff!=0 ){
  6385   6420         iOff = iTermOff;
  6386   6421       }else{
  6387   6422         iOff = szLeaf;
  6388   6423       }
         6424  +    if( iOff>n ){
         6425  +      rc = FTS5_CORRUPT;
         6426  +      goto decode_out;
         6427  +    }
  6389   6428       fts5DecodePoslist(&rc, &s, &a[4], iOff-4);
  6390   6429   
  6391   6430       /* Decode any more doclist data that appears on the page before the
  6392   6431       ** first term. */
  6393   6432       nDoclist = (iTermOff ? iTermOff : szLeaf) - iOff;
         6433  +    if( nDoclist+iOff>n ){
         6434  +      rc = FTS5_CORRUPT;
         6435  +      goto decode_out;
         6436  +    }
  6394   6437       fts5DecodeDoclist(&rc, &s, &a[iOff], nDoclist);
  6395   6438   
  6396         -    while( iPgidxOff<n ){
         6439  +    while( iPgidxOff<n && rc==SQLITE_OK ){
  6397   6440         int bFirst = (iPgidxOff==szLeaf);     /* True for first term on page */
  6398   6441         int nByte;                            /* Bytes of data */
  6399   6442         int iEnd;
  6400   6443         
  6401   6444         iPgidxOff += fts5GetVarint32(&a[iPgidxOff], nByte);
  6402   6445         iPgidxPrev += nByte;
  6403   6446         iOff = iPgidxPrev;
................................................................................
  6404   6447   
  6405   6448         if( iPgidxOff<n ){
  6406   6449           fts5GetVarint32(&a[iPgidxOff], nByte);
  6407   6450           iEnd = iPgidxPrev + nByte;
  6408   6451         }else{
  6409   6452           iEnd = szLeaf;
  6410   6453         }
         6454  +      if( iEnd>szLeaf ){
         6455  +        rc = FTS5_CORRUPT;
         6456  +        break;
         6457  +      }
  6411   6458   
  6412   6459         if( bFirst==0 ){
  6413   6460           iOff += fts5GetVarint32(&a[iOff], nByte);
         6461  +        if( nByte>term.n ){
         6462  +          rc = FTS5_CORRUPT;
         6463  +          break;
         6464  +        }
  6414   6465           term.n = nByte;
  6415   6466         }
  6416   6467         iOff += fts5GetVarint32(&a[iOff], nByte);
         6468  +      if( iOff+nByte>n ){
         6469  +        rc = FTS5_CORRUPT;
         6470  +        break;
         6471  +      }
  6417   6472         fts5BufferAppendBlob(&rc, &term, nByte, &a[iOff]);
  6418   6473         iOff += nByte;
  6419   6474   
  6420   6475         sqlite3Fts5BufferAppendPrintf(
  6421   6476             &rc, &s, " term=%.*s", term.n, (const char*)term.p
  6422   6477         );
  6423   6478         iOff += fts5DecodeDoclist(&rc, &s, &a[iOff], iEnd-iOff);

Changes to ext/fts5/fts5_main.c.

    24     24   */
    25     25   int sqlite3_fts5_may_be_corrupt = 1;
    26     26   
    27     27   
    28     28   typedef struct Fts5Auxdata Fts5Auxdata;
    29     29   typedef struct Fts5Auxiliary Fts5Auxiliary;
    30     30   typedef struct Fts5Cursor Fts5Cursor;
           31  +typedef struct Fts5FullTable Fts5FullTable;
    31     32   typedef struct Fts5Sorter Fts5Sorter;
    32         -typedef struct Fts5Table Fts5Table;
    33     33   typedef struct Fts5TokenizerModule Fts5TokenizerModule;
    34     34   
    35     35   /*
    36     36   ** NOTES ON TRANSACTIONS: 
    37     37   **
    38     38   ** SQLite invokes the following virtual table methods as transactions are 
    39     39   ** opened and closed by the user:
................................................................................
   106    106     char *zName;                    /* Name of tokenizer */
   107    107     void *pUserData;                /* User pointer passed to xCreate() */
   108    108     fts5_tokenizer x;               /* Tokenizer functions */
   109    109     void (*xDestroy)(void*);        /* Destructor function */
   110    110     Fts5TokenizerModule *pNext;     /* Next registered tokenizer module */
   111    111   };
   112    112   
   113         -/*
   114         -** Virtual-table object.
   115         -*/
   116         -struct Fts5Table {
   117         -  sqlite3_vtab base;              /* Base class used by SQLite core */
   118         -  Fts5Config *pConfig;            /* Virtual table configuration */
   119         -  Fts5Index *pIndex;              /* Full-text index */
          113  +struct Fts5FullTable {
          114  +  Fts5Table p;                    /* Public class members from fts5Int.h */
   120    115     Fts5Storage *pStorage;          /* Document store */
   121    116     Fts5Global *pGlobal;            /* Global (connection wide) data */
   122    117     Fts5Cursor *pSortCsr;           /* Sort data from this cursor */
   123    118   #ifdef SQLITE_DEBUG
   124    119     struct Fts5TransactionState ts;
   125    120   #endif
   126    121   };
................................................................................
   250    245   #define FTS5_BEGIN      1
   251    246   #define FTS5_SYNC       2
   252    247   #define FTS5_COMMIT     3
   253    248   #define FTS5_ROLLBACK   4
   254    249   #define FTS5_SAVEPOINT  5
   255    250   #define FTS5_RELEASE    6
   256    251   #define FTS5_ROLLBACKTO 7
   257         -static void fts5CheckTransactionState(Fts5Table *p, int op, int iSavepoint){
          252  +static void fts5CheckTransactionState(Fts5FullTable *p, int op, int iSavepoint){
   258    253     switch( op ){
   259    254       case FTS5_BEGIN:
   260    255         assert( p->ts.eState==0 );
   261    256         p->ts.eState = 1;
   262    257         p->ts.iSavepoint = -1;
   263    258         break;
   264    259   
................................................................................
   289    284         assert( iSavepoint>=0 );
   290    285         assert( iSavepoint<=p->ts.iSavepoint );
   291    286         p->ts.iSavepoint = iSavepoint-1;
   292    287         break;
   293    288   
   294    289       case FTS5_ROLLBACKTO:
   295    290         assert( p->ts.eState==1 );
   296         -      assert( iSavepoint>=0 );
          291  +      assert( iSavepoint>=-1 );
   297    292         assert( iSavepoint<=p->ts.iSavepoint );
   298    293         p->ts.iSavepoint = iSavepoint;
   299    294         break;
   300    295     }
   301    296   }
   302    297   #else
   303    298   # define fts5CheckTransactionState(x,y,z)
   304    299   #endif
   305    300   
   306    301   /*
   307    302   ** Return true if pTab is a contentless table.
   308    303   */
   309         -static int fts5IsContentless(Fts5Table *pTab){
   310         -  return pTab->pConfig->eContent==FTS5_CONTENT_NONE;
          304  +static int fts5IsContentless(Fts5FullTable *pTab){
          305  +  return pTab->p.pConfig->eContent==FTS5_CONTENT_NONE;
   311    306   }
   312    307   
   313    308   /*
   314    309   ** Delete a virtual table handle allocated by fts5InitVtab(). 
   315    310   */
   316         -static void fts5FreeVtab(Fts5Table *pTab){
          311  +static void fts5FreeVtab(Fts5FullTable *pTab){
   317    312     if( pTab ){
   318         -    sqlite3Fts5IndexClose(pTab->pIndex);
          313  +    sqlite3Fts5IndexClose(pTab->p.pIndex);
   319    314       sqlite3Fts5StorageClose(pTab->pStorage);
   320         -    sqlite3Fts5ConfigFree(pTab->pConfig);
          315  +    sqlite3Fts5ConfigFree(pTab->p.pConfig);
   321    316       sqlite3_free(pTab);
   322    317     }
   323    318   }
   324    319   
   325    320   /*
   326    321   ** The xDisconnect() virtual table method.
   327    322   */
   328    323   static int fts5DisconnectMethod(sqlite3_vtab *pVtab){
   329         -  fts5FreeVtab((Fts5Table*)pVtab);
          324  +  fts5FreeVtab((Fts5FullTable*)pVtab);
   330    325     return SQLITE_OK;
   331    326   }
   332    327   
   333    328   /*
   334    329   ** The xDestroy() virtual table method.
   335    330   */
   336    331   static int fts5DestroyMethod(sqlite3_vtab *pVtab){
   337    332     Fts5Table *pTab = (Fts5Table*)pVtab;
   338    333     int rc = sqlite3Fts5DropAll(pTab->pConfig);
   339    334     if( rc==SQLITE_OK ){
   340         -    fts5FreeVtab((Fts5Table*)pVtab);
          335  +    fts5FreeVtab((Fts5FullTable*)pVtab);
   341    336     }
   342    337     return rc;
   343    338   }
   344    339   
   345    340   /*
   346    341   ** This function is the implementation of both the xConnect and xCreate
   347    342   ** methods of the FTS3 virtual table.
................................................................................
   362    357     sqlite3_vtab **ppVTab,          /* Write the resulting vtab structure here */
   363    358     char **pzErr                    /* Write any error message here */
   364    359   ){
   365    360     Fts5Global *pGlobal = (Fts5Global*)pAux;
   366    361     const char **azConfig = (const char**)argv;
   367    362     int rc = SQLITE_OK;             /* Return code */
   368    363     Fts5Config *pConfig = 0;        /* Results of parsing argc/argv */
   369         -  Fts5Table *pTab = 0;            /* New virtual table object */
          364  +  Fts5FullTable *pTab = 0;        /* New virtual table object */
   370    365   
   371    366     /* Allocate the new vtab object and parse the configuration */
   372         -  pTab = (Fts5Table*)sqlite3Fts5MallocZero(&rc, sizeof(Fts5Table));
          367  +  pTab = (Fts5FullTable*)sqlite3Fts5MallocZero(&rc, sizeof(Fts5FullTable));
   373    368     if( rc==SQLITE_OK ){
   374    369       rc = sqlite3Fts5ConfigParse(pGlobal, db, argc, azConfig, &pConfig, pzErr);
   375    370       assert( (rc==SQLITE_OK && *pzErr==0) || pConfig==0 );
   376    371     }
   377    372     if( rc==SQLITE_OK ){
   378         -    pTab->pConfig = pConfig;
          373  +    pTab->p.pConfig = pConfig;
   379    374       pTab->pGlobal = pGlobal;
   380    375     }
   381    376   
   382    377     /* Open the index sub-system */
   383    378     if( rc==SQLITE_OK ){
   384         -    rc = sqlite3Fts5IndexOpen(pConfig, bCreate, &pTab->pIndex, pzErr);
          379  +    rc = sqlite3Fts5IndexOpen(pConfig, bCreate, &pTab->p.pIndex, pzErr);
   385    380     }
   386    381   
   387    382     /* Open the storage sub-system */
   388    383     if( rc==SQLITE_OK ){
   389    384       rc = sqlite3Fts5StorageOpen(
   390         -        pConfig, pTab->pIndex, bCreate, &pTab->pStorage, pzErr
          385  +        pConfig, pTab->p.pIndex, bCreate, &pTab->pStorage, pzErr
   391    386       );
   392    387     }
   393    388   
   394    389     /* Call sqlite3_declare_vtab() */
   395    390     if( rc==SQLITE_OK ){
   396    391       rc = sqlite3Fts5ConfigDeclareVtab(pConfig);
   397    392     }
   398    393   
   399    394     /* Load the initial configuration */
   400    395     if( rc==SQLITE_OK ){
   401    396       assert( pConfig->pzErrmsg==0 );
   402    397       pConfig->pzErrmsg = pzErr;
   403         -    rc = sqlite3Fts5IndexLoadConfig(pTab->pIndex);
   404         -    sqlite3Fts5IndexRollback(pTab->pIndex);
          398  +    rc = sqlite3Fts5IndexLoadConfig(pTab->p.pIndex);
          399  +    sqlite3Fts5IndexRollback(pTab->p.pIndex);
   405    400       pConfig->pzErrmsg = 0;
   406    401     }
   407    402   
   408    403     if( rc!=SQLITE_OK ){
   409    404       fts5FreeVtab(pTab);
   410    405       pTab = 0;
   411    406     }else if( bCreate ){
................................................................................
   610    605       }
   611    606     }
   612    607   
   613    608     pInfo->idxNum = idxFlags;
   614    609     return SQLITE_OK;
   615    610   }
   616    611   
   617         -static int fts5NewTransaction(Fts5Table *pTab){
          612  +static int fts5NewTransaction(Fts5FullTable *pTab){
   618    613     Fts5Cursor *pCsr;
   619    614     for(pCsr=pTab->pGlobal->pCsr; pCsr; pCsr=pCsr->pNext){
   620    615       if( pCsr->base.pVtab==(sqlite3_vtab*)pTab ) return SQLITE_OK;
   621    616     }
   622    617     return sqlite3Fts5StorageReset(pTab->pStorage);
   623    618   }
   624    619   
   625    620   /*
   626    621   ** Implementation of xOpen method.
   627    622   */
   628    623   static int fts5OpenMethod(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCsr){
   629         -  Fts5Table *pTab = (Fts5Table*)pVTab;
   630         -  Fts5Config *pConfig = pTab->pConfig;
          624  +  Fts5FullTable *pTab = (Fts5FullTable*)pVTab;
          625  +  Fts5Config *pConfig = pTab->p.pConfig;
   631    626     Fts5Cursor *pCsr = 0;           /* New cursor object */
   632         -  int nByte;                      /* Bytes of space to allocate */
          627  +  sqlite3_int64 nByte;            /* Bytes of space to allocate */
   633    628     int rc;                         /* Return code */
   634    629   
   635    630     rc = fts5NewTransaction(pTab);
   636    631     if( rc==SQLITE_OK ){
   637    632       nByte = sizeof(Fts5Cursor) + pConfig->nCol * sizeof(int);
   638         -    pCsr = (Fts5Cursor*)sqlite3_malloc(nByte);
          633  +    pCsr = (Fts5Cursor*)sqlite3_malloc64(nByte);
   639    634       if( pCsr ){
   640    635         Fts5Global *pGlobal = pTab->pGlobal;
   641    636         memset(pCsr, 0, nByte);
   642    637         pCsr->aColumnSize = (int*)&pCsr[1];
   643    638         pCsr->pNext = pGlobal->pCsr;
   644    639         pGlobal->pCsr = pCsr;
   645    640         pCsr->iCsrId = ++pGlobal->iNextId;
................................................................................
   669    664       | FTS5CSR_REQUIRE_DOCSIZE 
   670    665       | FTS5CSR_REQUIRE_INST 
   671    666       | FTS5CSR_REQUIRE_POSLIST 
   672    667     );
   673    668   }
   674    669   
   675    670   static void fts5FreeCursorComponents(Fts5Cursor *pCsr){
   676         -  Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
          671  +  Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
   677    672     Fts5Auxdata *pData;
   678    673     Fts5Auxdata *pNext;
   679    674   
   680    675     sqlite3_free(pCsr->aInstIter);
   681    676     sqlite3_free(pCsr->aInst);
   682    677     if( pCsr->pStmt ){
   683    678       int eStmt = fts5StmtType(pCsr);
................................................................................
   713    708   
   714    709   /*
   715    710   ** Close the cursor.  For additional information see the documentation
   716    711   ** on the xClose method of the virtual table interface.
   717    712   */
   718    713   static int fts5CloseMethod(sqlite3_vtab_cursor *pCursor){
   719    714     if( pCursor ){
   720         -    Fts5Table *pTab = (Fts5Table*)(pCursor->pVtab);
          715  +    Fts5FullTable *pTab = (Fts5FullTable*)(pCursor->pVtab);
   721    716       Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
   722    717       Fts5Cursor **pp;
   723    718   
   724    719       fts5FreeCursorComponents(pCsr);
   725    720       /* Remove the cursor from the Fts5Global.pCsr list */
   726    721       for(pp=&pTab->pGlobal->pCsr; (*pp)!=pCsr; pp=&(*pp)->pNext);
   727    722       *pp = pCsr->pNext;
................................................................................
   770    765   }
   771    766   
   772    767   
   773    768   /*
   774    769   ** Set the FTS5CSR_REQUIRE_RESEEK flag on all FTS5_PLAN_MATCH cursors 
   775    770   ** open on table pTab.
   776    771   */
   777         -static void fts5TripCursors(Fts5Table *pTab){
          772  +static void fts5TripCursors(Fts5FullTable *pTab){
   778    773     Fts5Cursor *pCsr;
   779    774     for(pCsr=pTab->pGlobal->pCsr; pCsr; pCsr=pCsr->pNext){
   780    775       if( pCsr->ePlan==FTS5_PLAN_MATCH
   781    776        && pCsr->base.pVtab==(sqlite3_vtab*)pTab 
   782    777       ){
   783    778         CsrFlagSet(pCsr, FTS5CSR_REQUIRE_RESEEK);
   784    779       }
................................................................................
   797    792   ** Return SQLITE_OK if successful or if no reseek was required, or an 
   798    793   ** error code if an error occurred.
   799    794   */
   800    795   static int fts5CursorReseek(Fts5Cursor *pCsr, int *pbSkip){
   801    796     int rc = SQLITE_OK;
   802    797     assert( *pbSkip==0 );
   803    798     if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_RESEEK) ){
   804         -    Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
          799  +    Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
   805    800       int bDesc = pCsr->bDesc;
   806    801       i64 iRowid = sqlite3Fts5ExprRowid(pCsr->pExpr);
   807    802   
   808         -    rc = sqlite3Fts5ExprFirst(pCsr->pExpr, pTab->pIndex, iRowid, bDesc);
          803  +    rc = sqlite3Fts5ExprFirst(pCsr->pExpr, pTab->p.pIndex, iRowid, bDesc);
   809    804       if( rc==SQLITE_OK &&  iRowid!=sqlite3Fts5ExprRowid(pCsr->pExpr) ){
   810    805         *pbSkip = 1;
   811    806       }
   812    807   
   813    808       CsrFlagClear(pCsr, FTS5CSR_REQUIRE_RESEEK);
   814    809       fts5CsrNewrow(pCsr);
   815    810       if( sqlite3Fts5ExprEof(pCsr->pExpr) ){
................................................................................
   898    893     }
   899    894   
   900    895     va_end(ap);
   901    896     *ppStmt = pRet;
   902    897     return rc;
   903    898   } 
   904    899   
   905         -static int fts5CursorFirstSorted(Fts5Table *pTab, Fts5Cursor *pCsr, int bDesc){
   906         -  Fts5Config *pConfig = pTab->pConfig;
          900  +static int fts5CursorFirstSorted(
          901  +  Fts5FullTable *pTab, 
          902  +  Fts5Cursor *pCsr, 
          903  +  int bDesc
          904  +){
          905  +  Fts5Config *pConfig = pTab->p.pConfig;
   907    906     Fts5Sorter *pSorter;
   908    907     int nPhrase;
   909         -  int nByte;
          908  +  sqlite3_int64 nByte;
   910    909     int rc;
   911    910     const char *zRank = pCsr->zRank;
   912    911     const char *zRankArgs = pCsr->zRankArgs;
   913    912     
   914    913     nPhrase = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
   915    914     nByte = sizeof(Fts5Sorter) + sizeof(int) * (nPhrase-1);
   916         -  pSorter = (Fts5Sorter*)sqlite3_malloc(nByte);
          915  +  pSorter = (Fts5Sorter*)sqlite3_malloc64(nByte);
   917    916     if( pSorter==0 ) return SQLITE_NOMEM;
   918    917     memset(pSorter, 0, nByte);
   919    918     pSorter->nIdx = nPhrase;
   920    919   
   921    920     /* TODO: It would be better to have some system for reusing statement
   922    921     ** handles here, rather than preparing a new one for each query. But that
   923    922     ** is not possible as SQLite reference counts the virtual table objects.
................................................................................
   946    945       sqlite3_free(pSorter);
   947    946       pCsr->pSorter = 0;
   948    947     }
   949    948   
   950    949     return rc;
   951    950   }
   952    951   
   953         -static int fts5CursorFirst(Fts5Table *pTab, Fts5Cursor *pCsr, int bDesc){
          952  +static int fts5CursorFirst(Fts5FullTable *pTab, Fts5Cursor *pCsr, int bDesc){
   954    953     int rc;
   955    954     Fts5Expr *pExpr = pCsr->pExpr;
   956         -  rc = sqlite3Fts5ExprFirst(pExpr, pTab->pIndex, pCsr->iFirstRowid, bDesc);
          955  +  rc = sqlite3Fts5ExprFirst(pExpr, pTab->p.pIndex, pCsr->iFirstRowid, bDesc);
   957    956     if( sqlite3Fts5ExprEof(pExpr) ){
   958    957       CsrFlagSet(pCsr, FTS5CSR_EOF);
   959    958     }
   960    959     fts5CsrNewrow(pCsr);
   961    960     return rc;
   962    961   }
   963    962   
................................................................................
   964    963   /*
   965    964   ** Process a "special" query. A special query is identified as one with a
   966    965   ** MATCH expression that begins with a '*' character. The remainder of
   967    966   ** the text passed to the MATCH operator are used as  the special query
   968    967   ** parameters.
   969    968   */
   970    969   static int fts5SpecialMatch(
   971         -  Fts5Table *pTab, 
          970  +  Fts5FullTable *pTab, 
   972    971     Fts5Cursor *pCsr, 
   973    972     const char *zQuery
   974    973   ){
   975    974     int rc = SQLITE_OK;             /* Return code */
   976    975     const char *z = zQuery;         /* Special query text */
   977    976     int n;                          /* Number of bytes in text at z */
   978    977   
   979    978     while( z[0]==' ' ) z++;
   980    979     for(n=0; z[n] && z[n]!=' '; n++);
   981    980   
   982         -  assert( pTab->base.zErrMsg==0 );
          981  +  assert( pTab->p.base.zErrMsg==0 );
   983    982     pCsr->ePlan = FTS5_PLAN_SPECIAL;
   984    983   
   985    984     if( 0==sqlite3_strnicmp("reads", z, n) ){
   986         -    pCsr->iSpecial = sqlite3Fts5IndexReads(pTab->pIndex);
          985  +    pCsr->iSpecial = sqlite3Fts5IndexReads(pTab->p.pIndex);
   987    986     }
   988    987     else if( 0==sqlite3_strnicmp("id", z, n) ){
   989    988       pCsr->iSpecial = pCsr->iCsrId;
   990    989     }
   991    990     else{
   992    991       /* An unrecognized directive. Return an error message. */
   993         -    pTab->base.zErrMsg = sqlite3_mprintf("unknown special query: %.*s", n, z);
          992  +    pTab->p.base.zErrMsg = sqlite3_mprintf("unknown special query: %.*s", n, z);
   994    993       rc = SQLITE_ERROR;
   995    994     }
   996    995   
   997    996     return rc;
   998    997   }
   999    998   
  1000    999   /*
  1001   1000   ** Search for an auxiliary function named zName that can be used with table
  1002   1001   ** pTab. If one is found, return a pointer to the corresponding Fts5Auxiliary
  1003   1002   ** structure. Otherwise, if no such function exists, return NULL.
  1004   1003   */
  1005         -static Fts5Auxiliary *fts5FindAuxiliary(Fts5Table *pTab, const char *zName){
         1004  +static Fts5Auxiliary *fts5FindAuxiliary(Fts5FullTable *pTab, const char *zName){
  1006   1005     Fts5Auxiliary *pAux;
  1007   1006   
  1008   1007     for(pAux=pTab->pGlobal->pAux; pAux; pAux=pAux->pNext){
  1009   1008       if( sqlite3_stricmp(zName, pAux->zFunc)==0 ) return pAux;
  1010   1009     }
  1011   1010   
  1012   1011     /* No function of the specified name was found. Return 0. */
  1013   1012     return 0;
  1014   1013   }
  1015   1014   
  1016   1015   
  1017   1016   static int fts5FindRankFunction(Fts5Cursor *pCsr){
  1018         -  Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
  1019         -  Fts5Config *pConfig = pTab->pConfig;
         1017  +  Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
         1018  +  Fts5Config *pConfig = pTab->p.pConfig;
  1020   1019     int rc = SQLITE_OK;
  1021   1020     Fts5Auxiliary *pAux = 0;
  1022   1021     const char *zRank = pCsr->zRank;
  1023   1022     const char *zRankArgs = pCsr->zRankArgs;
  1024   1023   
  1025   1024     if( zRankArgs ){
  1026   1025       char *zSql = sqlite3Fts5Mprintf(&rc, "SELECT %s", zRankArgs);
................................................................................
  1028   1027         sqlite3_stmt *pStmt = 0;
  1029   1028         rc = sqlite3_prepare_v3(pConfig->db, zSql, -1,
  1030   1029                                 SQLITE_PREPARE_PERSISTENT, &pStmt, 0);
  1031   1030         sqlite3_free(zSql);
  1032   1031         assert( rc==SQLITE_OK || pCsr->pRankArgStmt==0 );
  1033   1032         if( rc==SQLITE_OK ){
  1034   1033           if( SQLITE_ROW==sqlite3_step(pStmt) ){
  1035         -          int nByte;
         1034  +          sqlite3_int64 nByte;
  1036   1035             pCsr->nRankArg = sqlite3_column_count(pStmt);
  1037   1036             nByte = sizeof(sqlite3_value*)*pCsr->nRankArg;
  1038   1037             pCsr->apRankArg = (sqlite3_value**)sqlite3Fts5MallocZero(&rc, nByte);
  1039   1038             if( rc==SQLITE_OK ){
  1040   1039               int i;
  1041   1040               for(i=0; i<pCsr->nRankArg; i++){
  1042   1041                 pCsr->apRankArg[i] = sqlite3_column_value(pStmt, i);
................................................................................
  1050   1049         }
  1051   1050       }
  1052   1051     }
  1053   1052   
  1054   1053     if( rc==SQLITE_OK ){
  1055   1054       pAux = fts5FindAuxiliary(pTab, zRank);
  1056   1055       if( pAux==0 ){
  1057         -      assert( pTab->base.zErrMsg==0 );
  1058         -      pTab->base.zErrMsg = sqlite3_mprintf("no such function: %s", zRank);
         1056  +      assert( pTab->p.base.zErrMsg==0 );
         1057  +      pTab->p.base.zErrMsg = sqlite3_mprintf("no such function: %s", zRank);
  1059   1058         rc = SQLITE_ERROR;
  1060   1059       }
  1061   1060     }
  1062   1061   
  1063   1062     pCsr->pRank = pAux;
  1064   1063     return rc;
  1065   1064   }
................................................................................
  1126   1125   static int fts5FilterMethod(
  1127   1126     sqlite3_vtab_cursor *pCursor,   /* The cursor used for this query */
  1128   1127     int idxNum,                     /* Strategy index */
  1129   1128     const char *zUnused,            /* Unused */
  1130   1129     int nVal,                       /* Number of elements in apVal */
  1131   1130     sqlite3_value **apVal           /* Arguments for the indexing scheme */
  1132   1131   ){
  1133         -  Fts5Table *pTab = (Fts5Table*)(pCursor->pVtab);
  1134         -  Fts5Config *pConfig = pTab->pConfig;
         1132  +  Fts5FullTable *pTab = (Fts5FullTable*)(pCursor->pVtab);
         1133  +  Fts5Config *pConfig = pTab->p.pConfig;
  1135   1134     Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
  1136   1135     int rc = SQLITE_OK;             /* Error code */
  1137   1136     int iVal = 0;                   /* Counter for apVal[] */
  1138   1137     int bDesc;                      /* True if ORDER BY [rank|rowid] DESC */
  1139   1138     int bOrderByRank;               /* True if ORDER BY rank */
  1140   1139     sqlite3_value *pMatch = 0;      /* <tbl> MATCH ? expression (or NULL) */
  1141   1140     sqlite3_value *pRank = 0;       /* rank MATCH ? expression (or NULL) */
................................................................................
  1156   1155     assert( pCsr->pStmt==0 );
  1157   1156     assert( pCsr->pExpr==0 );
  1158   1157     assert( pCsr->csrflags==0 );
  1159   1158     assert( pCsr->pRank==0 );
  1160   1159     assert( pCsr->zRank==0 );
  1161   1160     assert( pCsr->zRankArgs==0 );
  1162   1161   
  1163         -  assert( pzErrmsg==0 || pzErrmsg==&pTab->base.zErrMsg );
  1164         -  pConfig->pzErrmsg = &pTab->base.zErrMsg;
         1162  +  assert( pzErrmsg==0 || pzErrmsg==&pTab->p.base.zErrMsg );
         1163  +  pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
  1165   1164   
  1166   1165     /* Decode the arguments passed through to this function.
  1167   1166     **
  1168   1167     ** Note: The following set of if(...) statements must be in the same
  1169   1168     ** order as the corresponding entries in the struct at the top of
  1170   1169     ** fts5BestIndexMethod().  */
  1171   1170     if( BitFlagTest(idxNum, FTS5_BI_MATCH) ) pMatch = apVal[iVal++];
................................................................................
  1223   1222       if( rc==SQLITE_OK ){
  1224   1223         if( zExpr[0]=='*' ){
  1225   1224           /* The user has issued a query of the form "MATCH '*...'". This
  1226   1225           ** indicates that the MATCH expression is not a full text query,
  1227   1226           ** but a request for an internal parameter.  */
  1228   1227           rc = fts5SpecialMatch(pTab, pCsr, &zExpr[1]);
  1229   1228         }else{
  1230         -        char **pzErr = &pTab->base.zErrMsg;
         1229  +        char **pzErr = &pTab->p.base.zErrMsg;
  1231   1230           rc = sqlite3Fts5ExprNew(pConfig, iCol, zExpr, &pCsr->pExpr, pzErr);
  1232   1231           if( rc==SQLITE_OK ){
  1233   1232             if( bOrderByRank ){
  1234   1233               pCsr->ePlan = FTS5_PLAN_SORTED_MATCH;
  1235   1234               rc = fts5CursorFirstSorted(pTab, pCsr, bDesc);
  1236   1235             }else{
  1237   1236               pCsr->ePlan = FTS5_PLAN_MATCH;
................................................................................
  1246   1245       );
  1247   1246       rc = SQLITE_ERROR;
  1248   1247     }else{
  1249   1248       /* This is either a full-table scan (ePlan==FTS5_PLAN_SCAN) or a lookup
  1250   1249       ** by rowid (ePlan==FTS5_PLAN_ROWID).  */
  1251   1250       pCsr->ePlan = (pRowidEq ? FTS5_PLAN_ROWID : FTS5_PLAN_SCAN);
  1252   1251       rc = sqlite3Fts5StorageStmt(
  1253         -        pTab->pStorage, fts5StmtType(pCsr), &pCsr->pStmt, &pTab->base.zErrMsg
         1252  +        pTab->pStorage, fts5StmtType(pCsr), &pCsr->pStmt, &pTab->p.base.zErrMsg
  1254   1253       );
  1255   1254       if( rc==SQLITE_OK ){
  1256   1255         if( pCsr->ePlan==FTS5_PLAN_ROWID ){
  1257   1256           sqlite3_bind_value(pCsr->pStmt, 1, apVal[0]);
  1258   1257         }else{
  1259   1258           sqlite3_bind_int64(pCsr->pStmt, 1, pCsr->iFirstRowid);
  1260   1259           sqlite3_bind_int64(pCsr->pStmt, 2, pCsr->iLastRowid);
................................................................................
  1329   1328   ** be left in sqlite3_vtab.zErrMsg.
  1330   1329   */
  1331   1330   static int fts5SeekCursor(Fts5Cursor *pCsr, int bErrormsg){
  1332   1331     int rc = SQLITE_OK;
  1333   1332   
  1334   1333     /* If the cursor does not yet have a statement handle, obtain one now. */ 
  1335   1334     if( pCsr->pStmt==0 ){
  1336         -    Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
         1335  +    Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
  1337   1336       int eStmt = fts5StmtType(pCsr);
  1338   1337       rc = sqlite3Fts5StorageStmt(
  1339         -        pTab->pStorage, eStmt, &pCsr->pStmt, (bErrormsg?&pTab->base.zErrMsg:0)
         1338  +        pTab->pStorage, eStmt, &pCsr->pStmt, (bErrormsg?&pTab->p.base.zErrMsg:0)
  1340   1339       );
  1341         -    assert( rc!=SQLITE_OK || pTab->base.zErrMsg==0 );
         1340  +    assert( rc!=SQLITE_OK || pTab->p.base.zErrMsg==0 );
  1342   1341       assert( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_CONTENT) );
  1343   1342     }
  1344   1343   
  1345   1344     if( rc==SQLITE_OK && CsrFlagTest(pCsr, FTS5CSR_REQUIRE_CONTENT) ){
  1346   1345       assert( pCsr->pExpr );
  1347   1346       sqlite3_reset(pCsr->pStmt);
  1348   1347       sqlite3_bind_int64(pCsr->pStmt, 1, fts5CursorRowid(pCsr));
................................................................................
  1356   1355           rc = FTS5_CORRUPT;
  1357   1356         }
  1358   1357       }
  1359   1358     }
  1360   1359     return rc;
  1361   1360   }
  1362   1361   
  1363         -static void fts5SetVtabError(Fts5Table *p, const char *zFormat, ...){
         1362  +static void fts5SetVtabError(Fts5FullTable *p, const char *zFormat, ...){
  1364   1363     va_list ap;                     /* ... printf arguments */
  1365   1364     va_start(ap, zFormat);
  1366         -  assert( p->base.zErrMsg==0 );
  1367         -  p->base.zErrMsg = sqlite3_vmprintf(zFormat, ap);
         1365  +  assert( p->p.base.zErrMsg==0 );
         1366  +  p->p.base.zErrMsg = sqlite3_vmprintf(zFormat, ap);
  1368   1367     va_end(ap);
  1369   1368   }
  1370   1369   
  1371   1370   /*
  1372   1371   ** This function is called to handle an FTS INSERT command. In other words,
  1373   1372   ** an INSERT statement of the form:
  1374   1373   **
................................................................................
  1380   1379   ** error code if an error occurs.
  1381   1380   **
  1382   1381   ** The commands implemented by this function are documented in the "Special
  1383   1382   ** INSERT Directives" section of the documentation. It should be updated if
  1384   1383   ** more commands are added to this function.
  1385   1384   */
  1386   1385   static int fts5SpecialInsert(
  1387         -  Fts5Table *pTab,                /* Fts5 table object */
         1386  +  Fts5FullTable *pTab,            /* Fts5 table object */
  1388   1387     const char *zCmd,               /* Text inserted into table-name column */
  1389   1388     sqlite3_value *pVal             /* Value inserted into rank column */
  1390   1389   ){
  1391         -  Fts5Config *pConfig = pTab->pConfig;
         1390  +  Fts5Config *pConfig = pTab->p.pConfig;
  1392   1391     int rc = SQLITE_OK;
  1393   1392     int bError = 0;
  1394   1393   
  1395   1394     if( 0==sqlite3_stricmp("delete-all", zCmd) ){
  1396   1395       if( pConfig->eContent==FTS5_CONTENT_NORMAL ){
  1397   1396         fts5SetVtabError(pTab, 
  1398   1397             "'delete-all' may only be used with a "
................................................................................
  1419   1418     }else if( 0==sqlite3_stricmp("integrity-check", zCmd) ){
  1420   1419       rc = sqlite3Fts5StorageIntegrity(pTab->pStorage);
  1421   1420   #ifdef SQLITE_DEBUG
  1422   1421     }else if( 0==sqlite3_stricmp("prefix-index", zCmd) ){
  1423   1422       pConfig->bPrefixIndex = sqlite3_value_int(pVal);
  1424   1423   #endif
  1425   1424     }else{
  1426         -    rc = sqlite3Fts5IndexLoadConfig(pTab->pIndex);
         1425  +    rc = sqlite3Fts5IndexLoadConfig(pTab->p.pIndex);
  1427   1426       if( rc==SQLITE_OK ){
  1428         -      rc = sqlite3Fts5ConfigSetValue(pTab->pConfig, zCmd, pVal, &bError);
         1427  +      rc = sqlite3Fts5ConfigSetValue(pTab->p.pConfig, zCmd, pVal, &bError);
  1429   1428       }
  1430   1429       if( rc==SQLITE_OK ){
  1431   1430         if( bError ){
  1432   1431           rc = SQLITE_ERROR;
  1433   1432         }else{
  1434   1433           rc = sqlite3Fts5StorageConfigValue(pTab->pStorage, zCmd, pVal, 0);
  1435   1434         }
  1436   1435       }
  1437   1436     }
  1438   1437     return rc;
  1439   1438   }
  1440   1439   
  1441   1440   static int fts5SpecialDelete(
  1442         -  Fts5Table *pTab, 
         1441  +  Fts5FullTable *pTab, 
  1443   1442     sqlite3_value **apVal
  1444   1443   ){
  1445   1444     int rc = SQLITE_OK;
  1446   1445     int eType1 = sqlite3_value_type(apVal[1]);
  1447   1446     if( eType1==SQLITE_INTEGER ){
  1448   1447       sqlite3_int64 iDel = sqlite3_value_int64(apVal[1]);
  1449   1448       rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, &apVal[2]);
  1450   1449     }
  1451   1450     return rc;
  1452   1451   }
  1453   1452   
  1454   1453   static void fts5StorageInsert(
  1455   1454     int *pRc, 
  1456         -  Fts5Table *pTab, 
         1455  +  Fts5FullTable *pTab, 
  1457   1456     sqlite3_value **apVal, 
  1458   1457     i64 *piRowid
  1459   1458   ){
  1460   1459     int rc = *pRc;
  1461   1460     if( rc==SQLITE_OK ){
  1462   1461       rc = sqlite3Fts5StorageContentInsert(pTab->pStorage, apVal, piRowid);
  1463   1462     }
................................................................................
  1483   1482   */
  1484   1483   static int fts5UpdateMethod(
  1485   1484     sqlite3_vtab *pVtab,            /* Virtual table handle */
  1486   1485     int nArg,                       /* Size of argument array */
  1487   1486     sqlite3_value **apVal,          /* Array of arguments */
  1488   1487     sqlite_int64 *pRowid            /* OUT: The affected (or effected) rowid */
  1489   1488   ){
  1490         -  Fts5Table *pTab = (Fts5Table*)pVtab;
  1491         -  Fts5Config *pConfig = pTab->pConfig;
         1489  +  Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
         1490  +  Fts5Config *pConfig = pTab->p.pConfig;
  1492   1491     int eType0;                     /* value_type() of apVal[0] */
  1493   1492     int rc = SQLITE_OK;             /* Return code */
  1494   1493   
  1495   1494     /* A transaction must be open when this is called. */
  1496   1495     assert( pTab->ts.eState==1 );
  1497   1496   
  1498   1497     assert( pVtab->zErrMsg==0 );
  1499   1498     assert( nArg==1 || nArg==(2+pConfig->nCol+2) );
  1500         -  assert( nArg==1 
  1501         -      || sqlite3_value_type(apVal[1])==SQLITE_INTEGER 
  1502         -      || sqlite3_value_type(apVal[1])==SQLITE_NULL 
         1499  +  assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER 
         1500  +       || sqlite3_value_type(apVal[0])==SQLITE_NULL 
  1503   1501     );
  1504         -  assert( pTab->pConfig->pzErrmsg==0 );
  1505         -  pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg;
         1502  +  assert( pTab->p.pConfig->pzErrmsg==0 );
         1503  +  pTab->p.pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
  1506   1504   
  1507   1505     /* Put any active cursors into REQUIRE_SEEK state. */
  1508   1506     fts5TripCursors(pTab);
  1509   1507   
  1510   1508     eType0 = sqlite3_value_type(apVal[0]);
  1511   1509     if( eType0==SQLITE_NULL 
  1512   1510      && sqlite3_value_type(apVal[2+pConfig->nCol])!=SQLITE_NULL 
................................................................................
  1539   1537   
  1540   1538       assert( eType0==SQLITE_INTEGER || eType0==SQLITE_NULL );
  1541   1539       assert( nArg!=1 || eType0==SQLITE_INTEGER );
  1542   1540   
  1543   1541       /* Filter out attempts to run UPDATE or DELETE on contentless tables.
  1544   1542       ** This is not suported.  */
  1545   1543       if( eType0==SQLITE_INTEGER && fts5IsContentless(pTab) ){
  1546         -      pTab->base.zErrMsg = sqlite3_mprintf(
         1544  +      pTab->p.base.zErrMsg = sqlite3_mprintf(
  1547   1545             "cannot %s contentless fts5 table: %s", 
  1548   1546             (nArg>1 ? "UPDATE" : "DELETE from"), pConfig->zName
  1549   1547         );
  1550   1548         rc = SQLITE_ERROR;
  1551   1549       }
  1552   1550   
  1553   1551       /* DELETE */
  1554   1552       else if( nArg==1 ){
  1555   1553         i64 iDel = sqlite3_value_int64(apVal[0]);  /* Rowid to delete */
  1556   1554         rc = sqlite3Fts5StorageDelete(pTab->pStorage, iDel, 0);
  1557   1555       }
  1558   1556   
  1559         -    /* INSERT */
  1560         -    else if( eType0!=SQLITE_INTEGER ){     
  1561         -      /* If this is a REPLACE, first remove the current entry (if any) */
  1562         -      if( eConflict==SQLITE_REPLACE 
  1563         -       && sqlite3_value_type(apVal[1])==SQLITE_INTEGER 
  1564         -      ){
  1565         -        i64 iNew = sqlite3_value_int64(apVal[1]);  /* Rowid to delete */
  1566         -        rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
  1567         -      }
  1568         -      fts5StorageInsert(&rc, pTab, apVal, pRowid);
  1569         -    }
  1570         -
  1571         -    /* UPDATE */
         1557  +    /* INSERT or UPDATE */
  1572   1558       else{
  1573         -      i64 iOld = sqlite3_value_int64(apVal[0]);  /* Old rowid */
  1574         -      i64 iNew = sqlite3_value_int64(apVal[1]);  /* New rowid */
  1575         -      if( iOld!=iNew ){
  1576         -        if( eConflict==SQLITE_REPLACE ){
  1577         -          rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
  1578         -          if( rc==SQLITE_OK ){
  1579         -            rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
  1580         -          }
  1581         -          fts5StorageInsert(&rc, pTab, apVal, pRowid);
  1582         -        }else{
  1583         -          rc = sqlite3Fts5StorageContentInsert(pTab->pStorage, apVal, pRowid);
  1584         -          if( rc==SQLITE_OK ){
  1585         -            rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
  1586         -          }
  1587         -          if( rc==SQLITE_OK ){
  1588         -            rc = sqlite3Fts5StorageIndexInsert(pTab->pStorage, apVal, *pRowid);
  1589         -          }
         1559  +      int eType1 = sqlite3_value_numeric_type(apVal[1]);
         1560  +
         1561  +      if( eType1!=SQLITE_INTEGER && eType1!=SQLITE_NULL ){
         1562  +        rc = SQLITE_MISMATCH;
         1563  +      }
         1564  +
         1565  +      else if( eType0!=SQLITE_INTEGER ){     
         1566  +        /* If this is a REPLACE, first remove the current entry (if any) */
         1567  +        if( eConflict==SQLITE_REPLACE && eType1==SQLITE_INTEGER ){
         1568  +          i64 iNew = sqlite3_value_int64(apVal[1]);  /* Rowid to delete */
         1569  +          rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
  1590   1570           }
  1591         -      }else{
  1592         -        rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
  1593   1571           fts5StorageInsert(&rc, pTab, apVal, pRowid);
  1594   1572         }
         1573  +
         1574  +      /* UPDATE */
         1575  +      else{
         1576  +        i64 iOld = sqlite3_value_int64(apVal[0]);  /* Old rowid */
         1577  +        i64 iNew = sqlite3_value_int64(apVal[1]);  /* New rowid */
         1578  +        if( eType1==SQLITE_INTEGER && iOld!=iNew ){
         1579  +          if( eConflict==SQLITE_REPLACE ){
         1580  +            rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
         1581  +            if( rc==SQLITE_OK ){
         1582  +              rc = sqlite3Fts5StorageDelete(pTab->pStorage, iNew, 0);
         1583  +            }
         1584  +            fts5StorageInsert(&rc, pTab, apVal, pRowid);
         1585  +          }else{
         1586  +            rc = sqlite3Fts5StorageContentInsert(pTab->pStorage, apVal, pRowid);
         1587  +            if( rc==SQLITE_OK ){
         1588  +              rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
         1589  +            }
         1590  +            if( rc==SQLITE_OK ){
         1591  +              rc = sqlite3Fts5StorageIndexInsert(pTab->pStorage, apVal,*pRowid);
         1592  +            }
         1593  +          }
         1594  +        }else{
         1595  +          rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
         1596  +          fts5StorageInsert(&rc, pTab, apVal, pRowid);
         1597  +        }
         1598  +      }
  1595   1599       }
  1596   1600     }
  1597   1601   
  1598         -  pTab->pConfig->pzErrmsg = 0;
         1602  +  pTab->p.pConfig->pzErrmsg = 0;
  1599   1603     return rc;
  1600   1604   }
  1601   1605   
  1602   1606   /*
  1603   1607   ** Implementation of xSync() method. 
  1604   1608   */
  1605   1609   static int fts5SyncMethod(sqlite3_vtab *pVtab){
  1606   1610     int rc;
  1607         -  Fts5Table *pTab = (Fts5Table*)pVtab;
         1611  +  Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
  1608   1612     fts5CheckTransactionState(pTab, FTS5_SYNC, 0);
  1609         -  pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg;
         1613  +  pTab->p.pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
  1610   1614     fts5TripCursors(pTab);
  1611   1615     rc = sqlite3Fts5StorageSync(pTab->pStorage);
  1612         -  pTab->pConfig->pzErrmsg = 0;
         1616  +  pTab->p.pConfig->pzErrmsg = 0;
  1613   1617     return rc;
  1614   1618   }
  1615   1619   
  1616   1620   /*
  1617   1621   ** Implementation of xBegin() method. 
  1618   1622   */
  1619   1623   static int fts5BeginMethod(sqlite3_vtab *pVtab){
  1620         -  fts5CheckTransactionState((Fts5Table*)pVtab, FTS5_BEGIN, 0);
  1621         -  fts5NewTransaction((Fts5Table*)pVtab);
         1624  +  fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_BEGIN, 0);
         1625  +  fts5NewTransaction((Fts5FullTable*)pVtab);
  1622   1626     return SQLITE_OK;
  1623   1627   }
  1624   1628   
  1625   1629   /*
  1626   1630   ** Implementation of xCommit() method. This is a no-op. The contents of
  1627   1631   ** the pending-terms hash-table have already been flushed into the database
  1628   1632   ** by fts5SyncMethod().
  1629   1633   */
  1630   1634   static int fts5CommitMethod(sqlite3_vtab *pVtab){
  1631   1635     UNUSED_PARAM(pVtab);  /* Call below is a no-op for NDEBUG builds */
  1632         -  fts5CheckTransactionState((Fts5Table*)pVtab, FTS5_COMMIT, 0);
         1636  +  fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_COMMIT, 0);
  1633   1637     return SQLITE_OK;
  1634   1638   }
  1635   1639   
  1636   1640   /*
  1637   1641   ** Implementation of xRollback(). Discard the contents of the pending-terms
  1638   1642   ** hash-table. Any changes made to the database are reverted by SQLite.
  1639   1643   */
  1640   1644   static int fts5RollbackMethod(sqlite3_vtab *pVtab){
  1641   1645     int rc;
  1642         -  Fts5Table *pTab = (Fts5Table*)pVtab;
         1646  +  Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
  1643   1647     fts5CheckTransactionState(pTab, FTS5_ROLLBACK, 0);
  1644   1648     rc = sqlite3Fts5StorageRollback(pTab->pStorage);
  1645   1649     return rc;
  1646   1650   }
  1647   1651   
  1648   1652   static int fts5CsrPoslist(Fts5Cursor*, int, const u8**, int*);
  1649   1653   
................................................................................
  1659   1663   
  1660   1664   static int fts5ApiColumnTotalSize(
  1661   1665     Fts5Context *pCtx, 
  1662   1666     int iCol, 
  1663   1667     sqlite3_int64 *pnToken
  1664   1668   ){
  1665   1669     Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
  1666         -  Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
         1670  +  Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
  1667   1671     return sqlite3Fts5StorageSize(pTab->pStorage, iCol, pnToken);
  1668   1672   }
  1669   1673   
  1670   1674   static int fts5ApiRowCount(Fts5Context *pCtx, i64 *pnRow){
  1671   1675     Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
  1672         -  Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
         1676  +  Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
  1673   1677     return sqlite3Fts5StorageRowCount(pTab->pStorage, pnRow);
  1674   1678   }
  1675   1679   
  1676   1680   static int fts5ApiTokenize(
  1677   1681     Fts5Context *pCtx, 
  1678   1682     const char *pText, int nText, 
  1679   1683     void *pUserData,
................................................................................
  1700   1704     Fts5Context *pCtx, 
  1701   1705     int iCol, 
  1702   1706     const char **pz, 
  1703   1707     int *pn
  1704   1708   ){
  1705   1709     int rc = SQLITE_OK;
  1706   1710     Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
  1707         -  if( fts5IsContentless((Fts5Table*)(pCsr->base.pVtab)) ){
         1711  +  if( fts5IsContentless((Fts5FullTable*)(pCsr->base.pVtab)) 
         1712  +   || pCsr->ePlan==FTS5_PLAN_SPECIAL 
         1713  +  ){
  1708   1714       *pz = 0;
  1709   1715       *pn = 0;
  1710   1716     }else{
  1711   1717       rc = fts5SeekCursor(pCsr, 0);
  1712   1718       if( rc==SQLITE_OK ){
  1713   1719         *pz = (const char*)sqlite3_column_text(pCsr->pStmt, iCol+1);
  1714   1720         *pn = sqlite3_column_bytes(pCsr->pStmt, iCol+1);
................................................................................
  1769   1775   ** correctly for the current view. Return SQLITE_OK if successful, or an
  1770   1776   ** SQLite error code otherwise.
  1771   1777   */
  1772   1778   static int fts5CacheInstArray(Fts5Cursor *pCsr){
  1773   1779     int rc = SQLITE_OK;
  1774   1780     Fts5PoslistReader *aIter;       /* One iterator for each phrase */
  1775   1781     int nIter;                      /* Number of iterators/phrases */
         1782  +  int nCol = ((Fts5Table*)pCsr->base.pVtab)->pConfig->nCol;
  1776   1783     
  1777   1784     nIter = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
  1778   1785     if( pCsr->aInstIter==0 ){
  1779         -    int nByte = sizeof(Fts5PoslistReader) * nIter;
         1786  +    sqlite3_int64 nByte = sizeof(Fts5PoslistReader) * nIter;
  1780   1787       pCsr->aInstIter = (Fts5PoslistReader*)sqlite3Fts5MallocZero(&rc, nByte);
  1781   1788     }
  1782   1789     aIter = pCsr->aInstIter;
  1783   1790   
  1784   1791     if( aIter ){
  1785   1792       int nInst = 0;                /* Number instances seen so far */
  1786   1793       int i;
................................................................................
  1807   1814             }
  1808   1815           }
  1809   1816           if( iBest<0 ) break;
  1810   1817   
  1811   1818           nInst++;
  1812   1819           if( nInst>=pCsr->nInstAlloc ){
  1813   1820             pCsr->nInstAlloc = pCsr->nInstAlloc ? pCsr->nInstAlloc*2 : 32;
  1814         -          aInst = (int*)sqlite3_realloc(
         1821  +          aInst = (int*)sqlite3_realloc64(
  1815   1822                 pCsr->aInst, pCsr->nInstAlloc*sizeof(int)*3
  1816   1823                 );
  1817   1824             if( aInst ){
  1818   1825               pCsr->aInst = aInst;
  1819   1826             }else{
  1820   1827               rc = SQLITE_NOMEM;
  1821   1828               break;
................................................................................
  1822   1829             }
  1823   1830           }
  1824   1831   
  1825   1832           aInst = &pCsr->aInst[3 * (nInst-1)];
  1826   1833           aInst[0] = iBest;
  1827   1834           aInst[1] = FTS5_POS2COLUMN(aIter[iBest].iPos);
  1828   1835           aInst[2] = FTS5_POS2OFFSET(aIter[iBest].iPos);
         1836  +        if( aInst[1]<0 || aInst[1]>=nCol ){
         1837  +          rc = FTS5_CORRUPT;
         1838  +          break;
         1839  +        }
  1829   1840           sqlite3Fts5PoslistReaderNext(&aIter[iBest]);
  1830   1841         }
  1831   1842       }
  1832   1843   
  1833   1844       pCsr->nInstCount = nInst;
  1834   1845       CsrFlagClear(pCsr, FTS5CSR_REQUIRE_INST);
  1835   1846     }
................................................................................
  1894   1905       (*pCnt)++;
  1895   1906     }
  1896   1907     return SQLITE_OK;
  1897   1908   }
  1898   1909   
  1899   1910   static int fts5ApiColumnSize(Fts5Context *pCtx, int iCol, int *pnToken){
  1900   1911     Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
  1901         -  Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
  1902         -  Fts5Config *pConfig = pTab->pConfig;
         1912  +  Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
         1913  +  Fts5Config *pConfig = pTab->p.pConfig;
  1903   1914     int rc = SQLITE_OK;
  1904   1915   
  1905   1916     if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_DOCSIZE) ){
  1906   1917       if( pConfig->bColumnsize ){
  1907   1918         i64 iRowid = fts5CursorRowid(pCsr);
  1908   1919         rc = sqlite3Fts5StorageDocsize(pTab->pStorage, iRowid, pCsr->aColumnSize);
  1909   1920       }else if( pConfig->zContent==0 ){
................................................................................
  2151   2162   static int fts5ApiQueryPhrase(
  2152   2163     Fts5Context *pCtx, 
  2153   2164     int iPhrase, 
  2154   2165     void *pUserData,
  2155   2166     int(*xCallback)(const Fts5ExtensionApi*, Fts5Context*, void*)
  2156   2167   ){
  2157   2168     Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
  2158         -  Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
         2169  +  Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
  2159   2170     int rc;
  2160   2171     Fts5Cursor *pNew = 0;
  2161   2172   
  2162   2173     rc = fts5OpenMethod(pCsr->base.pVtab, (sqlite3_vtab_cursor**)&pNew);
  2163   2174     if( rc==SQLITE_OK ){
  2164   2175       pNew->ePlan = FTS5_PLAN_MATCH;
  2165   2176       pNew->iFirstRowid = SMALLEST_INT64;
................................................................................
  2228   2239     }else{
  2229   2240       fts5ApiInvoke(pAux, pCsr, context, argc-1, &argv[1]);
  2230   2241     }
  2231   2242   }
  2232   2243   
  2233   2244   
  2234   2245   /*
  2235         -** Given cursor id iId, return a pointer to the corresponding Fts5Index 
         2246  +** Given cursor id iId, return a pointer to the corresponding Fts5Table 
  2236   2247   ** object. Or NULL If the cursor id does not exist.
  2237         -**
  2238         -** If successful, set *ppConfig to point to the associated config object 
  2239         -** before returning.
  2240   2248   */
  2241         -Fts5Index *sqlite3Fts5IndexFromCsrid(
         2249  +Fts5Table *sqlite3Fts5TableFromCsrid(
  2242   2250     Fts5Global *pGlobal,            /* FTS5 global context for db handle */
  2243         -  i64 iCsrId,                     /* Id of cursor to find */
  2244         -  Fts5Config **ppConfig           /* OUT: Configuration object */
         2251  +  i64 iCsrId                      /* Id of cursor to find */
  2245   2252   ){
  2246   2253     Fts5Cursor *pCsr;
  2247         -  Fts5Table *pTab;
  2248         -
  2249   2254     pCsr = fts5CursorFromCsrid(pGlobal, iCsrId);
  2250         -  pTab = (Fts5Table*)pCsr->base.pVtab;
  2251         -  *ppConfig = pTab->pConfig;
  2252         -
  2253         -  return pTab->pIndex;
         2255  +  if( pCsr ){
         2256  +    return (Fts5Table*)pCsr->base.pVtab;
         2257  +  }
         2258  +  return 0;
  2254   2259   }
  2255   2260   
  2256   2261   /*
  2257   2262   ** Return a "position-list blob" corresponding to the current position of
  2258   2263   ** cursor pCsr via sqlite3_result_blob(). A position-list blob contains
  2259   2264   ** the current position-list for each phrase in the query associated with
  2260   2265   ** cursor pCsr.
................................................................................
  2326   2331   ** the row that the supplied cursor currently points to.
  2327   2332   */
  2328   2333   static int fts5ColumnMethod(
  2329   2334     sqlite3_vtab_cursor *pCursor,   /* Cursor to retrieve value from */
  2330   2335     sqlite3_context *pCtx,          /* Context for sqlite3_result_xxx() calls */
  2331   2336     int iCol                        /* Index of column to read value from */
  2332   2337   ){
  2333         -  Fts5Table *pTab = (Fts5Table*)(pCursor->pVtab);
  2334         -  Fts5Config *pConfig = pTab->pConfig;
         2338  +  Fts5FullTable *pTab = (Fts5FullTable*)(pCursor->pVtab);
         2339  +  Fts5Config *pConfig = pTab->p.pConfig;
  2335   2340     Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
  2336   2341     int rc = SQLITE_OK;
  2337   2342     
  2338   2343     assert( CsrFlagTest(pCsr, FTS5CSR_EOF)==0 );
  2339   2344   
  2340   2345     if( pCsr->ePlan==FTS5_PLAN_SPECIAL ){
  2341   2346       if( iCol==pConfig->nCol ){
................................................................................
  2379   2384   static int fts5FindFunctionMethod(
  2380   2385     sqlite3_vtab *pVtab,            /* Virtual table handle */
  2381   2386     int nUnused,                    /* Number of SQL function arguments */
  2382   2387     const char *zName,              /* Name of SQL function */
  2383   2388     void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), /* OUT: Result */
  2384   2389     void **ppArg                    /* OUT: User data for *pxFunc */
  2385   2390   ){
  2386         -  Fts5Table *pTab = (Fts5Table*)pVtab;
         2391  +  Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
  2387   2392     Fts5Auxiliary *pAux;
  2388   2393   
  2389   2394     UNUSED_PARAM(nUnused);
  2390   2395     pAux = fts5FindAuxiliary(pTab, zName);
  2391   2396     if( pAux ){
  2392   2397       *pxFunc = fts5ApiCallback;
  2393   2398       *ppArg = (void*)pAux;
................................................................................
  2401   2406   /*
  2402   2407   ** Implementation of FTS5 xRename method. Rename an fts5 table.
  2403   2408   */
  2404   2409   static int fts5RenameMethod(
  2405   2410     sqlite3_vtab *pVtab,            /* Virtual table handle */
  2406   2411     const char *zName               /* New name of table */
  2407   2412   ){
  2408         -  Fts5Table *pTab = (Fts5Table*)pVtab;
         2413  +  Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
  2409   2414     return sqlite3Fts5StorageRename(pTab->pStorage, zName);
  2410   2415   }
         2416  +
         2417  +int sqlite3Fts5FlushToDisk(Fts5Table *pTab){
         2418  +  fts5TripCursors((Fts5FullTable*)pTab);
         2419  +  return sqlite3Fts5StorageSync(((Fts5FullTable*)pTab)->pStorage);
         2420  +}
  2411   2421   
  2412   2422   /*
  2413   2423   ** The xSavepoint() method.
  2414   2424   **
  2415   2425   ** Flush the contents of the pending-terms table to disk.
  2416   2426   */
  2417   2427   static int fts5SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
  2418         -  Fts5Table *pTab = (Fts5Table*)pVtab;
  2419   2428     UNUSED_PARAM(iSavepoint);  /* Call below is a no-op for NDEBUG builds */
  2420         -  fts5CheckTransactionState(pTab, FTS5_SAVEPOINT, iSavepoint);
  2421         -  fts5TripCursors(pTab);
  2422         -  return sqlite3Fts5StorageSync(pTab->pStorage);
         2429  +  fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_SAVEPOINT, iSavepoint);
         2430  +  return sqlite3Fts5FlushToDisk((Fts5Table*)pVtab);
  2423   2431   }
  2424   2432   
  2425   2433   /*
  2426   2434   ** The xRelease() method.
  2427   2435   **
  2428   2436   ** This is a no-op.
  2429   2437   */
  2430   2438   static int fts5ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
  2431         -  Fts5Table *pTab = (Fts5Table*)pVtab;
  2432   2439     UNUSED_PARAM(iSavepoint);  /* Call below is a no-op for NDEBUG builds */
  2433         -  fts5CheckTransactionState(pTab, FTS5_RELEASE, iSavepoint);
  2434         -  fts5TripCursors(pTab);
  2435         -  return sqlite3Fts5StorageSync(pTab->pStorage);
         2440  +  fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_RELEASE, iSavepoint);
         2441  +  return sqlite3Fts5FlushToDisk((Fts5Table*)pVtab);
  2436   2442   }
  2437   2443   
  2438   2444   /*
  2439   2445   ** The xRollbackTo() method.
  2440   2446   **
  2441   2447   ** Discard the contents of the pending terms table.
  2442   2448   */
  2443   2449   static int fts5RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
  2444         -  Fts5Table *pTab = (Fts5Table*)pVtab;
         2450  +  Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
  2445   2451     UNUSED_PARAM(iSavepoint);  /* Call below is a no-op for NDEBUG builds */
  2446   2452     fts5CheckTransactionState(pTab, FTS5_ROLLBACKTO, iSavepoint);
  2447   2453     fts5TripCursors(pTab);
  2448   2454     return sqlite3Fts5StorageRollback(pTab->pStorage);
  2449   2455   }
  2450   2456   
  2451   2457   /*
................................................................................
  2640   2646     int nArg,                       /* Number of args */
  2641   2647     sqlite3_value **apUnused        /* Function arguments */
  2642   2648   ){
  2643   2649     assert( nArg==0 );
  2644   2650     UNUSED_PARAM2(nArg, apUnused);
  2645   2651     sqlite3_result_text(pCtx, "--FTS5-SOURCE-ID--", -1, SQLITE_TRANSIENT);
  2646   2652   }
         2653  +
         2654  +/*
         2655  +** Return true if zName is the extension on one of the shadow tables used
         2656  +** by this module.
         2657  +*/
         2658  +static int fts5ShadowName(const char *zName){
         2659  +  static const char *azName[] = {
         2660  +    "config", "content", "data", "docsize", "idx"
         2661  +  };
         2662  +  unsigned int i;
         2663  +  for(i=0; i<sizeof(azName)/sizeof(azName[0]); i++){
         2664  +    if( sqlite3_stricmp(zName, azName[i])==0 ) return 1;
         2665  +  }
         2666  +  return 0;
         2667  +}
  2647   2668   
  2648   2669   static int fts5Init(sqlite3 *db){
  2649   2670     static const sqlite3_module fts5Mod = {
  2650         -    /* iVersion      */ 2,
         2671  +    /* iVersion      */ 3,
  2651   2672       /* xCreate       */ fts5CreateMethod,
  2652   2673       /* xConnect      */ fts5ConnectMethod,
  2653   2674       /* xBestIndex    */ fts5BestIndexMethod,
  2654   2675       /* xDisconnect   */ fts5DisconnectMethod,
  2655   2676       /* xDestroy      */ fts5DestroyMethod,
  2656   2677       /* xOpen         */ fts5OpenMethod,
  2657   2678       /* xClose        */ fts5CloseMethod,
................................................................................
  2666   2687       /* xCommit       */ fts5CommitMethod,
  2667   2688       /* xRollback     */ fts5RollbackMethod,
  2668   2689       /* xFindFunction */ fts5FindFunctionMethod,
  2669   2690       /* xRename       */ fts5RenameMethod,
  2670   2691       /* xSavepoint    */ fts5SavepointMethod,
  2671   2692       /* xRelease      */ fts5ReleaseMethod,
  2672   2693       /* xRollbackTo   */ fts5RollbackToMethod,
         2694  +    /* xShadowName   */ fts5ShadowName
  2673   2695     };
  2674   2696   
  2675   2697     int rc;
  2676   2698     Fts5Global *pGlobal = 0;
  2677   2699   
  2678   2700     pGlobal = (Fts5Global*)sqlite3_malloc(sizeof(Fts5Global));
  2679   2701     if( pGlobal==0 ){

Changes to ext/fts5/fts5_storage.c.

   111    111   
   112    112         case FTS5_STMT_INSERT_CONTENT: 
   113    113         case FTS5_STMT_REPLACE_CONTENT: {
   114    114           int nCol = pC->nCol + 1;
   115    115           char *zBind;
   116    116           int i;
   117    117   
   118         -        zBind = sqlite3_malloc(1 + nCol*2);
          118  +        zBind = sqlite3_malloc64(1 + nCol*2);
   119    119           if( zBind ){
   120    120             for(i=0; i<nCol; i++){
   121    121               zBind[i*2] = '?';
   122    122               zBind[i*2 + 1] = ',';
   123    123             }
   124    124             zBind[i*2-1] = '\0';
   125    125             zSql = sqlite3_mprintf(azStmt[eStmt], pC->zDb, pC->zName, zBind);
................................................................................
   132    132           zSql = sqlite3_mprintf(azStmt[eStmt], pC->zDb, pC->zName);
   133    133           break;
   134    134       }
   135    135   
   136    136       if( zSql==0 ){
   137    137         rc = SQLITE_NOMEM;
   138    138       }else{
   139         -      rc = sqlite3_prepare_v3(pC->db, zSql, -1,
   140         -                              SQLITE_PREPARE_PERSISTENT, &p->aStmt[eStmt], 0);
          139  +      int f = SQLITE_PREPARE_PERSISTENT;
          140  +      if( eStmt>FTS5_STMT_LOOKUP ) f |= SQLITE_PREPARE_NO_VTAB;
          141  +      rc = sqlite3_prepare_v3(pC->db, zSql, -1, f, &p->aStmt[eStmt], 0);
   141    142         sqlite3_free(zSql);
   142    143         if( rc!=SQLITE_OK && pzErrMsg ){
   143    144           *pzErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(pC->db));
   144    145         }
   145    146       }
   146    147     }
   147    148   
................................................................................
   277    278     Fts5Index *pIndex, 
   278    279     int bCreate, 
   279    280     Fts5Storage **pp,
   280    281     char **pzErr                    /* OUT: Error message */
   281    282   ){
   282    283     int rc = SQLITE_OK;
   283    284     Fts5Storage *p;                 /* New object */
   284         -  int nByte;                      /* Bytes of space to allocate */
          285  +  sqlite3_int64 nByte;            /* Bytes of space to allocate */
   285    286   
   286    287     nByte = sizeof(Fts5Storage)               /* Fts5Storage object */
   287    288           + pConfig->nCol * sizeof(i64);      /* Fts5Storage.aTotalSize[] */
   288         -  *pp = p = (Fts5Storage*)sqlite3_malloc(nByte);
          289  +  *pp = p = (Fts5Storage*)sqlite3_malloc64(nByte);
   289    290     if( !p ) return SQLITE_NOMEM;
   290    291   
   291    292     memset(p, 0, nByte);
   292    293     p->aTotalSize = (i64*)&p[1];
   293    294     p->pConfig = pConfig;
   294    295     p->pIndex = pIndex;
   295    296   
   296    297     if( bCreate ){
   297    298       if( pConfig->eContent==FTS5_CONTENT_NORMAL ){
   298    299         int nDefn = 32 + pConfig->nCol*10;
   299         -      char *zDefn = sqlite3_malloc(32 + pConfig->nCol * 10);
          300  +      char *zDefn = sqlite3_malloc64(32 + (sqlite3_int64)pConfig->nCol * 10);
   300    301         if( zDefn==0 ){
   301    302           rc = SQLITE_NOMEM;
   302    303         }else{
   303    304           int i;
   304    305           int iOff;
   305    306           sqlite3_snprintf(nDefn, zDefn, "id INTEGER PRIMARY KEY");
   306    307           iOff = (int)strlen(zDefn);
................................................................................
   583    584   }
   584    585   
   585    586   int sqlite3Fts5StorageRebuild(Fts5Storage *p){
   586    587     Fts5Buffer buf = {0,0,0};
   587    588     Fts5Config *pConfig = p->pConfig;
   588    589     sqlite3_stmt *pScan = 0;
   589    590     Fts5InsertCtx ctx;
   590         -  int rc;
          591  +  int rc, rc2;
   591    592   
   592    593     memset(&ctx, 0, sizeof(Fts5InsertCtx));
   593    594     ctx.pStorage = p;
   594    595     rc = sqlite3Fts5StorageDeleteAll(p);
   595    596     if( rc==SQLITE_OK ){
   596    597       rc = fts5StorageLoadTotals(p, 1);
   597    598     }
................................................................................
   622    623       p->nTotalRow++;
   623    624   
   624    625       if( rc==SQLITE_OK ){
   625    626         rc = fts5StorageInsertDocsize(p, iRowid, &buf);
   626    627       }
   627    628     }
   628    629     sqlite3_free(buf.p);
          630  +  rc2 = sqlite3_reset(pScan);
          631  +  if( rc==SQLITE_OK ) rc = rc2;
   629    632   
   630    633     /* Write the averages record */
   631    634     if( rc==SQLITE_OK ){
   632    635       rc = fts5StorageSaveTotals(p);
   633    636     }
   634    637     return rc;
   635    638   }
................................................................................
   871    874     int *aColSize;                  /* Array of size pConfig->nCol */
   872    875     i64 *aTotalSize;                /* Array of size pConfig->nCol */
   873    876     Fts5IntegrityCtx ctx;
   874    877     sqlite3_stmt *pScan;
   875    878   
   876    879     memset(&ctx, 0, sizeof(Fts5IntegrityCtx));
   877    880     ctx.pConfig = p->pConfig;
   878         -  aTotalSize = (i64*)sqlite3_malloc(pConfig->nCol * (sizeof(int)+sizeof(i64)));
          881  +  aTotalSize = (i64*)sqlite3_malloc64(pConfig->nCol*(sizeof(int)+sizeof(i64)));
   879    882     if( !aTotalSize ) return SQLITE_NOMEM;
   880    883     aColSize = (int*)&aTotalSize[pConfig->nCol];
   881    884     memset(aTotalSize, 0, sizeof(i64) * pConfig->nCol);
   882    885   
   883    886     /* Generate the expected index checksum based on the contents of the
   884    887     ** %_content table. This block stores the checksum in ctx.cksum. */
   885    888     rc = fts5StorageGetStmt(p, FTS5_STMT_SCAN, &pScan, 0);
................................................................................
  1071   1074     }
  1072   1075     return rc;
  1073   1076   }
  1074   1077   
  1075   1078   int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow){
  1076   1079     int rc = fts5StorageLoadTotals(p, 0);
  1077   1080     if( rc==SQLITE_OK ){
         1081  +    /* nTotalRow being zero does not necessarily indicate a corrupt 
         1082  +    ** database - it might be that the FTS5 table really does contain zero
         1083  +    ** rows. However this function is only called from the xRowCount() API,
         1084  +    ** and there is no way for that API to be invoked if the table contains
         1085  +    ** no rows. Hence the FTS5_CORRUPT return.  */
  1078   1086       *pnRow = p->nTotalRow;
         1087  +    if( p->nTotalRow<=0 ) rc = FTS5_CORRUPT;
  1079   1088     }
  1080   1089     return rc;
  1081   1090   }
  1082   1091   
  1083   1092   /*
  1084   1093   ** Flush any data currently held in-memory to disk.
  1085   1094   */

Changes to ext/fts5/fts5_test_mi.c.

   305    305     const char *zArg                /* Matchinfo flag string */
   306    306   ){
   307    307     Fts5MatchinfoCtx *p;
   308    308     int nCol;
   309    309     int nPhrase;
   310    310     int i;
   311    311     int nInt;
   312         -  int nByte;
          312  +  sqlite3_int64 nByte;
   313    313     int rc;
   314    314   
   315    315     nCol = pApi->xColumnCount(pFts);
   316    316     nPhrase = pApi->xPhraseCount(pFts);
   317    317   
   318    318     nInt = 0;
   319    319     for(i=0; zArg[i]; i++){
................................................................................
   326    326       }
   327    327       nInt += n;
   328    328     }
   329    329   
   330    330     nByte = sizeof(Fts5MatchinfoCtx)          /* The struct itself */
   331    331            + sizeof(u32) * nInt               /* The p->aRet[] array */
   332    332            + (i+1);                           /* The p->zArg string */
   333         -  p = (Fts5MatchinfoCtx*)sqlite3_malloc(nByte);
          333  +  p = (Fts5MatchinfoCtx*)sqlite3_malloc64(nByte);
   334    334     if( p==0 ){
   335    335       sqlite3_result_error_nomem(pCtx);
   336    336       return 0;
   337    337     }
   338    338     memset(p, 0, nByte);
   339    339   
   340    340     p->nCol = nCol;

Changes to ext/fts5/fts5_test_tok.c.

   133    133       int nByte = 0;
   134    134       char **azDequote;
   135    135   
   136    136       for(i=0; i<argc; i++){
   137    137         nByte += (int)(strlen(argv[i]) + 1);
   138    138       }
   139    139   
   140         -    *pazDequote = azDequote = sqlite3_malloc(sizeof(char *)*argc + nByte);
          140  +    *pazDequote = azDequote = sqlite3_malloc64(sizeof(char *)*argc + nByte);
   141    141       if( azDequote==0 ){
   142    142         rc = SQLITE_NOMEM;
   143    143       }else{
   144    144         char *pSpace = (char *)&azDequote[argc];
   145    145         for(i=0; i<argc; i++){
   146    146           int n = (int)strlen(argv[i]);
   147    147           azDequote[i] = pSpace;
................................................................................
   331    331   ){
   332    332     Fts5tokCursor *pCsr = (Fts5tokCursor*)pCtx;
   333    333     Fts5tokRow *pRow;
   334    334   
   335    335     if( (pCsr->nRow & (pCsr->nRow-1))==0 ){
   336    336       int nNew = pCsr->nRow ? pCsr->nRow*2 : 32;
   337    337       Fts5tokRow *aNew;
   338         -    aNew = (Fts5tokRow*)sqlite3_realloc(pCsr->aRow, nNew*sizeof(Fts5tokRow));
          338  +    aNew = (Fts5tokRow*)sqlite3_realloc64(pCsr->aRow, nNew*sizeof(Fts5tokRow));
   339    339       if( aNew==0 ) return SQLITE_NOMEM;
   340    340       memset(&aNew[pCsr->nRow], 0, sizeof(Fts5tokRow)*(nNew-pCsr->nRow));
   341    341       pCsr->aRow = aNew;
   342    342     }
   343    343   
   344    344     pRow = &pCsr->aRow[pCsr->nRow];
   345    345     pRow->iStart = iStart;
................................................................................
   374    374     if( idxNum==1 ){
   375    375       const char *zByte = (const char *)sqlite3_value_text(apVal[0]);
   376    376       int nByte = sqlite3_value_bytes(apVal[0]);
   377    377       pCsr->zInput = sqlite3_malloc(nByte+1);
   378    378       if( pCsr->zInput==0 ){
   379    379         rc = SQLITE_NOMEM;
   380    380       }else{
   381         -      memcpy(pCsr->zInput, zByte, nByte);
          381  +      if( nByte>0 ) memcpy(pCsr->zInput, zByte, nByte);
   382    382         pCsr->zInput[nByte] = 0;
   383    383         rc = pTab->tok.xTokenize(
   384    384             pTab->pTok, (void*)pCsr, 0, zByte, nByte, fts5tokCb
   385    385         );
   386    386       }
   387    387     }
   388    388   
................................................................................
   467    467        0,                           /* xSync         */
   468    468        0,                           /* xCommit       */
   469    469        0,                           /* xRollback     */
   470    470        0,                           /* xFindFunction */
   471    471        0,                           /* xRename       */
   472    472        0,                           /* xSavepoint    */
   473    473        0,                           /* xRelease      */
   474         -     0                            /* xRollbackTo   */
          474  +     0,                           /* xRollbackTo   */
          475  +     0                            /* xShadowName   */
   475    476     };
   476    477     int rc;                         /* Return code */
   477    478   
   478    479     rc = sqlite3_create_module(db, "fts5tokenize", &fts5tok_module, (void*)pApi);
   479    480     return rc;
   480    481   }
   481    482   
   482    483   #endif /* defined(SQLITE_TEST) && defined(SQLITE_ENABLE_FTS5) */

Changes to ext/fts5/fts5_tokenize.c.

   148    148         ie++;
   149    149       }
   150    150   
   151    151       /* Fold to lower case */
   152    152       nByte = ie-is;
   153    153       if( nByte>nFold ){
   154    154         if( pFold!=aFold ) sqlite3_free(pFold);
   155         -      pFold = sqlite3_malloc(nByte*2);
          155  +      pFold = sqlite3_malloc64((sqlite3_int64)nByte*2);
   156    156         if( pFold==0 ){
   157    157           rc = SQLITE_NOMEM;
   158    158           break;
   159    159         }
   160    160         nFold = nByte*2;
   161    161       }
   162    162       asciiFold(pFold, &pText[is], nByte);
................................................................................
   230    230   #endif /* ifndef SQLITE_AMALGAMATION */
   231    231   
   232    232   typedef struct Unicode61Tokenizer Unicode61Tokenizer;
   233    233   struct Unicode61Tokenizer {
   234    234     unsigned char aTokenChar[128];  /* ASCII range token characters */
   235    235     char *aFold;                    /* Buffer to fold text into */
   236    236     int nFold;                      /* Size of aFold[] in bytes */
   237         -  int bRemoveDiacritic;           /* True if remove_diacritics=1 is set */
          237  +  int eRemoveDiacritic;           /* True if remove_diacritics=1 is set */
   238    238     int nException;
   239    239     int *aiException;
   240    240   
   241    241     unsigned char aCategory[32];    /* True for token char categories */
   242    242   };
          243  +
          244  +/* Values for eRemoveDiacritic (must match internals of fts5_unicode2.c) */
          245  +#define FTS5_REMOVE_DIACRITICS_NONE    0
          246  +#define FTS5_REMOVE_DIACRITICS_SIMPLE  1
          247  +#define FTS5_REMOVE_DIACRITICS_COMPLEX 2
   243    248   
   244    249   static int fts5UnicodeAddExceptions(
   245    250     Unicode61Tokenizer *p,          /* Tokenizer object */
   246    251     const char *z,                  /* Characters to treat as exceptions */
   247    252     int bTokenChars                 /* 1 for 'tokenchars', 0 for 'separators' */
   248    253   ){
   249    254     int rc = SQLITE_OK;
   250    255     int n = (int)strlen(z);
   251    256     int *aNew;
   252    257   
   253    258     if( n>0 ){
   254         -    aNew = (int*)sqlite3_realloc(p->aiException, (n+p->nException)*sizeof(int));
          259  +    aNew = (int*)sqlite3_realloc64(p->aiException,
          260  +                                   (n+p->nException)*sizeof(int));
   255    261       if( aNew ){
   256    262         int nNew = p->nException;
   257    263         const unsigned char *zCsr = (const unsigned char*)z;
   258    264         const unsigned char *zTerm = (const unsigned char*)&z[n];
   259    265         while( zCsr<zTerm ){
   260         -        int iCode;
          266  +        u32 iCode;
   261    267           int bToken;
   262    268           READ_UTF8(zCsr, zTerm, iCode);
   263    269           if( iCode<128 ){
   264    270             p->aTokenChar[iCode] = (unsigned char)bTokenChars;
   265    271           }else{
   266    272             bToken = p->aCategory[sqlite3Fts5UnicodeCategory(iCode)];
   267    273             assert( (bToken==0 || bToken==1) ); 
   268    274             assert( (bTokenChars==0 || bTokenChars==1) );
   269    275             if( bToken!=bTokenChars && sqlite3Fts5UnicodeIsdiacritic(iCode)==0 ){
   270    276               int i;
   271    277               for(i=0; i<nNew; i++){
   272         -              if( aNew[i]>iCode ) break;
          278  +              if( (u32)aNew[i]>iCode ) break;
   273    279               }
   274    280               memmove(&aNew[i+1], &aNew[i], (nNew-i)*sizeof(int));
   275    281               aNew[i] = iCode;
   276    282               nNew++;
   277    283             }
   278    284           }
   279    285         }
................................................................................
   357    363     }else{
   358    364       p = (Unicode61Tokenizer*)sqlite3_malloc(sizeof(Unicode61Tokenizer));
   359    365       if( p ){
   360    366         const char *zCat = "L* N* Co";
   361    367         int i;
   362    368         memset(p, 0, sizeof(Unicode61Tokenizer));
   363    369   
   364         -      p->bRemoveDiacritic = 1;
          370  +      p->eRemoveDiacritic = FTS5_REMOVE_DIACRITICS_SIMPLE;
   365    371         p->nFold = 64;
   366    372         p->aFold = sqlite3_malloc(p->nFold * sizeof(char));
   367    373         if( p->aFold==0 ){
   368    374           rc = SQLITE_NOMEM;
   369    375         }
   370    376   
   371    377         /* Search for a "categories" argument */
................................................................................
   378    384         if( rc==SQLITE_OK ){
   379    385           rc = unicodeSetCategories(p, zCat);
   380    386         }
   381    387   
   382    388         for(i=0; rc==SQLITE_OK && i<nArg; i+=2){
   383    389           const char *zArg = azArg[i+1];
   384    390           if( 0==sqlite3_stricmp(azArg[i], "remove_diacritics") ){
   385         -          if( (zArg[0]!='0' && zArg[0]!='1') || zArg[1] ){
          391  +          if( (zArg[0]!='0' && zArg[0]!='1' && zArg[0]!='2') || zArg[1] ){
   386    392               rc = SQLITE_ERROR;
          393  +          }else{
          394  +            p->eRemoveDiacritic = (zArg[0] - '0');
          395  +            assert( p->eRemoveDiacritic==FTS5_REMOVE_DIACRITICS_NONE
          396  +                 || p->eRemoveDiacritic==FTS5_REMOVE_DIACRITICS_SIMPLE
          397  +                 || p->eRemoveDiacritic==FTS5_REMOVE_DIACRITICS_COMPLEX
          398  +            );
   387    399             }
   388         -          p->bRemoveDiacritic = (zArg[0]=='1');
   389    400           }else
   390    401           if( 0==sqlite3_stricmp(azArg[i], "tokenchars") ){
   391    402             rc = fts5UnicodeAddExceptions(p, zArg, 1);
   392    403           }else
   393    404           if( 0==sqlite3_stricmp(azArg[i], "separators") ){
   394    405             rc = fts5UnicodeAddExceptions(p, zArg, 0);
   395    406           }else
................................................................................
   415    426   /*
   416    427   ** Return true if, for the purposes of tokenizing with the tokenizer
   417    428   ** passed as the first argument, codepoint iCode is considered a token 
   418    429   ** character (not a separator).
   419    430   */
   420    431   static int fts5UnicodeIsAlnum(Unicode61Tokenizer *p, int iCode){
   421    432     return (
   422         -    p->aCategory[sqlite3Fts5UnicodeCategory(iCode)]
          433  +    p->aCategory[sqlite3Fts5UnicodeCategory((u32)iCode)]
   423    434       ^ fts5UnicodeIsException(p, iCode)
   424    435     );
   425    436   }
   426    437   
   427    438   static int fts5UnicodeTokenize(
   428    439     Fts5Tokenizer *pTokenizer,
   429    440     void *pCtx,
................................................................................
   444    455     const char *pEnd = &aFold[nFold-6];
   445    456   
   446    457     UNUSED_PARAM(iUnused);
   447    458   
   448    459     /* Each iteration of this loop gobbles up a contiguous run of separators,
   449    460     ** then the next token.  */
   450    461     while( rc==SQLITE_OK ){
   451         -    int iCode;                    /* non-ASCII codepoint read from input */
          462  +    u32 iCode;                    /* non-ASCII codepoint read from input */
   452    463       char *zOut = aFold;
   453    464       int is;
   454    465       int ie;
   455    466   
   456    467       /* Skip any separator characters. */
   457    468       while( 1 ){
   458    469         if( zCsr>=zTerm ) goto tokenize_done;
................................................................................
   476    487       /* Run through the tokenchars. Fold them into the output buffer along
   477    488       ** the way.  */
   478    489       while( zCsr<zTerm ){
   479    490   
   480    491         /* Grow the output buffer so that there is sufficient space to fit the
   481    492         ** largest possible utf-8 character.  */
   482    493         if( zOut>pEnd ){
   483         -        aFold = sqlite3_malloc(nFold*2);
          494  +        aFold = sqlite3_malloc64((sqlite3_int64)nFold*2);
   484    495           if( aFold==0 ){
   485    496             rc = SQLITE_NOMEM;
   486    497             goto tokenize_done;
   487    498           }
   488    499           zOut = &aFold[zOut - p->aFold];
   489    500           memcpy(aFold, p->aFold, nFold);
   490    501           sqlite3_free(p->aFold);
................................................................................
   495    506   
   496    507         if( *zCsr & 0x80 ){
   497    508           /* An non-ascii-range character. Fold it into the output buffer if
   498    509           ** it is a token character, or break out of the loop if it is not. */
   499    510           READ_UTF8(zCsr, zTerm, iCode);
   500    511           if( fts5UnicodeIsAlnum(p,iCode)||sqlite3Fts5UnicodeIsdiacritic(iCode) ){
   501    512    non_ascii_tokenchar:
   502         -          iCode = sqlite3Fts5UnicodeFold(iCode, p->bRemoveDiacritic);
          513  +          iCode = sqlite3Fts5UnicodeFold(iCode, p->eRemoveDiacritic);
   503    514             if( iCode ) WRITE_UTF8(zOut, iCode);
   504    515           }else{
   505    516             break;
   506    517           }
   507    518         }else if( a[*zCsr]==0 ){
   508    519           /* An ascii-range separator character. End of token. */
   509    520           break; 
................................................................................
  1270   1281           &aBuiltin[i].x,
  1271   1282           0
  1272   1283       );
  1273   1284     }
  1274   1285   
  1275   1286     return rc;
  1276   1287   }
  1277         -
  1278         -

Changes to ext/fts5/fts5_unicode2.c.

     1      1   /*
     2         -** 2012 May 25
            2  +** 2012-05-25
     3      3   **
     4      4   ** The author disclaims copyright to this source code.  In place of
     5      5   ** a legal notice, here is a blessing:
     6      6   **
     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
................................................................................
    24     24   ** If the argument is a codepoint corresponding to a lowercase letter
    25     25   ** in the ASCII range with a diacritic added, return the codepoint
    26     26   ** of the ASCII letter only. For example, if passed 235 - "LATIN
    27     27   ** SMALL LETTER E WITH DIAERESIS" - return 65 ("LATIN SMALL LETTER
    28     28   ** E"). The resuls of passing a codepoint that corresponds to an
    29     29   ** uppercase letter are undefined.
    30     30   */
    31         -static int fts5_remove_diacritic(int c){
           31  +static int fts5_remove_diacritic(int c, int bComplex){
    32     32     unsigned short aDia[] = {
    33     33           0,  1797,  1848,  1859,  1891,  1928,  1940,  1995, 
    34     34        2024,  2040,  2060,  2110,  2168,  2206,  2264,  2286, 
    35     35        2344,  2383,  2472,  2488,  2516,  2596,  2668,  2732, 
    36     36        2782,  2842,  2894,  2954,  2984,  3000,  3028,  3336, 
    37         -     3456,  3696,  3712,  3728,  3744,  3896,  3912,  3928, 
    38         -     3968,  4008,  4040,  4106,  4138,  4170,  4202,  4234, 
    39         -     4266,  4296,  4312,  4344,  4408,  4424,  4472,  4504, 
    40         -     6148,  6198,  6264,  6280,  6360,  6429,  6505,  6529, 
    41         -    61448, 61468, 61534, 61592, 61642, 61688, 61704, 61726, 
    42         -    61784, 61800, 61836, 61880, 61914, 61948, 61998, 62122, 
    43         -    62154, 62200, 62218, 62302, 62364, 62442, 62478, 62536, 
    44         -    62554, 62584, 62604, 62640, 62648, 62656, 62664, 62730, 
    45         -    62924, 63050, 63082, 63274, 63390, 
           37  +     3456,  3696,  3712,  3728,  3744,  3766,  3832,  3896, 
           38  +     3912,  3928,  3944,  3968,  4008,  4040,  4056,  4106, 
           39  +     4138,  4170,  4202,  4234,  4266,  4296,  4312,  4344, 
           40  +     4408,  4424,  4442,  4472,  4488,  4504,  6148,  6198, 
           41  +     6264,  6280,  6360,  6429,  6505,  6529, 61448, 61468, 
           42  +    61512, 61534, 61592, 61610, 61642, 61672, 61688, 61704, 
           43  +    61726, 61784, 61800, 61816, 61836, 61880, 61896, 61914, 
           44  +    61948, 61998, 62062, 62122, 62154, 62184, 62200, 62218, 
           45  +    62252, 62302, 62364, 62410, 62442, 62478, 62536, 62554, 
           46  +    62584, 62604, 62640, 62648, 62656, 62664, 62730, 62766, 
           47  +    62830, 62890, 62924, 62974, 63032, 63050, 63082, 63118, 
           48  +    63182, 63242, 63274, 63310, 63368, 63390, 
    46     49     };
    47         -  char aChar[] = {
    48         -    '\0', 'a',  'c',  'e',  'i',  'n',  'o',  'u',  'y',  'y',  'a',  'c',  
    49         -    'd',  'e',  'e',  'g',  'h',  'i',  'j',  'k',  'l',  'n',  'o',  'r',  
    50         -    's',  't',  'u',  'u',  'w',  'y',  'z',  'o',  'u',  'a',  'i',  'o',  
    51         -    'u',  'g',  'k',  'o',  'j',  'g',  'n',  'a',  'e',  'i',  'o',  'r',  
    52         -    'u',  's',  't',  'h',  'a',  'e',  'o',  'y',  '\0', '\0', '\0', '\0', 
    53         -    '\0', '\0', '\0', '\0', 'a',  'b',  'd',  'd',  'e',  'f',  'g',  'h',  
    54         -    'h',  'i',  'k',  'l',  'l',  'm',  'n',  'p',  'r',  'r',  's',  't',  
    55         -    'u',  'v',  'w',  'w',  'x',  'y',  'z',  'h',  't',  'w',  'y',  'a',  
    56         -    'e',  'i',  'o',  'u',  'y',  
           50  +#define HIBIT ((unsigned char)0x80)
           51  +  unsigned char aChar[] = {
           52  +    '\0',      'a',       'c',       'e',       'i',       'n',       
           53  +    'o',       'u',       'y',       'y',       'a',       'c',       
           54  +    'd',       'e',       'e',       'g',       'h',       'i',       
           55  +    'j',       'k',       'l',       'n',       'o',       'r',       
           56  +    's',       't',       'u',       'u',       'w',       'y',       
           57  +    'z',       'o',       'u',       'a',       'i',       'o',       
           58  +    'u',       'u'|HIBIT, 'a'|HIBIT, 'g',       'k',       'o',       
           59  +    'o'|HIBIT, 'j',       'g',       'n',       'a'|HIBIT, 'a',       
           60  +    'e',       'i',       'o',       'r',       'u',       's',       
           61  +    't',       'h',       'a',       'e',       'o'|HIBIT, 'o',       
           62  +    'o'|HIBIT, 'y',       '\0',      '\0',      '\0',      '\0',      
           63  +    '\0',      '\0',      '\0',      '\0',      'a',       'b',       
           64  +    'c'|HIBIT, 'd',       'd',       'e'|HIBIT, 'e',       'e'|HIBIT, 
           65  +    'f',       'g',       'h',       'h',       'i',       'i'|HIBIT, 
           66  +    'k',       'l',       'l'|HIBIT, 'l',       'm',       'n',       
           67  +    'o'|HIBIT, 'p',       'r',       'r'|HIBIT, 'r',       's',       
           68  +    's'|HIBIT, 't',       'u',       'u'|HIBIT, 'v',       'w',       
           69  +    'w',       'x',       'y',       'z',       'h',       't',       
           70  +    'w',       'y',       'a',       'a'|HIBIT, 'a'|HIBIT, 'a'|HIBIT, 
           71  +    'e',       'e'|HIBIT, 'e'|HIBIT, 'i',       'o',       'o'|HIBIT, 
           72  +    'o'|HIBIT, 'o'|HIBIT, 'u',       'u'|HIBIT, 'u'|HIBIT, 'y',       
    57     73     };
    58     74   
    59     75     unsigned int key = (((unsigned int)c)<<3) | 0x00000007;
    60     76     int iRes = 0;
    61     77     int iHi = sizeof(aDia)/sizeof(aDia[0]) - 1;
    62     78     int iLo = 0;
    63     79     while( iHi>=iLo ){
................................................................................
    66     82         iRes = iTest;
    67     83         iLo = iTest+1;
    68     84       }else{
    69     85         iHi = iTest-1;
    70     86       }
    71     87     }
    72     88     assert( key>=aDia[iRes] );
    73         -  return ((c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : (int)aChar[iRes]);
           89  +  if( bComplex==0 && (aChar[iRes] & 0x80) ) return c;
           90  +  return (c > (aDia[iRes]>>3) + (aDia[iRes]&0x07)) ? c : ((int)aChar[iRes] & 0x7F);
    74     91   }
    75     92   
    76     93   
    77     94   /*
    78     95   ** Return true if the argument interpreted as a unicode codepoint
    79     96   ** is a diacritical modifier character.
    80     97   */
    81     98   int sqlite3Fts5UnicodeIsdiacritic(int c){
    82     99     unsigned int mask0 = 0x08029FDF;
    83    100     unsigned int mask1 = 0x000361F8;
    84    101     if( c<768 || c>817 ) return 0;
    85    102     return (c < 768+32) ?
    86         -      (mask0 & (1 << (c-768))) :
    87         -      (mask1 & (1 << (c-768-32)));
          103  +      (mask0 & ((unsigned int)1 << (c-768))) :
          104  +      (mask1 & ((unsigned int)1 << (c-768-32)));
    88    105   }
    89    106   
    90    107   
    91    108   /*
    92    109   ** Interpret the argument as a unicode codepoint. If the codepoint
    93    110   ** is an upper case character that has a lower case equivalent,
    94    111   ** return the codepoint corresponding to the lower case version.
    95    112   ** Otherwise, return a copy of the argument.
    96    113   **
    97    114   ** The results are undefined if the value passed to this function
    98    115   ** is less than zero.
    99    116   */
   100         -int sqlite3Fts5UnicodeFold(int c, int bRemoveDiacritic){
          117  +int sqlite3Fts5UnicodeFold(int c, int eRemoveDiacritic){
   101    118     /* Each entry in the following array defines a rule for folding a range
   102    119     ** of codepoints to lower case. The rule applies to a range of nRange
   103    120     ** codepoints starting at codepoint iCode.
   104    121     **
   105    122     ** If the least significant bit in flags is clear, then the rule applies
   106    123     ** to all nRange codepoints (i.e. all nRange codepoints are upper case and
   107    124     ** need to be folded). Or, if it is set, then the rule only applies to
................................................................................
   216    233       assert( iRes>=0 && c>=aEntry[iRes].iCode );
   217    234       p = &aEntry[iRes];
   218    235       if( c<(p->iCode + p->nRange) && 0==(0x01 & p->flags & (p->iCode ^ c)) ){
   219    236         ret = (c + (aiOff[p->flags>>1])) & 0x0000FFFF;
   220    237         assert( ret>0 );
   221    238       }
   222    239   
   223         -    if( bRemoveDiacritic ) ret = fts5_remove_diacritic(ret);
          240  +    if( eRemoveDiacritic ){
          241  +      ret = fts5_remove_diacritic(ret, eRemoveDiacritic==2);
          242  +    }
   224    243     }
   225    244     
   226    245     else if( c>=66560 && c<66600 ){
   227    246       ret = c + 40;
   228    247     }
   229    248   
   230    249     return ret;
   231    250   }
   232    251   
   233    252   
   234         -#if 0
   235         -int sqlite3Fts5UnicodeNCat(void) { 
   236         -  return 32;
   237         -}
   238         -#endif
   239         -
   240    253   int sqlite3Fts5UnicodeCatParse(const char *zCat, u8 *aArray){ 
   241    254     aArray[0] = 1;
   242    255     switch( zCat[0] ){
   243    256       case 'C':
   244    257             switch( zCat[1] ){
   245    258               case 'c': aArray[1] = 1; break;
   246    259               case 'f': aArray[2] = 1; break;
................................................................................
   714    727       89,    1434,  3226,  506,   474,   506,   506,   367,   1018,  1946,  
   715    728       1402,  954,   1402,  314,   90,    1082,  218,   2266,  666,   1210,  
   716    729       186,   570,   2042,  58,    5850,  154,   2010,  154,   794,   2266,  
   717    730       378,   2266,  3738,  39,    39,    39,    39,    39,    39,    17351, 
   718    731       34,    3074,  7692,  63,    63,    
   719    732     };
   720    733   
   721         -int sqlite3Fts5UnicodeCategory(int iCode) { 
          734  +int sqlite3Fts5UnicodeCategory(u32 iCode) { 
   722    735     int iRes = -1;
   723    736     int iHi;
   724    737     int iLo;
   725    738     int ret;
   726    739     u16 iKey;
   727    740   
   728    741     if( iCode>=(1<<20) ){
................................................................................
   752    765   void sqlite3Fts5UnicodeAscii(u8 *aArray, u8 *aAscii){
   753    766     int i = 0;
   754    767     int iTbl = 0;
   755    768     while( i<128 ){
   756    769       int bToken = aArray[ aFts5UnicodeData[iTbl] & 0x1F ];
   757    770       int n = (aFts5UnicodeData[iTbl] >> 5) + i;
   758    771       for(; i<128 && i<n; i++){
   759         -      aAscii[i] = (u8)bToken;
          772  +      aAscii[i] = bToken;
   760    773       }
   761    774       iTbl++;
   762    775     }
   763    776   }
   764         -

Changes to ext/fts5/fts5_varint.c.

    72     72     ** routine.
    73     73     */
    74     74     {
    75     75       u64 v64;
    76     76       u8 n;
    77     77       p -= 2;
    78     78       n = sqlite3Fts5GetVarint(p, &v64);
    79         -    *v = (u32)v64;
           79  +    *v = ((u32)v64) & 0x7FFFFFFF;
    80     80       assert( n>3 && n<=9 );
    81     81       return n;
    82     82     }
    83     83   }
    84     84   
    85     85   
    86     86   /*
................................................................................
   338    338   #endif
   339    339     assert( iVal>=(1 << 7) );
   340    340     if( iVal<(1 << 14) ) return 2;
   341    341     if( iVal<(1 << 21) ) return 3;
   342    342     if( iVal<(1 << 28) ) return 4;
   343    343     return 5;
   344    344   }
   345         -

Changes to ext/fts5/fts5_vocab.c.

    51     51     Fts5Global *pGlobal;            /* FTS5 global object for this database */
    52     52     int eType;                      /* FTS5_VOCAB_COL, ROW or INSTANCE */
    53     53   };
    54     54   
    55     55   struct Fts5VocabCursor {
    56     56     sqlite3_vtab_cursor base;
    57     57     sqlite3_stmt *pStmt;            /* Statement holding lock on pIndex */
    58         -  Fts5Index *pIndex;              /* Associated FTS5 index */
           58  +  Fts5Table *pFts5;               /* Associated FTS5 table */
    59     59   
    60     60     int bEof;                       /* True if this cursor is at EOF */
    61     61     Fts5IndexIter *pIter;           /* Term/rowid iterator object */
    62     62   
    63     63     int nLeTerm;                    /* Size of zLeTerm in bytes */
    64     64     char *zLeTerm;                  /* (term <= $zLeTerm) paramater, or NULL */
    65     65   
    66     66     /* These are used by 'col' tables only */
    67         -  Fts5Config *pConfig;            /* Fts5 table configuration */
    68     67     int iCol;
    69     68     i64 *aCnt;
    70     69     i64 *aDoc;
    71     70   
    72     71     /* Output values used by all tables. */
    73     72     i64 rowid;                      /* This table's current rowid value */
    74     73     Fts5Buffer term;                /* Current value of 'term' column */
................................................................................
   323    322   ** Implementation of xOpen method.
   324    323   */
   325    324   static int fts5VocabOpenMethod(
   326    325     sqlite3_vtab *pVTab, 
   327    326     sqlite3_vtab_cursor **ppCsr
   328    327   ){
   329    328     Fts5VocabTable *pTab = (Fts5VocabTable*)pVTab;
   330         -  Fts5Index *pIndex = 0;
   331         -  Fts5Config *pConfig = 0;
          329  +  Fts5Table *pFts5 = 0;
   332    330     Fts5VocabCursor *pCsr = 0;
   333    331     int rc = SQLITE_OK;
   334    332     sqlite3_stmt *pStmt = 0;
   335    333     char *zSql = 0;
   336    334   
   337    335     zSql = sqlite3Fts5Mprintf(&rc,
   338    336         "SELECT t.%Q FROM %Q.%Q AS t WHERE t.%Q MATCH '*id'",
................................................................................
   343    341     }
   344    342     sqlite3_free(zSql);
   345    343     assert( rc==SQLITE_OK || pStmt==0 );
   346    344     if( rc==SQLITE_ERROR ) rc = SQLITE_OK;
   347    345   
   348    346     if( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){
   349    347       i64 iId = sqlite3_column_int64(pStmt, 0);
   350         -    pIndex = sqlite3Fts5IndexFromCsrid(pTab->pGlobal, iId, &pConfig);
          348  +    pFts5 = sqlite3Fts5TableFromCsrid(pTab->pGlobal, iId);
   351    349     }
   352    350   
   353         -  if( rc==SQLITE_OK && pIndex==0 ){
   354         -    rc = sqlite3_finalize(pStmt);
   355         -    pStmt = 0;
   356         -    if( rc==SQLITE_OK ){
   357         -      pVTab->zErrMsg = sqlite3_mprintf(
   358         -          "no such fts5 table: %s.%s", pTab->zFts5Db, pTab->zFts5Tbl
   359         -      );
   360         -      rc = SQLITE_ERROR;
          351  +  if( rc==SQLITE_OK ){
          352  +    if( pFts5==0 ){
          353  +      rc = sqlite3_finalize(pStmt);
          354  +      pStmt = 0;
          355  +      if( rc==SQLITE_OK ){
          356  +        pVTab->zErrMsg = sqlite3_mprintf(
          357  +            "no such fts5 table: %s.%s", pTab->zFts5Db, pTab->zFts5Tbl
          358  +            );
          359  +        rc = SQLITE_ERROR;
          360  +      }
          361  +    }else{
          362  +      rc = sqlite3Fts5FlushToDisk(pFts5);
   361    363       }
   362    364     }
   363    365   
   364    366     if( rc==SQLITE_OK ){
   365         -    int nByte = pConfig->nCol * sizeof(i64) * 2 + sizeof(Fts5VocabCursor);
          367  +    int nByte = pFts5->pConfig->nCol * sizeof(i64)*2 + sizeof(Fts5VocabCursor);
   366    368       pCsr = (Fts5VocabCursor*)sqlite3Fts5MallocZero(&rc, nByte);
   367    369     }
   368    370   
   369    371     if( pCsr ){
   370         -    pCsr->pIndex = pIndex;
          372  +    pCsr->pFts5 = pFts5;
   371    373       pCsr->pStmt = pStmt;
   372         -    pCsr->pConfig = pConfig;
   373    374       pCsr->aCnt = (i64*)&pCsr[1];
   374         -    pCsr->aDoc = &pCsr->aCnt[pConfig->nCol];
          375  +    pCsr->aDoc = &pCsr->aCnt[pFts5->pConfig->nCol];
   375    376     }else{
   376    377       sqlite3_finalize(pStmt);
   377    378     }
   378    379   
   379    380     *ppCsr = (sqlite3_vtab_cursor*)pCsr;
   380    381     return rc;
   381    382   }
................................................................................
   383    384   static void fts5VocabResetCursor(Fts5VocabCursor *pCsr){
   384    385     pCsr->rowid = 0;
   385    386     sqlite3Fts5IterClose(pCsr->pIter);
   386    387     pCsr->pIter = 0;
   387    388     sqlite3_free(pCsr->zLeTerm);
   388    389     pCsr->nLeTerm = -1;
   389    390     pCsr->zLeTerm = 0;
          391  +  pCsr->bEof = 0;
   390    392   }
   391    393   
   392    394   /*
   393    395   ** Close the cursor.  For additional information see the documentation
   394    396   ** on the xClose method of the virtual table interface.
   395    397   */
   396    398   static int fts5VocabCloseMethod(sqlite3_vtab_cursor *pCursor){
................................................................................
   421    423   
   422    424       sqlite3Fts5BufferSet(&rc, &pCsr->term, nTerm, (const u8*)zTerm);
   423    425     }
   424    426     return rc;
   425    427   }
   426    428   
   427    429   static int fts5VocabInstanceNext(Fts5VocabCursor *pCsr){
   428         -  int eDetail = pCsr->pConfig->eDetail;
          430  +  int eDetail = pCsr->pFts5->pConfig->eDetail;
   429    431     int rc = SQLITE_OK;
   430    432     Fts5IndexIter *pIter = pCsr->pIter;
   431    433     i64 *pp = &pCsr->iInstPos;
   432    434     int *po = &pCsr->iInstOff;
   433    435     
          436  +  assert( sqlite3Fts5IterEof(pIter)==0 );
          437  +  assert( pCsr->bEof==0 );
   434    438     while( eDetail==FTS5_DETAIL_NONE
   435    439         || sqlite3Fts5PoslistNext64(pIter->pData, pIter->nData, po, pp) 
   436    440     ){
   437    441       pCsr->iInstPos = 0;
   438    442       pCsr->iInstOff = 0;
   439    443   
   440    444       rc = sqlite3Fts5IterNextScan(pCsr->pIter);
   441    445       if( rc==SQLITE_OK ){
   442    446         rc = fts5VocabInstanceNewTerm(pCsr);
   443         -      if( eDetail==FTS5_DETAIL_NONE ) break;
          447  +      if( pCsr->bEof || eDetail==FTS5_DETAIL_NONE ) break;
   444    448       }
   445    449       if( rc ){
   446    450         pCsr->bEof = 1;
   447    451         break;
   448    452       }
   449    453     }
   450    454   
................................................................................
   454    458   /*
   455    459   ** Advance the cursor to the next row in the table.
   456    460   */
   457    461   static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){
   458    462     Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor;
   459    463     Fts5VocabTable *pTab = (Fts5VocabTable*)pCursor->pVtab;
   460    464     int rc = SQLITE_OK;
   461         -  int nCol = pCsr->pConfig->nCol;
          465  +  int nCol = pCsr->pFts5->pConfig->nCol;
   462    466   
   463    467     pCsr->rowid++;
   464    468   
   465    469     if( pTab->eType==FTS5_VOCAB_INSTANCE ){
   466    470       return fts5VocabInstanceNext(pCsr);
   467    471     }
   468    472   
................................................................................
   476    480       if( sqlite3Fts5IterEof(pCsr->pIter) ){
   477    481         pCsr->bEof = 1;
   478    482       }else{
   479    483         const char *zTerm;
   480    484         int nTerm;
   481    485   
   482    486         zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
          487  +      assert( nTerm>=0 );
   483    488         if( pCsr->nLeTerm>=0 ){
   484    489           int nCmp = MIN(nTerm, pCsr->nLeTerm);
   485    490           int bCmp = memcmp(pCsr->zLeTerm, zTerm, nCmp);
   486    491           if( bCmp<0 || (bCmp==0 && pCsr->nLeTerm<nTerm) ){
   487    492             pCsr->bEof = 1;
   488    493             return SQLITE_OK;
   489    494           }
................................................................................
   492    497         sqlite3Fts5BufferSet(&rc, &pCsr->term, nTerm, (const u8*)zTerm);
   493    498         memset(pCsr->aCnt, 0, nCol * sizeof(i64));
   494    499         memset(pCsr->aDoc, 0, nCol * sizeof(i64));
   495    500         pCsr->iCol = 0;
   496    501   
   497    502         assert( pTab->eType==FTS5_VOCAB_COL || pTab->eType==FTS5_VOCAB_ROW );
   498    503         while( rc==SQLITE_OK ){
   499         -        int eDetail = pCsr->pConfig->eDetail;
          504  +        int eDetail = pCsr->pFts5->pConfig->eDetail;
   500    505           const u8 *pPos; int nPos;   /* Position list */
   501    506           i64 iPos = 0;               /* 64-bit position read from poslist */
   502    507           int iOff = 0;               /* Current offset within position list */
   503    508   
   504    509           pPos = pCsr->pIter->pData;
   505    510           nPos = pCsr->pIter->nData;
   506    511   
................................................................................
   515    520               break;
   516    521   
   517    522             case FTS5_VOCAB_COL:
   518    523               if( eDetail==FTS5_DETAIL_FULL ){
   519    524                 int iCol = -1;
   520    525                 while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff, &iPos) ){
   521    526                   int ii = FTS5_POS2COLUMN(iPos);
   522         -                pCsr->aCnt[ii]++;
   523    527                   if( iCol!=ii ){
   524    528                     if( ii>=nCol ){
   525    529                       rc = FTS5_CORRUPT;
   526    530                       break;
   527    531                     }
   528    532                     pCsr->aDoc[ii]++;
   529    533                     iCol = ii;
   530    534                   }
          535  +                pCsr->aCnt[ii]++;
   531    536                 }
   532    537               }else if( eDetail==FTS5_DETAIL_COLUMNS ){
   533    538                 while( 0==sqlite3Fts5PoslistNext64(pPos, nPos, &iOff,&iPos) ){
   534    539                   assert_nc( iPos>=0 && iPos<nCol );
   535    540                   if( iPos>=nCol ){
   536    541                     rc = FTS5_CORRUPT;
   537    542                     break;
................................................................................
   552    557           if( rc==SQLITE_OK ){
   553    558             rc = sqlite3Fts5IterNextScan(pCsr->pIter);
   554    559           }
   555    560           if( pTab->eType==FTS5_VOCAB_INSTANCE ) break;
   556    561   
   557    562           if( rc==SQLITE_OK ){
   558    563             zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
   559         -          if( nTerm!=pCsr->term.n || memcmp(zTerm, pCsr->term.p, nTerm) ){
          564  +          if( nTerm!=pCsr->term.n 
          565  +          || (nTerm>0 && memcmp(zTerm, pCsr->term.p, nTerm)) 
          566  +          ){
   560    567               break;
   561    568             }
   562    569             if( sqlite3Fts5IterEof(pCsr->pIter) ) break;
   563    570           }
   564    571         }
   565    572       }
   566    573     }
   567    574   
   568    575     if( rc==SQLITE_OK && pCsr->bEof==0 && pTab->eType==FTS5_VOCAB_COL ){
   569    576       while( pCsr->aDoc[pCsr->iCol]==0 ) pCsr->iCol++;
   570         -    assert( pCsr->iCol<pCsr->pConfig->nCol );
          577  +    assert( pCsr->iCol<pCsr->pFts5->pConfig->nCol );
   571    578     }
   572    579     return rc;
   573    580   }
   574    581   
   575    582   /*
   576    583   ** This is the xFilter implementation for the virtual table.
   577    584   */
................................................................................
   610    617     }else{
   611    618       if( pGe ){
   612    619         zTerm = (const char *)sqlite3_value_text(pGe);
   613    620         nTerm = sqlite3_value_bytes(pGe);
   614    621       }
   615    622       if( pLe ){
   616    623         const char *zCopy = (const char *)sqlite3_value_text(pLe);
          624  +      if( zCopy==0 ) zCopy = "";
   617    625         pCsr->nLeTerm = sqlite3_value_bytes(pLe);
   618    626         pCsr->zLeTerm = sqlite3_malloc(pCsr->nLeTerm+1);
   619    627         if( pCsr->zLeTerm==0 ){
   620    628           rc = SQLITE_NOMEM;
   621    629         }else{
   622    630           memcpy(pCsr->zLeTerm, zCopy, pCsr->nLeTerm+1);
   623    631         }
   624    632       }
   625    633     }
   626    634   
   627    635     if( rc==SQLITE_OK ){
   628         -    rc = sqlite3Fts5IndexQuery(pCsr->pIndex, zTerm, nTerm, f, 0, &pCsr->pIter);
          636  +    Fts5Index *pIndex = pCsr->pFts5->pIndex;
          637  +    rc = sqlite3Fts5IndexQuery(pIndex, zTerm, nTerm, f, 0, &pCsr->pIter);
   629    638     }
   630    639     if( rc==SQLITE_OK && eType==FTS5_VOCAB_INSTANCE ){
   631    640       rc = fts5VocabInstanceNewTerm(pCsr);
   632    641     }
   633         -  if( rc==SQLITE_OK 
   634         -   && !pCsr->bEof 
   635         -   && (eType!=FTS5_VOCAB_INSTANCE || pCsr->pConfig->eDetail!=FTS5_DETAIL_NONE)
          642  +  if( rc==SQLITE_OK && !pCsr->bEof 
          643  +   && (eType!=FTS5_VOCAB_INSTANCE 
          644  +    || pCsr->pFts5->pConfig->eDetail!=FTS5_DETAIL_NONE)
   636    645     ){
   637    646       rc = fts5VocabNextMethod(pCursor);
   638    647     }
   639    648   
   640    649     return rc;
   641    650   }
   642    651   
................................................................................
   651    660   
   652    661   static int fts5VocabColumnMethod(
   653    662     sqlite3_vtab_cursor *pCursor,   /* Cursor to retrieve value from */
   654    663     sqlite3_context *pCtx,          /* Context for sqlite3_result_xxx() calls */
   655    664     int iCol                        /* Index of column to read value from */
   656    665   ){
   657    666     Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor;
   658         -  int eDetail = pCsr->pConfig->eDetail;
          667  +  int eDetail = pCsr->pFts5->pConfig->eDetail;
   659    668     int eType = ((Fts5VocabTable*)(pCursor->pVtab))->eType;
   660    669     i64 iVal = 0;
   661    670   
   662    671     if( iCol==0 ){
   663    672       sqlite3_result_text(
   664    673           pCtx, (const char*)pCsr->term.p, pCsr->term.n, SQLITE_TRANSIENT
   665    674       );
   666    675     }else if( eType==FTS5_VOCAB_COL ){
   667    676       assert( iCol==1 || iCol==2 || iCol==3 );
   668    677       if( iCol==1 ){
   669    678         if( eDetail!=FTS5_DETAIL_NONE ){
   670         -        const char *z = pCsr->pConfig->azCol[pCsr->iCol];
          679  +        const char *z = pCsr->pFts5->pConfig->azCol[pCsr->iCol];
   671    680           sqlite3_result_text(pCtx, z, -1, SQLITE_STATIC);
   672    681         }
   673    682       }else if( iCol==2 ){
   674    683         iVal = pCsr->aDoc[pCsr->iCol];
   675    684       }else{
   676    685         iVal = pCsr->aCnt[pCsr->iCol];
   677    686       }
................................................................................
   691    700         case 2: {
   692    701           int ii = -1;
   693    702           if( eDetail==FTS5_DETAIL_FULL ){
   694    703             ii = FTS5_POS2COLUMN(pCsr->iInstPos);
   695    704           }else if( eDetail==FTS5_DETAIL_COLUMNS ){
   696    705             ii = (int)pCsr->iInstPos;
   697    706           }
   698         -        if( ii>=0 && ii<pCsr->pConfig->nCol ){
   699         -          const char *z = pCsr->pConfig->azCol[ii];
          707  +        if( ii>=0 && ii<pCsr->pFts5->pConfig->nCol ){
          708  +          const char *z = pCsr->pFts5->pConfig->azCol[ii];
   700    709             sqlite3_result_text(pCtx, z, -1, SQLITE_STATIC);
   701    710           }
   702    711           break;
   703    712         }
   704    713         default: {
   705    714           assert( iCol==3 );
   706    715           if( eDetail==FTS5_DETAIL_FULL ){
................................................................................
   751    760       /* xCommit       */ 0,
   752    761       /* xRollback     */ 0,
   753    762       /* xFindFunction */ 0,
   754    763       /* xRename       */ 0,
   755    764       /* xSavepoint    */ 0,
   756    765       /* xRelease      */ 0,
   757    766       /* xRollbackTo   */ 0,
          767  +    /* xShadowName   */ 0
   758    768     };
   759    769     void *p = (void*)pGlobal;
   760    770   
   761    771     return sqlite3_create_module_v2(db, "fts5vocab", &fts5Vocab, p, 0);
   762    772   }
   763         -
   764         -

Changes to ext/fts5/test/fts5aa.test.

    34     34     t1_docsize {CREATE TABLE 't1_docsize'(id INTEGER PRIMARY KEY, sz BLOB)}
    35     35     t1_config {CREATE TABLE 't1_config'(k PRIMARY KEY, v) WITHOUT ROWID}
    36     36   }
    37     37   
    38     38   do_execsql_test 1.1 {
    39     39     DROP TABLE t1;
    40     40     SELECT name, sql FROM sqlite_master;
    41         -} {
    42         -}
           41  +} {}
    43     42   
    44     43   #-------------------------------------------------------------------------
    45     44   #
    46     45   
    47     46   do_execsql_test 2.0 {
    48     47     CREATE VIRTUAL TABLE t1 USING fts5(x, y, detail=%DETAIL%);
    49     48   }
................................................................................
   405    404     }
   406    405     set nRow
   407    406   } {200}
   408    407   
   409    408   do_execsql_test 15.0 {
   410    409     INSERT INTO t1(t1) VALUES('integrity-check');
   411    410   }
          411  +sqlite3_db_config db DEFENSIVE 0
   412    412   do_execsql_test 15.1 {
   413    413     UPDATE t1_content SET c1 = 'xyz xyz xyz xyz xyz abc' WHERE rowid = 1;
   414    414   }
   415    415   do_catchsql_test 15.2 {
   416    416     INSERT INTO t1(t1) VALUES('integrity-check');
   417    417   } {1 {database disk image is malformed}}
   418    418   

Changes to ext/fts5/test/fts5ai.test.

    47     47       ROLLBACK TO one;
    48     48     COMMIT;
    49     49   }
    50     50   
    51     51   do_execsql_test 1.2 {
    52     52     INSERT INTO t1(t1) VALUES('integrity-check');
    53     53   }
           54  +
           55  +do_execsql_test 1.3 {
           56  +  SAVEPOINT one;
           57  +    INSERT INTO t1 VALUES('v w x');
           58  +  ROLLBACK TO one;
           59  +}
    54     60   }
    55     61   
    56     62   
    57     63   finish_test

Changes to ext/fts5/test/fts5ak.test.

   139    139     --   '[a b c d e]'
   140    140     SELECT highlight(ft, 0, '[', ']') FROM ft WHERE ft MATCH 'a+b+c AND c+d+e';
   141    141   } {
   142    142     {[a b c] x [c d e]}
   143    143     {[a b c] [c d e]}
   144    144     {[a b c d e]}
   145    145   }
          146  +
          147  +do_execsql_test 3.2 {
          148  +  SELECT highlight(ft, 0, NULL, NULL) FROM ft WHERE ft MATCH 'a+b+c AND c+d+e';
          149  +} {
          150  +  {a b c x c d e}
          151  +  {a b c c d e}
          152  +  {a b c d e}
          153  +}
   146    154   
   147    155   }
   148    156   
   149    157   finish_test

Added ext/fts5/test/fts5circref.test.

            1  +# 2018 Dec 22
            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 FTS5 module.
           13  +#
           14  +
           15  +source [file join [file dirname [info script]] fts5_common.tcl]
           16  +set testprefix fts5circref
           17  +
           18  +# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
           19  +ifcapable !fts5 {
           20  +  finish_test
           21  +  return
           22  +}
           23  +
           24  +do_execsql_test 1.0 {
           25  +  CREATE VIRTUAL TABLE tt USING fts5(a);
           26  +  SELECT name FROM sqlite_master ORDER BY 1;
           27  +} {
           28  +  tt tt_config tt_content tt_data tt_docsize tt_idx
           29  +}
           30  +db_save_and_close
           31  +
           32  +foreach {tn schema sql} {
           33  +  1 {
           34  +    CREATE TRIGGER tr1 AFTER INSERT ON tt_config BEGIN
           35  +      SELECT * FROM tt;
           36  +    END;
           37  +  } {
           38  +    INSERT INTO tt(tt, rank) VALUES('usermerge', 4);
           39  +  }
           40  +
           41  +  2 {
           42  +    CREATE TRIGGER tr1 AFTER INSERT ON tt_docsize BEGIN
           43  +      SELECT * FROM tt;
           44  +    END;
           45  +  } {
           46  +    INSERT INTO tt(a) VALUES('one two three');
           47  +  }
           48  +
           49  +  3 {
           50  +    CREATE TRIGGER tr1 AFTER INSERT ON tt_content BEGIN
           51  +      SELECT * FROM tt;
           52  +    END;
           53  +  } {
           54  +    INSERT INTO tt(a) VALUES('one two three');
           55  +  }
           56  +
           57  +  4 {
           58  +    CREATE TRIGGER tr1 AFTER INSERT ON tt_data BEGIN
           59  +      SELECT * FROM tt;
           60  +    END;
           61  +  } {
           62  +    INSERT INTO tt(a) VALUES('one two three');
           63  +  }
           64  +
           65  +  5 {
           66  +    CREATE TRIGGER tr1 AFTER INSERT ON tt_idx BEGIN
           67  +      SELECT * FROM tt;
           68  +    END;
           69  +  } {
           70  +    INSERT INTO tt(a) VALUES('one two three');
           71  +  }
           72  +} {
           73  +  db_restore_and_reopen
           74  +  do_execsql_test 1.1.$tn.1 $schema
           75  +  do_catchsql_test 1.1.$tn.2 $sql {1 {SQL logic error}}
           76  +  db close
           77  +}
           78  +
           79  +
           80  +finish_test

Changes to ext/fts5/test/fts5connect.test.

   240    240   
   241    241     do_execsql_test 4.$tn.3 {
   242    242       INSERT INTO ft3(ft3) VALUES('integrity-check');
   243    243     }
   244    244   }
   245    245   
   246    246   finish_test
   247         -

Changes to ext/fts5/test/fts5corrupt.test.

    37     37     fts5_level_segs t1
    38     38   } {1}
    39     39   db_save
    40     40   
    41     41   do_execsql_test 1.2 { INSERT INTO t1(t1) VALUES('integrity-check') }
    42     42   set segid [lindex [fts5_level_segids t1] 0]
    43     43   
           44  +sqlite3_db_config db DEFENSIVE 0
    44     45   do_test 1.3 {
    45     46     execsql {
    46     47       DELETE FROM t1_data WHERE rowid = fts5_rowid('segment', $segid, 4);
    47     48     }
    48     49     catchsql { INSERT INTO t1(t1) VALUES('integrity-check') }
    49     50   } {1 {database disk image is malformed}}
    50     51   
    51     52   do_test 1.4 {
    52     53     db_restore_and_reopen
           54  +  sqlite3_db_config db DEFENSIVE 0
    53     55     execsql {
    54     56       UPDATE t1_data set block = X'00000000' || substr(block, 5) WHERE
    55     57       rowid = fts5_rowid('segment', $segid, 4);
    56     58     }
    57     59     catchsql { INSERT INTO t1(t1) VALUES('integrity-check') }
    58     60   } {1 {database disk image is malformed}}
    59     61   
................................................................................
    85     87     INSERT INTO t3 VALUES('three o');
    86     88     INSERT INTO t3 VALUES('four e');
    87     89     INSERT INTO t3 VALUES('five o');
    88     90   }
    89     91   do_execsql_test 3.1 {
    90     92     SELECT * FROM t3 WHERE t3 MATCH 'o'
    91     93   } {{one o} {three o} {five o}}
    92         -
           94  +sqlite3_db_config db DEFENSIVE 0
    93     95   do_catchsql_test 3.1 {
    94     96     DELETE FROM t3_content WHERE rowid = 3;
    95     97     SELECT * FROM t3 WHERE t3 MATCH 'o';
    96     98   } {1 {database disk image is malformed}}
    97     99   
    98    100   finish_test

Changes to ext/fts5/test/fts5corrupt2.test.

    95     95   # Also tested is that "MATCH 'x*'" does not crash and sometimes reports
    96     96   # corruption. It may not report the db as corrupt because truncating the
    97     97   # final leaf to some sizes may create a valid leaf page.
    98     98   #
    99     99   set lrowid [db one {SELECT max(rowid) FROM t1_data WHERE (rowid & $mask)=0}] 
   100    100   set nbyte [db one {SELECT length(block) FROM t1_data WHERE rowid=$lrowid}]
   101    101   set all [db eval {SELECT rowid FROM t1}]
          102  +sqlite3_db_config db DEFENSIVE 0
   102    103   for {set i [expr $nbyte-2]} {$i>=0} {incr i -1} {
   103    104     do_execsql_test 2.$i.1 {
   104    105       BEGIN;
   105    106         UPDATE t1_data SET block = substr(block, 1, $i) WHERE rowid=$lrowid;
   106    107     }
   107    108   
   108    109     do_catchsql_test 2.$i.2 {
................................................................................
   244    245   
   245    246       execsql ROLLBACK
   246    247     }
   247    248   }
   248    249   
   249    250   #--------------------------------------------------------------------
   250    251   reset_db
          252  +sqlite3_db_config db DEFENSIVE 0
   251    253   do_execsql_test 6.1 {
   252    254     CREATE VIRTUAL TABLE x5 USING fts5(tt);
   253    255     INSERT INTO x5 VALUES('a');
   254    256     INSERT INTO x5 VALUES('a a');
   255    257     INSERT INTO x5 VALUES('a a a');
   256    258     INSERT INTO x5 VALUES('a a a a');
   257    259   

Changes to ext/fts5/test/fts5corrupt3.test.

    19     19   
    20     20   # If SQLITE_ENABLE_FTS5 is defined, omit this file.
    21     21   ifcapable !fts5 {
    22     22     finish_test
    23     23     return
    24     24   }
    25     25   sqlite3_fts5_may_be_corrupt 1
           26  +database_may_be_corrupt
    26     27   
    27     28   proc create_t1 {} {
    28     29     expr srand(0)
    29     30     db func rnddoc fts5_rnddoc
    30     31     db eval {
    31     32       CREATE VIRTUAL TABLE t1 USING fts5(x);
    32     33       INSERT INTO t1(t1, rank) VALUES('pgsz', 64);
    33     34       WITH ii(i) AS (SELECT 1 UNION SELECT i+1 FROM ii WHERE i<100)
    34     35         INSERT INTO t1 SELECT rnddoc(10) FROM ii;
    35     36     }
    36     37   }
    37     38   
    38         -if 1 {
    39         -
    40     39   # Create a simple FTS5 table containing 100 documents. Each document 
    41     40   # contains 10 terms, each of which start with the character "x".
    42     41   #
    43     42   do_test 1.0 { create_t1 } {}
    44     43   
    45     44   do_test 1.1 {
    46     45     # Pick out the rowid of the right-most b-tree leaf in the new segment.
................................................................................
    47     46     set rowid [db one {
    48     47       SELECT max(rowid) FROM t1_data WHERE ((rowid>>31) & 0x0F)==1
    49     48     }]
    50     49     set L [db one {SELECT length(block) FROM t1_data WHERE rowid = $rowid}]
    51     50     set {} {}
    52     51   } {} 
    53     52   
           53  +sqlite3_db_config db DEFENSIVE 0
    54     54   for {set i 0} {$i < $L} {incr i} {
    55     55     do_test 1.2.$i {
    56     56       catchsql {
    57     57         BEGIN;
    58     58         UPDATE t1_data SET block = substr(block, 1, $i) WHERE id = $rowid;
    59     59         INSERT INTO t1(t1) VALUES('integrity-check');
    60     60       }
................................................................................
    82     82   
    83     83   
    84     84   #-------------------------------------------------------------------------
    85     85   # Test that missing leaf pages are recognized as corruption.
    86     86   #
    87     87   reset_db
    88     88   do_test 3.0 { create_t1 } {}
           89  +sqlite3_db_config db DEFENSIVE 0
    89     90   
    90     91   do_execsql_test 3.1 {
    91     92     SELECT count(*) FROM t1_data;
    92     93   } {105}
    93     94   
    94     95   proc do_3_test {tn} {
    95     96     set i 0
................................................................................
   154    155   
   155    156   do_3_test 3.10
   156    157   
   157    158   #-------------------------------------------------------------------------
   158    159   # Test that segments that end unexpectedly are identified as corruption.
   159    160   #
   160    161   reset_db
          162  +sqlite3_db_config db DEFENSIVE 0
   161    163   do_test 4.0 {
   162    164     execsql { 
   163    165       CREATE VIRTUAL TABLE t1 USING fts5(x);
   164    166       INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
   165    167     }
   166    168     for {set i 0} {$i < 100} {incr i} {
   167    169       set rnd [expr int(rand() * 100)]
................................................................................
   178    180     set end [lindex $var end]
   179    181     if {$end<=$i} break
   180    182     lset var end [expr $end - $i]
   181    183     set struct [binary format c* $var]
   182    184   
   183    185     db close
   184    186     sqlite3 db test.db
          187  +  sqlite3_db_config db DEFENSIVE 0
   185    188   
   186    189     db eval {
   187    190       BEGIN;
   188    191       UPDATE t1_data SET block = $struct WHERE id=10;
   189    192     }
   190    193     do_test 4.1.$i {
   191    194       incr nErr [catch { db eval { SELECT rowid FROM t1 WHERE t1 MATCH 'x*' } }]
................................................................................
   253    256       catch { db eval ROLLBACK }
   254    257     }
   255    258   }
   256    259   
   257    260   #------------------------------------------------------------------------
   258    261   #
   259    262   reset_db
          263  +sqlite3_db_config db DEFENSIVE 0
   260    264   do_execsql_test 6.1.0 {
   261    265     CREATE VIRTUAL TABLE t1 USING fts5(a);
   262    266     INSERT INTO t1 VALUES('bbbbb ccccc');
   263    267     SELECT quote(block) FROM t1_data WHERE rowid>100;
   264    268   } {X'000000180630626262626201020201056363636363010203040A'}
   265    269   do_execsql_test 6.1.1 {
   266    270     UPDATE t1_data SET block = 
................................................................................
   269    273   }
   270    274   do_catchsql_test 6.1.2 {
   271    275     INSERT INTO t1(t1) VALUES('integrity-check');
   272    276   } {1 {database disk image is malformed}}
   273    277   
   274    278   #-------
   275    279   reset_db
          280  +sqlite3_db_config db DEFENSIVE 0
   276    281   do_execsql_test 6.2.0 {
   277    282     CREATE VIRTUAL TABLE t1 USING fts5(a);
   278    283     INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
   279    284     INSERT INTO t1 VALUES('aa bb cc dd ee');
   280    285     SELECT pgno, quote(term) FROM t1_idx;
   281    286   } {2 X'' 4 X'3064'}
   282    287   do_execsql_test 6.2.1 {
................................................................................
   284    289   }
   285    290   do_catchsql_test 6.2.2 {
   286    291     INSERT INTO t1(t1) VALUES('integrity-check');
   287    292   } {1 {database disk image is malformed}}
   288    293   
   289    294   #-------
   290    295   reset_db
          296  +sqlite3_db_config db DEFENSIVE 0
   291    297   do_execsql_test 6.3.0 {
   292    298     CREATE VIRTUAL TABLE t1 USING fts5(a);
   293    299     INSERT INTO t1 VALUES('abc abcdef abcdefghi');
   294    300     SELECT quote(block) FROM t1_data WHERE id>100;
   295    301   }    {X'0000001C043061626301020204036465660102030703676869010204040808'}
   296    302   do_execsql_test 6.3.1 {
   297    303     BEGIN;
................................................................................
   358    364       INSERT INTO t5 VALUES( rnddoc(10000) );
   359    365       INSERT INTO t5 VALUES( rnddoc(10000) );
   360    366       INSERT INTO t5 VALUES( rnddoc(10000) );
   361    367       INSERT INTO t5(t5) VALUES('optimize');
   362    368     }
   363    369   } {}
   364    370   
          371  +sqlite3_db_config db DEFENSIVE 0
   365    372   do_test 7.1 {
   366    373     foreach i [db eval { SELECT rowid FROM t5_data WHERE rowid>100 }] {
   367    374       db eval BEGIN  
   368    375       db eval {DELETE FROM t5_data WHERE rowid = $i}
   369    376       set r [catchsql { INSERT INTO t5(t5) VALUES('integrity-check')} ]
   370    377       if {$r != "1 {database disk image is malformed}"} { error $r }
   371    378       db eval ROLLBACK  
   372    379     }
   373    380   } {}
   374    381   
   375         -}
   376         -
   377    382   #------------------------------------------------------------------------
   378    383   # Corruption within the structure record.
   379    384   #
   380    385   reset_db
   381    386   do_execsql_test 8.1 {
   382    387     CREATE VIRTUAL TABLE t1 USING fts5(x, y);
   383    388     INSERT INTO t1 VALUES('one', 'two');
   384    389   }
   385    390   
          391  +sqlite3_db_config db DEFENSIVE 0
   386    392   do_test 9.1.1 {
   387    393     set    blob "12345678"    ;# cookie
   388    394     append blob "0105"        ;# 1 level, total of 5 segments
   389    395     append blob "06"          ;# write counter
   390    396     append blob "0002"        ;# first level has 0 segments merging, 2 other.
   391    397     append blob "450108"      ;# first segment
   392    398     execsql "REPLACE INTO t1_data VALUES(10, X'$blob')"
................................................................................
   402    408     append blob "0001"        ;# first level has 0 segments merging, 1 other.
   403    409     append blob "450108"      ;# first segment
   404    410     execsql "REPLACE INTO t1_data VALUES(10, X'$blob')"
   405    411   } {}
   406    412   do_catchsql_test 9.2.2 {
   407    413     SELECT * FROM t1('one AND two');
   408    414   } {1 {database disk image is malformed}}
          415  +
          416  +#-------------------------------------------------------------------------
          417  +reset_db
          418  +do_test 10.0 {
          419  +  sqlite3 db {}
          420  +  db deserialize [decode_hexdb {
          421  +| size 32768 pagesize 4096 filename c9.db
          422  +| page 1 offset 0
          423  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          424  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
          425  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 04   ................
          426  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
          427  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
          428  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          429  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          430  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          431  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          432  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          433  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          434  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          435  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          436  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          437  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
          438  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
          439  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          440  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          441  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          442  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          443  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          444  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          445  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          446  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          447  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          448  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          449  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          450  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
          451  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
          452  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
          453  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
          454  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
          455  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
          456  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
          457  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
          458  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
          459  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
          460  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
          461  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
          462  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
          463  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
          464  +| page 2 offset 4096
          465  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
          466  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
          467  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
          468  +|   4048: 63 6b 01 02 02 04 02 66 74 02 06 36 b0 a0 10 21   ck.....ft..6...!
          469  +|   4064: d6 f7 07 46 96 d6 97 a6 05 01 03 00 10 03 03 0f   ...F............
          470  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
          471  +| page 3 offset 8192
          472  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
          473  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
          474  +| page 4 offset 12288
          475  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
          476  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
          477  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
          478  +| page 5 offset 16384
          479  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f4 0f ee 00 00   ................
          480  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
          481  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
          482  +| page 6 offset 20480
          483  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
          484  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
          485  +| page 7 offset 24576
          486  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
          487  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
          488  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
          489  +|   4080: 68 65 62 6c 65 74 31 74 31 43 52 45 41 54 45 20   heblet1t1CREATE 
          490  +| page 8 offset 28672
          491  +|      0: 56 49 52 54 55 41 4c 20 54 41 42 4c 45 20 74 31   VIRTUAL TABLE t1
          492  +|     16: 20 55 53 49 4e 47 20 66 74 73 35 28 63 6f 6e 74    USING fts5(cont
          493  +|     32: 65 6e 74 29 0d 00 00 00 03 0f bd 00 0f e8 0f ef   ent)............
          494  +|     48: 0f bd 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
          495  +| end c9.db
          496  +  }]
          497  +} {}
          498  +do_catchsql_test 10.1 {
          499  +  SELECT * FROM t1 WHERE t1 MATCH 'abandon';
          500  +} {1 {database disk image is malformed}}
          501  +
          502  +#-------------------------------------------------------------------------
          503  +#
          504  +reset_db
          505  +do_test 11.0 {
          506  +  sqlite3 db {}
          507  +  db deserialize [decode_hexdb {
          508  +| size 28672 pagesize 4096 filename c10b.db
          509  +| page 1 offset 0
          510  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          511  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
          512  +|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
          513  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
          514  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
          515  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
          516  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          517  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          518  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          519  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          520  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          521  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          522  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          523  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          524  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          525  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
          526  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
          527  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          528  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          529  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          530  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          531  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          532  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          533  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          534  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          535  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          536  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          537  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          538  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
          539  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
          540  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
          541  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
          542  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
          543  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
          544  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
          545  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
          546  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 44 d9   (id INTEGER PRD.
          547  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
          548  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
          549  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
          550  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
          551  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
          552  +| page 2 offset 4096
          553  +|      0: 0d 00 00 00 06 0f 59 00 0f e8 0f ef 0f bd 0f b0   ......Y.........
          554  +|     16: 0f 73 0f 59 00 00 00 00 00 00 00 00 00 00 00 00   .s.Y............
          555  +|   3920: 00 00 00 00 00 00 00 00 00 13 84 80 80 80 80 04   ................
          556  +|   3936: 03 01 2a 0a 00 00 00 00 01 02 02 00 02 01 01 01   ..*.............
          557  +|   3952: 02 01 01 36 84 80 80 80 80 03 03 05 66 00 40 00   ...6........f.@.
          558  +|   3968: 00 00 01 00 00 00 29 07 30 61 63 74 69 76 65 04   ......).0active.
          559  +|   3984: 02 02 02 03 74 6f 6d 06 02 02 05 02 69 63 07 02   ....tom.....ic..
          560  +|   4000: 02 01 06 62 6f 6f 6d 65 72 05 02 02 04 0b 08 07   ...boomer.......
          561  +|   4016: 06 84 80 80 80 80 02 03 01 10 01 07 07 24 84 80   .............$..
          562  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
          563  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
          564  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
          565  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
          566  +| page 3 offset 8192
          567  +|      0: 0a 00 00 00 02 0f f3 00 0f fa 0f f3 00 00 00 00   ................
          568  +|   4080: 00 00 00 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
          569  +| page 4 offset 12288
          570  +|      0: 0d 00 00 00 07 0f b6 00 0f f6 0f ec 0f e0 0f d5   ................
          571  +|     16: 0f ca 0f c1 0f b6 00 00 00 00 00 00 00 00 00 00   ................
          572  +|   4016: 00 00 00 00 00 00 09 07 03 00 19 61 74 6f 6d 69   ...........atomi
          573  +|   4032: 63 07 06 03 00 15 61 74 6f 6d 09 05 03 00 19 62   c.....atom.....b
          574  +|   4048: 6f 6f 6d 65 72 09 04 03 00 19 61 63 74 69 76 65   oomer.....active
          575  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
          576  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
          577  +| page 5 offset 16384
          578  +|      0: 0d 00 00 00 07 0f d6 00 0f fa 0f f4 0f ee 0f e8   ................
          579  +|     16: 0f e2 0f dc 0f d6 00 00 00 00 00 00 00 00 00 00   ................
          580  +|   4048: 00 00 00 00 00 00 04 07 03 00 0e 01 04 06 03 00   ................
          581  +|   4064: 0e 01 04 05 03 00 0e 01 04 04 03 00 0e 01 04 03   ................
          582  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
          583  +| page 6 offset 20480
          584  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
          585  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
          586  +| page 7 offset 24576
          587  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
          588  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
          589  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
          590  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
          591  +| end c10b.db
          592  +}]} {}
          593  +
          594  +# This returns SQLITE_CONSTRAINT instead of SQLITE_CORRUPT. The problem is
          595  +# that the corrupted structure-record leads fts5 to try to use a segment-id
          596  +# that is already in use. This is caught by the PRIMARY KEY constraint on
          597  +# the %_idx table.
          598  +#
          599  +do_catchsql_test 11.1 {
          600  +  UPDATE t1 SET content='abc' WHERE content='boomer';
          601  +} {1 {constraint failed}}
          602  +
          603  +#-------------------------------------------------------------------------
          604  +#
          605  +reset_db
          606  +do_test 12.0 {
          607  +  sqlite3 db {}
          608  +  db deserialize [decode_hexdb {
          609  +| size 28672 pagesize 4096 filename c2.db
          610  +| page 1 offset 0
          611  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          612  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
          613  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00   ................
          614  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
          615  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
          616  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          617  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          618  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          619  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          620  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          621  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          622  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          623  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          624  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          625  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
          626  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
          627  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          628  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          629  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          630  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          631  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          632  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          633  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          634  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          635  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          636  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          637  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          638  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
          639  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
          640  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
          641  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
          642  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
          643  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
          644  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
          645  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
          646  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
          647  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
          648  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
          649  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
          650  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
          651  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
          652  +| page 2 offset 4096
          653  +|      0: 0d 00 00 00 03 0f bd 00 0f d8 0f ef 0f bd 00 00   ................
          654  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
          655  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
          656  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
          657  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
          658  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 20 01 01 01 01   ...$....... ....
          659  +| page 3 offset 8192
          660  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
          661  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
          662  +| page 4 offset 12288
          663  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 3f e0   ..............?.
          664  +|     16: a0 30 30 01 b6 16 26 16 e6 46 f6 e0 80 20 30 01   .00...&..F... 0.
          665  +|     32: 76 16 26 16 67 40 80 10 30 01 76 16 26 16 36 b0   v.&.g@..0.v.&.6.
          666  +|     48: d0 00 00 00 30 fe e0 00 ff a0 ff 40 fe 00 00 00   ....0......@....
          667  +| page 5 offset 16384
          668  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
          669  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
          670  +| page 6 offset 20480
          671  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
          672  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
          673  +| page 7 offset 24576
          674  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
          675  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
          676  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
          677  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
          678  +| end c2.db
          679  +}]} {}
          680  +
          681  +do_catchsql_test 11.1 {
          682  +  SELECT * FROM t1 WHERE t1 MATCH 'abandon';
          683  +} {1 {vtable constructor failed: t1}}
          684  +
          685  +do_catchsql_test 11.2 {
          686  +  INSERT INTO t1(t1, rank) VALUES('merge', 500);
          687  +} {1 {vtable constructor failed: t1}}
          688  +
          689  +#-------------------------------------------------------------------------
          690  +#
          691  +reset_db
          692  +do_test 13.0 {
          693  +  sqlite3 db {}
          694  +  db deserialize [decode_hexdb {
          695  +| size 28672 pagesize 4096 filename c13.db
          696  +| page 1 offset 0
          697  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          698  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
          699  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 04   ................
          700  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
          701  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
          702  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          703  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          704  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          705  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          706  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          707  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          708  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          709  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          710  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          711  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
          712  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
          713  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          714  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          715  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          716  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          717  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          718  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          719  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          720  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          721  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          722  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          723  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          724  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 4f 69 64   ATE TABLE 't1Oid
          725  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
          726  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
          727  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
          728  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
          729  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
          730  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
          731  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
          732  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
          733  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
          734  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
          735  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
          736  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
          737  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
          738  +| page 2 offset 4096
          739  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
          740  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
          741  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
          742  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
          743  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
          744  +|   4080: 0a 03 00 24 00 eb 00 00 00 01 01 01 00 01 01 01   ...$............
          745  +| page 3 offset 8192
          746  +|      0: 01 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00   ................
          747  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
          748  +| page 4 offset 12288
          749  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
          750  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
          751  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
          752  +| page 5 offset 16384
          753  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f2 0f ee 00 00   ................
          754  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
          755  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
          756  +| page 6 offset 20480
          757  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
          758  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
          759  +| page 7 offset 24576
          760  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
          761  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
          762  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
          763  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
          764  +| end c13.db
          765  +SELECT * FROM t1 WHERE t1 MATCH 'abandon';
          766  +}]} {}
          767  +
          768  +do_catchsql_test 13.1 {
          769  +  SELECT * FROM t1 WHERE t1 MATCH 'abandon'; 
          770  +} {1 {vtable constructor failed: t1}}
          771  +
          772  +#-------------------------------------------------------------------------
          773  +reset_db
          774  +do_test 14.0 {
          775  +  sqlite3 db {}
          776  +  db deserialize [decode_hexdb {
          777  +| size 28672 pagesize 4096 filename c14b.db
          778  +| page 1 offset 0
          779  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          780  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
          781  +|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
          782  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
          783  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
          784  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
          785  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          786  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          787  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          788  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          789  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          790  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          791  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          792  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          793  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          794  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
          795  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
          796  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          797  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          798  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          799  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          800  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          801  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          802  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          803  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          804  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          805  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          806  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          807  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
          808  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
          809  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
          810  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
          811  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
          812  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
          813  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
          814  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
          815  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
          816  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
          817  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
          818  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
          819  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
          820  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
          821  +| page 2 offset 4096
          822  +|      0: 0d 0f ef 00 04 0f 18 00 0f e8 0f 18 0f bd 0f 2c   ...............,
          823  +|   3856: 00 00 00 00 00 00 00 00 12 0a 03 00 2a 00 00 00   ............*...
          824  +|   3872: 00 01 02 02 00 02 01 01 01 02 01 01 81 09 88 80   ................
          825  +|   3888: 80 80 80 01 04 00 82 16 00 00 00 79 06 30 61 62   ...........y.0ab
          826  +|   3904: 61 63 6b 08 02 07 04 04 6e 64 6f 6e 08 02 05 02   ack.....ndon....
          827  +|   3920: 05 63 74 69 76 65 04 02 02 04 02 0b 02 04 6c 70   .ctive........lp
          828  +|   3936: 68 61 08 04 02 0a 02 03 74 6b 6d 06 02 02 03 02   ha......tkm.....
          829  +|   3952: 6f 6d 08 02 09 05 02 69 63 07 02 02 01 06 62 61   om.....ic.....ba
          830  +|   3968: 63 6b 75 70 08 02 04 02 05 6f 6f 6d 65 72 05 02   ckup.....oomer..
          831  +|   3984: 02 01 0c 63 68 61 6e 6e 65 62 6f 6f 6d 65 72 08   ...channeboomer.
          832  +|   4000: 02 08 07 01 6c 08 02 03 01 04 74 65 73 74 08 02   ....l.....test..
          833  +|   4016: 06 04 0a 09 0d 0a 08 07 07 0b 0a 11 06 24 84 80   .............$..
          834  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
          835  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
          836  +|   4064: 6f 6e 03 02 02 03 9a 07 05 01 03 00 10 08 11 00   on..............
          837  +|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
          838  +| page 3 offset 8192
          839  +|      0: 0a 00 00 00 02 0f f3 00 0f fa 0f f3 00 00 00 00   ................
          840  +|   4080: 00 00 00 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
          841  +| page 4 offset 12288
          842  +|      0: 0d 00 00 00 08 0f 6a 00 0f f6 0f ec 0f e0 0f d5   ......j.........
          843  +|     16: 0f ca 0f c1 0f b6 0f 6a 00 00 00 00 00 00 00 00   .......j........
          844  +|   3936: 00 00 00 00 00 00 00 00 00 00 4a 08 04 00 81 19   ..........J.....
          845  +|   3952: 61 6c 70 68 61 20 63 68 61 6e 6e 65 6c 20 62 61   alpha channel ba
          846  +|   3968: 63 6b 75 70 20 61 62 61 6e 64 6f 6e 20 74 65 73   ckup abandon tes
          847  +|   3984: 74 20 61 62 61 63 6b 20 63 68 61 6e 6e 65 62 6f   t aback channebo
          848  +|   4000: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
          849  +|   4016: 61 63 74 69 76 65 09 07 03 00 19 61 74 6f 6d 69   active.....atomi
          850  +|   4032: 63 07 06 03 00 15 61 74 6b 6d 09 05 03 00 19 62   c.....atkm.....b
          851  +|   4048: 6f 6f 6d 65 72 09 04 03 00 19 61 63 74 69 76 65   oomer.....active
          852  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
          853  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
          854  +| page 5 offset 16384
          855  +|      0: 0d 00 00 00 08 0f d0 00 0f fa 0f f4 0f ee 0f e8   ................
          856  +|     16: 0f e2 0f dc 0f d6 0f d0 00 00 00 00 00 00 00 00   ................
          857  +|   4048: 04 08 03 00 0e 0a 04 07 03 00 0e 01 04 06 03 00   ................
          858  +|   4064: 0e 01 04 05 03 00 0e 01 04 04 03 00 0e 01 04 03   ................
          859  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
          860  +| page 6 offset 20480
          861  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
          862  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
          863  +| page 7 offset 24576
          864  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
          865  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
          866  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
          867  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
          868  +| end c14b.db
          869  +}]} {}
          870  +
          871  +do_catchsql_test 14.1 {
          872  +  INSERT INTO t1(t1) VALUES('optimize');
          873  +} {1 {database disk image is malformed}}
          874  +
          875  +#---------------------------------------------------------------------------
          876  +#
          877  +reset_db
          878  +do_test 15.0 {
          879  +  sqlite3 db {}
          880  +  db deserialize [decode_hexdb {
          881  +| size 32768 pagesize 4096 filename c16.db
          882  +| page 1 offset 0
          883  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          884  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
          885  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00   ................
          886  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
          887  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
          888  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          889  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          890  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          891  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          892  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          893  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          894  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          895  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          896  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          897  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 00 0f f6 0f ec   ..!!...tabl.....
          898  +|   3680: 0f e0 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ..sizet1_docsize
          899  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          900  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          901  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          902  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          903  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          904  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          905  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          906  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          907  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          908  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          909  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          910  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
          911  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
          912  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
          913  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
          914  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
          915  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
          916  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
          917  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
          918  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
          919  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
          920  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
          921  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
          922  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
          923  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
          924  +| page 2 offset 4096
          925  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
          926  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
          927  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
          928  +|   4048: 63 6b 01 02 02 04 02 66 74 00 02 22 04 04 6e 64   ck.....ft.....nd
          929  +|   4064: 6f 6e 04 67 90 38 2a 07 05 01 03 00 10 03 03 0f   on.g.8*.........
          930  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
          931  +| page 3 offset 8192
          932  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
          933  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
          934  +| page 4 offset 12288
          935  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
          936  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
          937  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
          938  +| page 5 offset 16384
          939  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f4 0f ee 00 00   ................
          940  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
          941  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
          942  +| page 6 offset 20480
          943  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
          944  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
          945  +| page 7 offset 24576
          946  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
          947  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
          948  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
          949  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
          950  +| page 8 offset 28672
          951  +|      0: 03 07 17 19 19 01 81 2d 74 61 62 6c 65 74 31 5f   .......-tablet1_
          952  +|     16: 69 64 78 74 31 5f 69 64 78 03 43 52 45 41 54 45   idxt1_idx.CREATE
          953  +|     32: 20 54 41 42 4c 45 20 27 74 31 5f 66 17 42 03 30    TABLE 't1_f.B.0
          954  +|     48: 01 00 00 10 10 04 02 02 00 00 00 00 00 00 00 00   ................
          955  +|     64: 70 00 00 00 00 00 00 00 00 00 00 00 70 00 00 00   p...........p...
          956  +| end c16.db
          957  +}]} {}
          958  +
          959  +do_catchsql_test 15.1 {
          960  +  INSERT INTO t1(t1) VALUES('integrity-check');
          961  +} {1 {database disk image is malformed}}
          962  +
          963  +#---------------------------------------------------------------------------
          964  +#
          965  +reset_db
          966  +do_test 16.0 {
          967  +  sqlite3 db {}
          968  +  db deserialize [decode_hexdb {
          969  +| size 28672 pagesize 4096 filename c17.db
          970  +| page 1 offset 0
          971  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          972  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
          973  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00   ................
          974  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
          975  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
          976  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          977  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          978  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          979  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          980  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          981  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          982  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          983  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          984  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          985  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
          986  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
          987  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          988  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          989  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          990  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          991  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          992  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          993  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          994  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          995  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          996  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          997  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          998  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
          999  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1000  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1001  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1002  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1003  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1004  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1005  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1006  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1007  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1008  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1009  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1010  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1011  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1012  +| page 2 offset 4096
         1013  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
         1014  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
         1015  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1016  +|   4048: 63 6b 01 02 02 04 02 66 74 00 02 22 04 04 6e 64   ck.....ft.....nd
         1017  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
         1018  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 41 01   ...$..........A.
         1019  +| page 3 offset 8192
         1020  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
         1021  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         1022  +| page 4 offset 12288
         1023  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
         1024  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1025  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         1026  +| page 5 offset 16384
         1027  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f4 0f ee 00 00   ................
         1028  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
         1029  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1030  +| page 6 offset 20480
         1031  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1032  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1033  +| page 7 offset 24576
         1034  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1035  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1036  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1037  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         1038  +| end c17.db
         1039  +}]} {}
         1040  +
         1041  +do_catchsql_test 16.1 {
         1042  +INSERT INTO t1(t1) VALUES('integrity-check');
         1043  +} {1 {vtable constructor failed: t1}}
         1044  +
         1045  +#--------------------------------------------------------------------------
         1046  +reset_db
         1047  +do_test 17.0 {
         1048  +  sqlite3 db {}
         1049  +  db deserialize [decode_hexdb {
         1050  +| size 28672 pagesize 4096 filename c18.db
         1051  +| page 1 offset 0
         1052  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1053  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
         1054  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00   ................
         1055  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1056  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
         1057  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1058  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1059  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1060  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1061  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1062  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1063  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1064  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1065  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1066  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         1067  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1068  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1069  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1070  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1071  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1072  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1073  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1074  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1075  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1076  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1077  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1078  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1079  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1080  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1081  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1082  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1083  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1084  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1085  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1086  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1087  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1088  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1089  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1090  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1091  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1092  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1093  +| page 2 offset 4096
         1094  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
         1095  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
         1096  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1097  +|   4048: 63 6b 01 02 02 04 02 66 74 00 02 22 04 04 6e 64   ck.....ft.....nd
         1098  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
         1099  +|   4080: 0a 03 00 24 00 00 0a aa aa aa aa aa aa aa aa aa   ...$............
         1100  +| page 3 offset 8192
         1101  +|      0: aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa   ................
         1102  +|     16: aa aa aa aa aa aa aa aa 00 00 10 10 10 00 10 10   ................
         1103  +|     32: 10 10 a0 00 00 00 10 ff a0 00 ff 52 05 64 95 25   ...........R.d.%
         1104  +|     48: 45 54 14 c2 05 44 14 24 c4 52 07 43 12 05 55 34   ET...D.$.R.C..U4
         1105  +|     64: 94 e4 72 06 67 47 33 52 86 36 f6 e7 46 56 e7 42   ..r.gG3R.6..FV.B
         1106  +|     80: 90 d0 00 00 00 30 fb d0 00 fe 80 fe f0 fb 00 00   .....0..........
         1107  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         1108  +| page 4 offset 12288
         1109  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
         1110  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1111  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         1112  +| page 5 offset 16384
         1113  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f4 0f ee 00 00   ................
         1114  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
         1115  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1116  +| page 6 offset 20480
         1117  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1118  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1119  +| page 7 offset 24576
         1120  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1121  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1122  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1123  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         1124  +| end c18.db
         1125  +}]} {}
         1126  +
         1127  +do_catchsql_test 17.1 {
         1128  +  SELECT * FROM t1 WHERE t1 MATCH 'abandon';
         1129  +} {1 {vtable constructor failed: t1}}
         1130  +
         1131  +#--------------------------------------------------------------------------
         1132  +reset_db
         1133  +do_test 18.0 {
         1134  +  sqlite3 db {}
         1135  +  db deserialize [decode_hexdb {
         1136  +| size 28672 pagesize 4096 filename c19b.db
         1137  +| page 1 offset 0
         1138  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1139  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
         1140  +|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         1141  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1142  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
         1143  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
         1144  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1145  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1146  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1147  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1148  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1149  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1150  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1151  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1152  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1153  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         1154  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1155  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1156  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1157  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1158  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1159  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1160  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1161  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1162  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1163  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1164  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1165  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1166  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1167  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1168  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1169  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1170  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1171  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1172  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1173  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1174  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1175  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1176  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1177  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1178  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1179  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1180  +| page 2 offset 4096
         1181  +|      0: 0d 09 a6 00 06 09 22 00 0f e8 09 22 0f bd 0f 2c   ...............,
         1182  +|     16: 09 bd 09 3c 00 00 00 00 00 00 00 00 00 00 00 00   ...<............
         1183  +|   2336: 00 00 18 0a 03 00 36 00 00 00 00 01 04 04 00 04   ......6.........
         1184  +|   2352: 01 01 01 02 01 01 03 01 01 04 01 01 63 90 80 80   ............c...
         1185  +|   2368: 80 80 01 04 00 81 4a 00 00 00 56 06 30 61 62 61   ......J...V.0aba
         1186  +|   2384: 63 6b 08 01 04 04 6e 64 6f 6e 03 01 05 01 02 05   ck....ndon......
         1187  +|   2400: 63 74 69 76 65 08 01 02 04 6c 70 68 61 08 01 02   ctive....lpha...
         1188  +|   2416: 03 74 6f 6d 08 01 01 06 62 61 63 6b 75 70 08 01   .tom....backup..
         1189  +|   2432: 01 0c 63 68 61 6e 6e 65 62 6f 6f 6d 65 72 08 01   ..channeboomer..
         1190  +|   2448: 07 01 6c 08 01 01 04 74 65 73 74 08 01 04 09 0a   ..l....test.....
         1191  +|   2464: 09 08 07 0a 10 05 0f 18 00 17 30 00 00 00 00 01   ..........0.....
         1192  +|   2480: 03 03 00 03 01 01 01 02 01 01 03 01 01 8a 53 8c   ..............S.
         1193  +|   2496: 80 80 80 80 01 04 00 95 2a 00 00 05 35 0d 30 30   ........*...5.00
         1194  +|   2512: 31 30 66 66 61 30 30 30 66 66 61 05 02 1c 02 49   10ffa000ffa....I
         1195  +|   2528: 33 34 33 35 32 34 35 34 31 35 34 34 35 32 30 35   3435245415445205
         1196  +|   2544: 34 34 31 34 32 34 63 34 35 32 30 32 37 37 34 33   441424c452027743
         1197  +|   2560: 31 35 66 36 39 36 34 37 38 32 37 32 38 37 33 36   15f6964782728736
         1198  +|   2576: 35 36 37 36 39 36 34 32 63 32 30 37 34 36 35 37   56769642c2074657
         1199  +|   2592: 32 36 64 32 63 32 30 37 30 05 02 12 02 3b 36 31   26d2c2070....;61
         1200  +|   2608: 37 32 31 32 31 30 31 37 37 37 34 36 31 36 32 35   7212101777461625
         1201  +|   2624: 63 36 35 37 34 33 31 35 66 36 33 36 66 36 65 37   c6574315f636f6e7
         1202  +|   2640: 34 36 35 36 65 37 34 37 34 33 31 35 66 36 33 36   4656e7474315f636
         1203  +|   2656: 66 36 65 37 34 36 35 36 65 05 04 07 07 01 04 31   f6e74656e......1
         1204  +|   2672: 66 62 64 05 02 19 01 44 32 34 38 34 38 30 38 30   fbd....D24848080
         1205  +|   2688: 38 30 38 30 30 31 30 33 30 30 34 65 30 30 30 30   80800103004e0000
         1206  +|   2704: 30 30 31 65 30 36 33 30 36 31 36 32 36 31 36 33   001e063061626163
         1207  +|   2720: 36 62 30 31 30 32 30 32 30 34 30 32 36 36 37 34   6b01020204026674
         1208  +|   2736: 30 32 30 32 30 32 30 34 30 34 36 65 05 02 1a 02   02020204046e....
         1209  +|   2752: 03 66 65 72 05 02 1d 01 28 33 65 37 34 36 35 36   .fer....(3e74656
         1210  +|   2768: 65 37 34 32 39 30 64 30 30 30 30 30 30 30 33 30   e74290d000000030
         1211  +|   2784: 66 62 64 30 30 30 66 65 38 30 66 65 66 30 66 62   fbd000fe80fef0fb
         1212  +|   2800: 64 05 02 18 01 4a 34 31 35 32 35 39 32 30 34 62   d....J415259204b
         1213  +|   2816: 34 35 35 39 32 63 32 30 36 32 36 63 36 66 36 33   45592c20626c6f63
         1214  +|   2832: 36 62 32 30 34 32 34 63 34 66 34 32 32 39 33 61   6b20424c4f42293a
         1215  +|   2848: 30 31 30 36 31 37 31 31 31 31 30 38 36 33 37 34   0106171111086374
         1216  +|   2864: 36 31 36 32 36 63 36 35 37 34 33 31 37 34 33 31   61626c6574317431
         1217  +|   2880: 05 02 16 02 49 33 35 32 34 35 34 31 35 34 34 35   ....I35245415445
         1218  +|   2896: 32 30 35 36 34 39 35 32 35 34 35 35 34 31 34 63   205649525455414c
         1219  +|   2912: 32 30 35 34 34 31 34 32 34 63 34 35 32 30 37 34   205441424c452074
         1220  +|   2928: 33 31 6f 30 35 35 35 33 34 39 34 65 34 37 32 30   31o05553494e4720
         1221  +|   2944: 36 36 37 34 37 33 33 35 32 38 36 33 36 66 05 02   6674733528636f..
         1222  +|   2960: 17 02 49 35 32 30 35 34 34 31 34 32 34 63 34 35   ..I5205441424c45
         1223  +|   2976: 32 30 32 37 37 34 33 31 35 66 36 33 36 66 36 65   202774315f636f6e
         1224  +|   2992: 37 34 36 35 36 65 37 34 32 37 32 38 36 39 36 34   74656e7427286964
         1225  +|   3008: 32 30 34 39 34 65 35 34 34 35 34 37 34 35 35 32   20494e5445474552
         1226  +|   3024: 32 30 35 30 35 32 34 39 34 64 34 31 05 02 0e 44   205052494d41...D
         1227  +|   3040: 29 62 30 35 30 37 31 37 32 31 32 31 30 31 38 31   )b05071721210181
         1228  +|   3056: 30 31 37 34 36 31 36 32 36 63 36 35 37 34 33 31   017461626c657431
         1229  +|   3072: 35 66 36 34 36 66 36 33 37 33 05 02 09 01 4a 35   5f646f6373....J5
         1230  +|   3088: 32 34 35 34 31 35 34 34 35 32 30 35 34 34 31 34   2454154452054414
         1231  +|   3104: 32 34 63 34 35 32 30 32 37 37 34 33 31 35 66 36   24c45202774315f6
         1232  +|   3120: 34 36 31 37 34 36 31 32 37 32 38 36 39 36 34 32   4617461272869642
         1233  +|   3136: 30 34 39 34 65 35 34 34 35 34 37 34 35 35 32 32   0494e54454745522
         1234  +|   3152: 30 35 30 35 32 34 39 34 64 05 02 15 03 3a 35 39   05052494d....:59
         1235  +|   3168: 32 30 34 62 34 35 35 39 32 63 32 30 36 33 33 30   204b45592c206330
         1236  +|   3184: 32 39 36 39 30 33 30 37 31 37 31 39 31 39 30 31   2969030717191901
         1237  +|   3200: 38 31 32 64 37 34 36 31 36 32 36 63 36 35 37 34   812d7461626c6574
         1238  +|   3216: 33 31 35 66 36 39 79 79 05 02 0f 02 49 34 32 30   315f69yy....I420
         1239  +|   3232: 35 32 34 66 35 37 34 39 34 34 35 35 30 32 30 37   524f574944550207
         1240  +|   3248: 31 37 31 62 31 62 30 31 38 31 30 31 37 34 36 31   171b1b0181017461
         1241  +|   3264: 36 32 36 63 36 37 37 34 33 31 35 66 36 34 36 31   626c6774315f6461
         1242  +|   3280: 37 34 36 31 37 34 33 31 35 66 36 34 36 31 37 34   746174315f646174
         1243  +|   3296: 36 31 30 32 34 33 05 02 14 02 07 66 36 39 36 34   610243.....f6964
         1244  +|   3312: 37 38 05 02 11 01 4a 36 34 36 66 36 65 30 33 30   78....J646f6e030
         1245  +|   3328: 32 30 32 30 34 30 61 30 37 30 35 30 31 30 33 30   202040a070501030
         1246  +|   3344: 30 31 30 30 33 30 33 30 66 30 61 30 33 30 30 32   01003030f0a03002
         1247  +|   3360: 34 30 30 30 30 30 30 30 30 30 31 30 31 30 31 30   4000000000101010
         1248  +|   3376: 30 30 31 30 31 30 31 30 31 30 61 30 30 30 30 30   0010101010a00000
         1249  +|   3392: 30 05 02 1b 02 49 35 32 37 32 38 36 39 36 34 32   0....I5272869642
         1250  +|   3408: 30 34 39 34 65 35 34 34 35 34 37 34 35 35 32 32   0494e54454745522
         1251  +|   3424: 30 35 30 35 32 34 39 34 64 34 31 35 32 35 39 32   05052494d4152592
         1252  +|   3440: 30 34 62 34 35 35 39 32 63 32 30 37 33 37 61 32   04b45592c20737a2
         1253  +|   3456: 30 34 32 34 63 34 66 34 32 32 39 35 35 30 34 05   0424c4f42295504.
         1254  +|   3472: 04 06 07 02 49 37 36 65 36 66 32 63 32 30 35 30   ....I76e6f2c2050
         1255  +|   3488: 35 32 34 39 34 64 34 31 35 32 35 39 32 30 34 62   52494d415259204b
         1256  +|   3504: 34 35 35 39 32 38 37 33 36 35 36 37 36 39 36 34   4559287365676964
         1257  +|   3520: 32 63 32 30 37 34 36 35 37 32 36 64 32 39 32 39   2c207465726d2929
         1258  +|   3536: 32 30 35 37 34 39 35 34 34 38 34 66 35 35 05 02   20574954484f55..
         1259  +|   3552: 13 02 49 39 37 61 36 35 37 34 33 31 35 66 36 34   ..I97a6574315f64
         1260  +|   3568: 36 66 36 33 37 33 36 39 37 61 36 35 30 35 34 33   6f6373697a650543
         1261  +|   3584: 35 32 34 35 34 31 35 34 34 35 32 30 35 34 34 31   5245415445205441
         1262  +|   3600: 34 32 34 63 34 35 32 30 32 37 37 34 33 31 35 66   424c45202774315f
         1263  +|   3616: 36 34 36 66 36 33 37 33 36 39 37 61 05 04 05 07   646f6373697a....
         1264  +|   3632: 01 0e 37 34 30 34 34 33 35 32 34 35 34 31 35 34   ..74044352454154
         1265  +|   3648: 05 04 08 07 02 49 36 32 39 32 30 35 37 34 39 35   .....I6292057495
         1266  +|   3664: 34 34 38 34 66 35 35 35 34 32 30 35 32 34 66 35   4484f555420524f5
         1267  +|   3680: 37 34 39 34 34 35 62 30 35 30 37 31 37 32 31 32   749445b050717212
         1268  +|   3696: 31 30 31 38 31 30 31 37 34 36 31 36 32 36 63 36   10181017461626c6
         1269  +|   3712: 35 37 34 33 31 35 66 36 34 36 66 36 33 37 33 05   574315f646f6373.
         1270  +|   3728: 02 04 01 06 62 61 63 6b 75 70 05 02 1e 02 05 65   ....backup.....e
         1271  +|   3744: 61 6d 65 72 05 02 02 02 05 6f 6f 6d 65 72 05 01   amer.....oomer..
         1272  +|   3760: 02 40 75 6d 6d 32 34 63 34 35 32 30 32 37 37 34   .@umm24c45202774
         1273  +|   3776: 33 31 35 66 36 33 36 66 36 65 36 36 36 39 36 37   315f636f6e666967
         1274  +|   3792: 32 37 32 38 36 62 32 30 35 30 35 32 34 39 34 64   27286b205052494d
         1275  +|   3808: 34 31 35 32 35 39 32 30 34 62 34 35 35 39 32 63   415259204b45592c
         1276  +|   3824: 32 30 05 02 03 01 04 79 65 6b 72 05 02 10 04 11   20.....yekr.....
         1277  +|   3840: 4e 41 09 49 08 2d 4f 4e 4e 2e 4f 3f 4e 0c 4f 4f   NA.I.-ONN.O?N.OO
         1278  +|   3856: 4e 4f 14 4e 0b 0a 09 45 0f ef 00 14 2a 00 00 00   NO.N...E....*...
         1279  +|   3872: 00 01 02 02 00 02 01 01 01 02 01 01 81 09 88 80   ................
         1280  +|   3888: 80 80 80 01 04 00 82 16 00 00 00 79 06 30 61 62   ...........y.0ab
         1281  +|   3904: 61 63 6b 08 02 07 04 04 6e 64 6f 6e 08 02 05 02   ack.....ndon....
         1282  +|   3920: 05 63 74 69 76 65 04 02 02 04 02 0b 02 04 6c 70   .ctive........lp
         1283  +|   3936: 68 61 08 04 02 0a 02 03 74 6b 6d 06 02 02 03 02   ha......tkm.....
         1284  +|   3952: 6f 6d 08 02 09 05 02 69 63 07 02 02 01 06 62 61   om.....ic.....ba
         1285  +|   3968: 63 6b 75 70 08 02 04 02 05 6f 6f 6d 65 72 05 02   ckup.....oomer..
         1286  +|   3984: 02 01 0c 63 68 61 6e 6e 65 62 6f 6f 6d 65 72 08   ...channeboomer.
         1287  +|   4000: 02 08 07 01 6c 08 02 03 01 04 74 65 73 74 08 02   ....l.....test..
         1288  +|   4016: 06 04 0a 09 0d 0a 08 07 07 0b 0a 11 06 24 84 80   .............$..
         1289  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1290  +|   4048: 63 6b 01 08 02 04 02 66 74 00 02 22 04 04 6e 64   ck.....ft.....nd
         1291  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 06 22 00   on..............
         1292  +|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         1293  +| page 3 offset 8192
         1294  +|      0: 0a 00 00 00 04 0f e5 00 0f fa 0f f3 0f ec 0f e5   ................
         1295  +|   4064: 00 00 00 00 00 06 04 01 0c 01 04 02 06 04 01 0c   ................
         1296  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         1297  +| page 4 offset 12288
         1298  +|      0: 0d 0f 68 00 06 08 98 00 0f f6 0f ec 0f d5 08 98   ..h.............
         1299  +|     16: 0f c1 0f b6 0f 68 0f 68 00 00 00 00 00 00 00 00   .....h.h........
         1300  +|   2192: 00 00 00 00 00 00 00 00 8d 4d 05 04 00 9b 1f 62   .........M.....b
         1301  +|   2208: 65 61 6d 65 72 20 62 75 6d 6d 32 34 63 34 35 32   eamer bumm24c452
         1302  +|   2224: 30 32 37 37 34 33 31 35 66 36 33 36 66 36 65 36   02774315f636f6e6
         1303  +|   2240: 36 36 39 36 37 32 37 32 38 36 62 32 30 35 30 35   6696727286b20505
         1304  +|   2256: 32 34 39 34 64 34 31 35 32 35 39 32 30 34 62 34   2494d415259204b4
         1305  +|   2272: 35 35 39 32 63 32 30 0a 37 36 32 39 32 30 35 37   5592c20.76292057
         1306  +|   2288: 34 39 35 34 34 38 34 66 35 35 35 34 32 30 35 32   4954484f55542052
         1307  +|   2304: 34 66 35 37 34 39 34 34 35 62 30 35 30 37 31 37   4f5749445b050717
         1308  +|   2320: 32 31 32 31 30 31 38 31 30 31 37 34 36 31 36 32   2121018101746162
         1309  +|   2336: 36 63 36 35 37 34 33 31 35 66 36 34 36 66 36 33   6c6574315f646f63
         1310  +|   2352: 37 33 0a 36 39 37 61 36 35 37 34 33 31 35 66 36   73.697a6574315f6
         1311  +|   2368: 34 36 66 36 33 37 33 36 39 37 61 36 35 30 35 34   46f6373697a65054
         1312  +|   2384: 33 35 32 34 35 34 31 35 34 34 35 32 30 35 34 34   3524541544520544
         1313  +|   2400: 31 34 32 34 63 34 35 32 30 32 37 37 34 33 31 35   1424c45202774315
         1314  +|   2416: 66 36 34 36 66 36 33 37 33 36 39 37 61 0a 36 35   f646f6373697a.65
         1315  +|   2432: 32 37 32 38 36 39 36 34 32 30 34 39 34 65 35 34   2728696420494e54
         1316  +|   2448: 34 35 34 37 34 35 35 32 32 30 35 30 35 32 34 39   4547455220505249
         1317  +|   2464: 34 64 34 31 35 32 35 39 32 30 34 62 34 35 35 39   4d415259204b4559
         1318  +|   2480: 32 63 32 30 37 33 37 61 32 30 34 32 34 63 34 66   2c20737a20424c4f
         1319  +|   2496: 34 32 32 39 35 35 30 34 0a 30 36 31 37 32 31 32   42295504.0617212
         1320  +|   2512: 31 30 31 37 37 37 34 36 31 36 32 35 63 36 35 37   101777461625c657
         1321  +|   2528: 34 33 31 35 66 36 33 36 66 36 65 37 34 36 35 36   4315f636f6e74656
         1322  +|   2544: 65 37 34 37 34 33 31 35 66 36 33 36 66 36 65 37   e7474315f636f6e7
         1323  +|   2560: 34 36 35 36 65 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   4656e...........
         1324  +|   2576: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1325  +|   2592: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1326  +|   2608: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1327  +|   2624: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1328  +|   2640: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1329  +|   2656: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 37 34 30   .............740
         1330  +|   2672: 34 34 33 35 32 34 35 34 31 35 34 0a 34 35 32 30   44352454154.4520
         1331  +|   2688: 35 34 34 31 34 32 34 63 34 35 32 30 32 37 37 34   5441424c45202774
         1332  +|   2704: 33 31 35 66 36 33 36 66 36 65 37 34 36 35 36 65   315f636f6e74656e
         1333  +|   2720: 37 34 32 37 32 38 36 39 36 34 32 30 34 39 34 65   742728696420494e
         1334  +|   2736: 35 34 34 35 34 37 34 35 35 32 32 30 35 30 35 62   544547455220505b
         1335  +|   2752: 30 35 30 37 31 37 32 31 32 31 30 31 38 31 30 31   0507172121018101
         1336  +|   2768: 37 34 36 31 36 32 36 63 36 35 37 34 33 31 35 66   7461626c6574315f
         1337  +|   2784: 36 34 36 66 36 33 37 33 0a 36 39 37 61 36 35 37   646f6373.697a657
         1338  +|   2800: 34 33 31 35 66 36 34 36 66 36 33 37 33 36 39 37   4315f646f6373697
         1339  +|   2816: 61 36 35 30 35 34 33 35 32 34 35 34 31 35 34 34   a650543524541544
         1340  +|   2832: 35 32 30 35 34 34 31 34 32 34 63 34 35 32 30 32   5205441424c45202
         1341  +|   2848: 37 37 34 33 31 35 66 36 34 36 66 36 33 37 33 36   774315f646f63736
         1342  +|   2864: 39 37 61 0a 36 35 32 37 32 38 36 39 36 34 32 30   97a.652728696420
         1343  +|   2880: 34 39 34 65 35 34 34 35 34 37 34 35 35 32 32 30   494e544547455220
         1344  +|   2896: 35 30 35 32 34 39 34 64 34 31 35 32 35 39 32 30   5052494d41525920
         1345  +|   2912: 34 62 34 35 35 39 32 63 32 30 37 33 37 61 32 30   4b45592c20737a20
         1346  +|   2928: 34 32 34 63 34 66 34 32 32 39 35 35 30 34 0a 30   424c4f42295504.0
         1347  +|   2944: 36 31 37 32 31 32 31 30 31 37 37 37 34 36 31 36   6172121017774616
         1348  +|   2960: 32 35 63 36 35 37 34 33 31 35 66 36 33 36 66 36   25c6574315f636f6
         1349  +|   2976: 65 37 34 36 35 36 65 37 34 37 34 33 31 35 66 36   e74656e7474315f6
         1350  +|   2992: 33 36 66 36 65 37 34 36 35 36 65 0b 0b 0b 0b 0b   36f6e74656e.....
         1351  +|   3008: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1352  +|   3024: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1353  +|   3040: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1354  +|   3056: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1355  +|   3072: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1356  +|   3088: 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b   ................
         1357  +|   3104: 0b 0b 0b 37 34 30 34 34 33 35 32 34 35 34 31 35   ...7404435245415
         1358  +|   3120: 34 0a 34 35 32 30 35 34 34 31 34 32 34 63 34 35   4.45205441424c45
         1359  +|   3136: 32 30 32 37 37 34 33 31 35 66 36 33 36 66 36 65   202774315f636f6e
         1360  +|   3152: 37 34 36 35 36 65 37 34 32 37 32 38 36 39 36 34   74656e7427286964
         1361  +|   3168: 32 30 34 39 34 65 35 34 34 35 34 37 34 35 35 32   20494e5445474552
         1362  +|   3184: 32 30 35 30 35 32 34 39 34 64 34 31 0a 35 32 35   205052494d41.525
         1363  +|   3200: 39 32 30 34 62 34 35 35 39 32 63 32 30 36 33 33   9204b45592c20633
         1364  +|   3216: 30 32 39 36 39 30 33 30 37 31 37 31 39 31 39 30   0296903071719190
         1365  +|   3232: 31 38 31 32 64 37 34 36 31 36 32 36 63 36 35 37   1812d7461626c657
         1366  +|   3248: 34 33 31 35 66 36 39 c3 bf c3 bf 7e c3 bf c3 89   4315f69....~....
         1367  +|   3264: 4b 52 c2 81 35 66 36 39 36 34 37 38 0a 30 33 34   KR..5f696478.034
         1368  +|   3280: 33 35 32 34 35 34 31 35 34 34 35 32 30 35 34 34   3524541544520544
         1369  +|   3296: 31 34 32 34 63 34 35 32 30 32 37 37 34 33 31 35   1424c45202774315
         1370  +|   3312: 66 36 39 36 34 37 38 32 37 32 38 37 33 36 35 36   f696478272873656
         1371  +|   3328: 37 36 39 36 34 32 63 32 30 37 34 36 35 37 32 36   769642c207465726
         1372  +|   3344: 64 32 63 32 30 37 30 0a 36 37 36 65 36 66 32 63   d2c2070.676e6f2c
         1373  +|   3360: 32 30 35 30 35 32 34 39 34 64 34 31 35 32 35 39   205052494d415259
         1374  +|   3376: 32 30 34 62 34 35 35 39 32 38 37 33 36 35 36 37   204b455928736567
         1375  +|   3392: 36 39 36 34 32 63 32 30 37 34 36 35 37 32 36 64   69642c207465726d
         1376  +|   3408: 32 39 32 39 32 30 35 37 34 39 35 34 34 38 34 66   292920574954484f
         1377  +|   3424: 35 35 0a 35 34 32 30 35 32 34 66 35 37 34 39 34   55.5420524f57494
         1378  +|   3440: 34 35 35 30 32 30 37 31 37 31 62 31 62 30 31 38   4550207171b1b018
         1379  +|   3456: 31 30 31 37 34 36 31 36 32 36 63 36 37 37 34 33   1017461626c67743
         1380  +|   3472: 31 35 66 36 34 36 31 37 34 36 31 37 34 33 31 35   15f6461746174315
         1381  +|   3488: 66 36 34 36 31 37 34 36 31 30 32 34 33 0a 35 32   f646174610243.52
         1382  +|   3504: 34 35 34 31 35 34 34 35 32 30 35 34 34 31 34 32   4541544520544142
         1383  +|   3520: 34 63 34 35 32 30 32 37 37 34 33 31 35 66 36 34   4c45202774315f64
         1384  +|   3536: 36 31 37 34 36 31 32 37 32 38 36 39 36 34 32 30   6174612728696420
         1385  +|   3552: 34 39 34 65 35 34 34 35 34 37 34 35 35 32 32 30   494e544547455220
         1386  +|   3568: 35 30 35 32 34 39 34 64 0a 34 31 35 32 35 39 32   5052494d.4152592
         1387  +|   3584: 30 34 62 34 35 35 39 32 63 32 30 36 32 36 63 36   04b45592c20626c6
         1388  +|   3600: 66 36 33 36 62 32 30 34 32 34 63 34 66 34 32 32   f636b20424c4f422
         1389  +|   3616: 39 33 61 30 31 30 36 31 37 31 31 31 31 30 38 36   93a0106171111086
         1390  +|   3632: 33 37 34 36 31 36 32 36 63 36 35 37 34 33 31 37   37461626c6574317
         1391  +|   3648: 34 33 31 0a 34 33 35 32 34 35 34 31 35 34 34 35   431.435245415445
         1392  +|   3664: 32 30 35 36 34 39 35 32 35 34 35 35 34 31 34 63   205649525455414c
         1393  +|   3680: 32 30 35 34 34 31 34 32 34 63 34 35 32 30 37 34   205441424c452074
         1394  +|   3696: 33 31 c3 94 30 35 35 35 33 34 39 34 65 34 37 32   31..05553494e472
         1395  +|   3712: 30 36 36 37 34 37 33 33 35 32 38 36 33 36 66 0a   06674733528636f.
         1396  +|   3728: 33 65 37 34 36 35 36 65 37 34 32 39 30 64 30 30   3e74656e74290d00
         1397  +|   3744: 30 30 30 30 30 33 30 66 62 64 30 30 30 66 65 38   0000030fbd000fe8
         1398  +|   3760: 30 66 65 66 30 66 62 64 0a 5b 31 66 62 64 5d 32   0fef0fbd.[1fbd]2
         1399  +|   3776: 34 38 34 38 30 38 30 38 30 38 30 30 31 30 33 30   4848080808001030
         1400  +|   3792: 30 34 65 30 30 30 30 30 30 31 65 30 36 33 30 36   04e0000001e06306
         1401  +|   3808: 31 36 32 36 31 36 33 36 62 30 31 30 32 30 32 30   16261636b0102020
         1402  +|   3824: 34 30 32 36 36 37 34 30 32 30 32 30 32 30 34 30   4026674020202040
         1403  +|   3840: 34 36 65 0a 36 34 36 66 36 65 30 33 30 32 30 32   46e.646f6e030202
         1404  +|   3856: 30 34 30 61 30 37 30 35 30 31 30 33 30 30 31 30   040a070501030010
         1405  +|   3872: 30 33 30 33 30 66 30 61 30 33 30 30 32 34 30 30   03030f0a03002400
         1406  +|   3888: 30 30 30 30 30 30 30 31 30 31 30 31 30 30 30 31   0000000101010001
         1407  +|   3904: 30 31 30 31 30 31 30 61 30 30 30 30 30 30 0a 30   0101010a000000.0
         1408  +|   3920: 31 30 66 66 61 30 30 30 66 66 61 0a 5b 32 66 65   10ffa000ffa.[2fe
         1409  +|   3936: 72 20 62 61 63 6b 75 70 0f ca 00 4e 81 1d 61 6c   r backup...N..al
         1410  +|   3952: 70 68 61 20 63 68 61 6e 6e 65 6c 20 c2 af 62 61   pha channel ..ba
         1411  +|   3968: 63 6b 75 70 20 61 62 61 6e 64 6f 6e 20 74 65 73   ckup abandon tes
         1412  +|   3984: 74 20 61 62 61 63 6b 20 63 68 61 6e 6e 65 62 6f   t aback channebo
         1413  +|   4000: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         1414  +|   4016: 61 63 74 69 76 65 09 07 03 00 19 61 74 6f 6d 69   active.....atomi
         1415  +|   4032: 63 07 06 03 00 15 61 74 6b 6d 0f e0 00 0b 19 62   c.....atkm.....b
         1416  +|   4048: 6f 6f 6d 65 72 09 04 03 00 19 61 63 74 69 76 65   oomer.....active
         1417  +|   4064: 00 00 00 0c 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1418  +|   4080: 17 61 66 21 66 74 08 01 03 00 17 61 62 61 63 6b   .af!ft.....aback
         1419  +| page 5 offset 16384
         1420  +|      0: 0d 0f ee 00 06 0f d6 00 0f fa 0f f4 0f e8 0f e2   ................
         1421  +|     16: 0f dc 0f d6 0f d0 0f d0 00 00 00 00 00 00 00 00   ................
         1422  +|   4048: 0f ee 00 06 0e 0a 04 07 03 00 0e 01 04 06 03 00   ................
         1423  +|   4064: 0e 01 04 05 03 00 0e 1d 04 04 03 00 0e 01 00 00   ................
         1424  +|   4080: 00 06 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1425  +| page 6 offset 20480
         1426  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1427  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1428  +| page 7 offset 24576
         1429  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1430  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1431  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1432  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         1433  +| end c19b.db
         1434  +}]} {}
         1435  +
         1436  +do_catchsql_test 18.1 {
         1437  +  INSERT INTO t1(t1) VALUES('optimize');
         1438  +} {1 {database disk image is malformed}}
         1439  +
         1440  +#--------------------------------------------------------------------------
         1441  +reset_db
         1442  +do_test 19.0 {
         1443  +  sqlite3 db {}
         1444  +  db deserialize [decode_hexdb {
         1445  +| size 28672 pagesize 4096 filename c20b.db
         1446  +| page 1 offset 0
         1447  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1448  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
         1449  +|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         1450  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1451  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
         1452  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
         1453  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1454  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1455  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1456  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1457  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1458  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1459  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1460  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1461  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1462  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         1463  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1464  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1465  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1466  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1467  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1468  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1469  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1470  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1471  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1472  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1473  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1474  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1475  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1476  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1477  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1478  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1479  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1480  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1481  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1482  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1483  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1484  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1485  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1486  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1487  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1488  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1489  +| page 2 offset 4096
         1490  +|      0: 0d 0f 20 00 05 0e a0 00 0f e8 0e a0 0f bd 0f 34   .. ............4
         1491  +|     16: 0e b7 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         1492  +|   3744: 15 0a 03 00 30 00 00 00 00 01 03 03 00 03 01 01   ....0...........
         1493  +|   3760: 01 02 01 01 03 01 01 62 8c 80 80 80 80 01 04 00   .......b........
         1494  +|   3776: 81 48 00 00 00 55 06 30 61 62 61 63 6b 08 01 04   .H...U.0aback...
         1495  +|   3792: 04 6e 64 6f 6e 03 01 05 01 02 05 63 74 69 76 65   .ndon......ctive
         1496  +|   3808: 08 01 02 04 6c 70 68 61 08 01 02 03 74 6f 6d 08   ....lpha....tom.
         1497  +|   3824: 01 01 06 62 61 63 6b 75 70 08 01 02 05 6f 6f 6d   ...backup....oom
         1498  +|   3840: 65 72 08 01 01 07 63 68 61 6e 6e 65 6c 08 01 01   er....channel...
         1499  +|   3856: 04 74 65 73 74 08 01 04 09 0a 09 08 07 0a 09 0b   .test...........
         1500  +|   3872: 0f ef 00 14 2a 00 00 00 00 01 02 02 00 02 01 01   ....*...........
         1501  +|   3888: 01 02 01 01 81 01 88 80 80 80 80 01 04 00 82 06   ................
         1502  +|   3904: 00 00 00 72 06 30 61 62 61 63 6b 08 02 07 04 04   ...r.0aback.....
         1503  +|   3920: 6e 64 6f 6e 08 02 05 02 05 63 74 69 76 65 04 02   ndon.....ctive..
         1504  +|   3936: 02 04 02 0b 02 04 6c 70 68 61 08 04 02 0a 02 03   ......lpha......
         1505  +|   3952: 74 6f 6d 06 02 02 02 02 09 05 02 69 63 07 02 02   tom........ic...
         1506  +|   3968: 01 06 62 61 63 6b 75 70 08 02 04 02 05 6f 6f 66   ..backup.....oof
         1507  +|   3984: 65 72 05 02 02 04 03 6d 65 72 08 02 08 01 07 63   er.....mer.....c
         1508  +|   4000: 68 61 6e 6e 65 6c 08 02 03 01 04 74 65 73 74 08   hannel.....test.
         1509  +|   4016: 02 06 04 0a 09 0d 0a 0b 07 0b 0a 08 0c 24 84 80   .............$..
         1510  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1511  +|   4048: 63 6b 01 02 66 04 00 22 74 00 02 22 04 04 6e 64   ck..f...t.....nd
         1512  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 06 06 00   on..............
         1513  +|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         1514  +| page 3 offset 8192
         1515  +|      0: 0a 00 00 00 03 0f ec 00 0f fa 0f f3 0f ec 00 00   ................
         1516  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 06 04 01 0c   ................
         1517  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         1518  +| page 4 offset 12288
         1519  +|      0: 0d 0f e0 00 06 0f b6 00 0f f6 0f ec 0f d5 0f ca   ................
         1520  +|     16: 0f c1 0f b6 0f 70 0f 70 00 00 00 00 00 00 00 00   .....p.p........
         1521  +|   3952: 0f e0 00 46 81 0d 61 6c 70 68 61 20 63 68 61 6e   ...F..alpha chan
         1522  +|   3968: 6e 65 6c 20 62 61 63 6b 75 70 20 61 62 61 6e 64   nel backup aband
         1523  +|   3984: 6f 6e 20 74 65 73 74 20 61 62 61 63 6b 20 62 6f   on test aback bo
         1524  +|   4000: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         1525  +|   4016: 61 63 74 69 76 65 09 07 03 00 19 61 74 6f 6d 69   active.....atomi
         1526  +|   4032: 63 07 06 03 00 15 61 74 6f 6d 09 05 03 00 19 62   c.....atom.....b
         1527  +|   4048: 6f 6f 66 65 72 09 04 03 00 19 61 63 74 69 76 65   oofer.....active
         1528  +|   4064: 00 00 00 0c 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1529  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         1530  +| page 5 offset 16384
         1531  +|      0: 0d 0f ee 00 06 0f d6 00 0f fa 0f f4 0f e8 0f e2   ................
         1532  +|     16: 0f dc 0f d6 0f d0 0f d0 00 00 00 00 00 00 00 00   ................
         1533  +|   4048: 0f ee 00 06 0e 0a 04 07 03 00 0e 01 04 06 03 00   ................
         1534  +|   4064: 0e 01 04 05 03 00 0e 01 04 04 03 00 0e 01 00 00   ................
         1535  +|   4080: 00 06 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1536  +| page 6 offset 20480
         1537  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1538  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1539  +| page 7 offset 24576
         1540  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1541  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1542  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1543  +|   4080: 86 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   .eck....optimize
         1544  +| end c20b.db
         1545  +}]} {}
         1546  +
         1547  +do_catchsql_test 19.1 {
         1548  +  INSERT INTO t1(t1) VALUES('optimize');
         1549  +} {1 {database disk image is malformed}}
         1550  +
         1551  +#--------------------------------------------------------------------------
         1552  +reset_db
         1553  +do_test 20.0 {
         1554  +  sqlite3 db {}
         1555  +  db deserialize [decode_hexdb {
         1556  +| size 28672 pagesize 4096 filename crash-cf347c523f793c.db
         1557  +| page 1 offset 0
         1558  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1559  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
         1560  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 00   ................
         1561  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1562  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
         1563  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1564  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1565  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1566  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1567  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1568  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1569  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1570  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1571  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1572  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         1573  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1574  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1575  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1576  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1577  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1578  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1579  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1580  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1581  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1582  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1583  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1584  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1585  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1586  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1587  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1588  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1589  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1590  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1591  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1592  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1593  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1594  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1595  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1596  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1597  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1598  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1599  +| page 2 offset 4096
         1600  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
         1601  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
         1602  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1603  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
         1604  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
         1605  +|   4080: 0a 03 00 24 00 00 00 0e ee ee ee ee ee ee ee ee   ...$............
         1606  +| page 3 offset 8192
         1607  +|      0: ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee   ................
         1608  +|     16: ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee   ................
         1609  +|     32: ee ee ee ee ee ee ee ee ee ee ee ee 00 10 10 10   ................
         1610  +|     48: 00 10 10 10 10 a0 00 00 00 10 ff a0 00 ff 00 00   ................
         1611  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         1612  +| page 4 offset 12288
         1613  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
         1614  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1615  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         1616  +| page 5 offset 16384
         1617  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f4 0f ee 00 00   ................
         1618  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
         1619  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1620  +| page 6 offset 20480
         1621  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1622  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1623  +| page 7 offset 24576
         1624  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1625  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1626  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1627  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         1628  +| end crash-cf347c523f793c.db
         1629  +}]} {}
         1630  +
         1631  +do_catchsql_test 20.1 {
         1632  +  SELECT * FROM t1 WHERE t1 MATCH 'abandon';
         1633  +} {1 {vtable constructor failed: t1}}
         1634  +
         1635  +#-------------------------------------------------------------------------
         1636  +reset_db
         1637  +do_test 21.0 {
         1638  +  sqlite3 db {}
         1639  +  db deserialize [decode_hexdb {
         1640  +| size 28672 pagesize 4096 filename c22b.db
         1641  +| page 1 offset 0
         1642  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1643  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
         1644  +|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         1645  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1646  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
         1647  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
         1648  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1649  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1650  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1651  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1652  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1653  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1654  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1655  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1656  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1657  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         1658  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1659  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1660  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1661  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1662  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1663  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1664  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1665  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1666  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1667  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1668  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1669  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1670  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1671  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1672  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1673  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1674  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1675  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1676  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1677  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1678  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1679  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1680  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1681  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1682  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         1683  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1684  +| page 2 offset 4096
         1685  +|      0: 0d 0e 8e 00 06 0e 2f 00 0f e8 0e 2f 0f bd 0f 3b   ....../..../...;
         1686  +|     16: 0e a5 0e 49 00 00 00 00 00 00 00 00 00 00 00 00   ...I............
         1687  +|   3616: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 18   ................
         1688  +|   3632: 0a 03 00 36 00 00 00 00 01 04 04 00 04 01 01 01   ...6............
         1689  +|   3648: 02 01 01 03 01 01 04 01 01 3e 90 80 80 80 80 01   .........>......
         1690  +|   3664: 04 00 81 00 00 00 00 36 06 30 62 61 63 6b 75 05   .......6.0backu.
         1691  +|   3680: 02 04 05 02 04 02 05 65 61 6d 65 72 05 02 02 05   .......eamer....
         1692  +|   3696: 02 02 02 05 6f 6f 6d 65 72 05 01 05 01 02 05 75   ....oomer......u
         1693  +|   3712: 6d 6d 65 72 05 02 03 05 02 03 04 0d 0d 0b 0f 27   mmer...........'
         1694  +|   3728: 00 17 30 00 00 00 00 01 03 03 00 03 01 01 01 02   ..0.............
         1695  +|   3744: 01 01 03 01 01 7b 8c 80 80 80 80 01 04 00 81 7a   ...............z
         1696  +|   3760: 00 00 00 6d 06 30 61 62 61 63 6b 0d 02 07 04 04   ...m.0aback.....
         1697  +|   3776: 6e 64 6f 6e 0d 02 05 02 05 63 74 69 76 65 09 02   ndon.....ctive..
         1698  +|   3792: 02 04 02 0b 02 04 6c 70 68 61 0d 04 02 0a 02 03   ......lpha......
         1699  +|   3808: 74 6f 6d 0b 02 02 02 02 09 05 02 69 63 0c 02 02   tom........ic...
         1700  +|   3824: 01 06 62 61 63 6b 75 70 0d 02 04 02 05 6f 6f 6d   ..backup.....oom
         1701  +|   3840: 65 72 0a 02 02 03 02 08 01 07 63 68 61 6e 6e 65   er........channe
         1702  +|   3856: 6c 0d 02 03 01 04 74 65 73 74 0d 02 06 04 0a 09   l.....test......
         1703  +|   3872: 0d 0a 0b 07 0b 0d 0c 0f ef 00 14 2a 00 00 00 00   ...........*....
         1704  +|   3888: 01 02 02 00 02 01 01 01 02 01 01 7b 88 80 80 80   ................
         1705  +|   3904: 80 01 04 00 81 7a 00 00 00 6d 06 30 61 62 61 63   .....z...m.0abac
         1706  +|   3920: 6b 08 02 07 04 04 6e 64 6f 6e 08 02 05 02 05 63   k.....ndon.....c
         1707  +|   3936: 74 69 76 65 04 02 02 04 02 0b 02 04 6c 70 68 61   tive........lpha
         1708  +|   3952: 08 04 02 0a 02 03 74 6f 6d 06 02 02 02 02 09 05   ......tom.......
         1709  +|   3968: 02 69 63 07 02 02 01 06 62 61 63 6b 75 70 08 02   .ic.....backup..
         1710  +|   3984: 04 02 05 6f 6f 6d 65 72 05 02 02 03 02 08 01 07   ...oomer........
         1711  +|   4000: 63 68 61 6e 6e 65 6c 08 02 03 01 04 74 65 73 74   channel.....test
         1712  +|   4016: 08 02 06 04 0a 09 0d 0a 0b 07 0b 0d 0c 24 84 80   .............$..
         1713  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1714  +|   4048: 63 6b 01 02 02 04 02 66 74 00 02 22 04 04 6e 64   ck.....ft.....nd
         1715  +|   4064: 6f 6e 03 02 02 08 0a 07 05 01 03 00 10 0d 23 00   on............#.
         1716  +|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         1717  +| page 3 offset 8192
         1718  +|      0: 0a 00 00 00 04 0f e5 00 0f fa 0f f3 0f ec 0f e5   ................
         1719  +|   4064: 00 00 00 00 00 06 04 01 0c 01 04 02 06 04 01 0c   ................
         1720  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         1721  +| page 4 offset 12288
         1722  +|      0: 0d 0f 5a 00 0d 0e ce 00 0f f6 0f ec 0f e0 0f d5   ..Z.............
         1723  +|     16: 0e e7 0f c1 0f b6 0f 70 0f 65 0e ce 0f 51 0f 46   .......p.e...Q.F
         1724  +|     32: 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         1725  +|   3776: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 17 0a   ................
         1726  +|   3792: 03 00 35 62 65 61 6d 65 72 20 62 75 6d 6d 65 72   ..5beamer bummer
         1727  +|   3808: 20 62 61 63 6b 75 29 17 05 03 00 35 62 65 61 6d    backu)....5beam
         1728  +|   3824: 65 72 20 62 75 6d 6d 65 72 20 62 61 63 6b 75 29   er bummer backu)
         1729  +|   3840: 44 0d 04 00 81 0d 61 6c 70 68 61 20 63 68 61 6e   D.....alpha chan
         1730  +|   3856: 6e 65 6c 20 62 61 63 6b 75 70 20 61 62 61 6e 64   nel backup aband
         1731  +|   3872: 6f 6e 20 74 65 73 74 20 61 62 61 63 6b 20 62 6f   on test aback bo
         1732  +|   3888: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         1733  +|   3904: 61 63 74 69 76 65 09 0c 03 00 19 61 74 6f 6d 69   active.....atomi
         1734  +|   3920: 63 07 0b 03 00 15 61 74 6f 6d 0f ca 00 0b 19 62   c.....atom.....b
         1735  +|   3936: 6f 6f 6d 65 72 09 09 03 00 19 61 63 74 69 76 65   oomer.....active
         1736  +|   3952: 44 08 04 00 81 0d 61 6c 70 68 61 20 63 68 61 6e   D.....alpha chan
         1737  +|   3968: 6e 65 6c 20 62 61 63 6b 75 70 20 61 62 61 6e 64   nel backup aband
         1738  +|   3984: 6f 6e 20 74 65 73 74 20 61 62 61 63 6b 20 62 6f   on test aback bo
         1739  +|   4000: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         1740  +|   4016: 61 63 74 69 76 65 09 07 03 00 19 61 74 6f 6d 69   active.....atomi
         1741  +|   4032: 63 07 06 03 00 15 61 74 6f 6d 00 00 00 0b 19 62   c.....atom.....b
         1742  +|   4048: 6f 6f 6d 65 72 09 04 03 00 19 61 63 74 69 76 65   oomer.....active
         1743  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         1744  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         1745  +| page 5 offset 16384
         1746  +|      0: 0d 00 00 00 0d 0f b2 00 0f fa 0f f4 0f ee 0f e8   ................
         1747  +|     16: 0f e2 0f dc 0f d6 0f d0 0f ca 0f c4 0f be 0f b8   ................
         1748  +|     32: 0f b2 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         1749  +|   4016: 00 00 04 0d 03 00 0e 0a 04 0c 03 00 0e 01 04 0b   ................
         1750  +|   4032: 03 00 0e 01 04 0a 03 00 0e 03 04 09 03 00 0e 01   ................
         1751  +|   4048: 04 08 03 00 0e 0a 04 07 03 00 0e 01 04 06 03 00   ................
         1752  +|   4064: 0e 01 04 05 03 00 0e 03 04 04 03 00 0e 01 04 03   ................
         1753  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         1754  +| page 6 offset 20480
         1755  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         1756  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         1757  +| page 7 offset 24576
         1758  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         1759  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         1760  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         1761  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         1762  +| end c22b.db
         1763  +}]} {}
         1764  +
         1765  +do_catchsql_test 21.1 {
         1766  +  DELETE FROM t1 WHERE t1 MATCH 'ab*ndon';
         1767  +} {1 {database disk image is malformed}}
         1768  +
         1769  +#-------------------------------------------------------------------------
         1770  +#
         1771  +reset_db
         1772  +do_test 22.0 {
         1773  +  sqlite3 db {}
         1774  +  db deserialize [decode_hexdb {
         1775  +| size 28672 pagesize 4096 filename c22b.db
         1776  +| page 1 offset 0
         1777  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1778  +|     16: 10 00 01 01 00 40 20 20 00 00 00 02 00 00 00 07   .....@  ........
         1779  +|     32: 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00   ................
         1780  +|     48: 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00   ................
         1781  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02   ................
         1782  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
         1783  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         1784  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         1785  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         1786  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         1787  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         1788  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         1789  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         1790  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         1791  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         1792  +|   3664: 07 17 21 21 01 81 01 74 41 62 6c 65 74 31 5f 64   ..!!...tAblet1_d
         1793  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         1794  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         1795  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         1796  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         1797  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         1798  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         1799  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         1800  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         1801  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         1802  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         1803  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         1804  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         1805  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         1806  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         1807  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         1808  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         1809  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         1810  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         1811  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         1812  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         1813  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1814  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         1815  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         1816  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         1817  +|   4064: 75 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   uAL TABLE t1 USI
         1818  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         1819  +| page 2 offset 4096
         1820  +|      0: 0d 0f 15 00 05 08 4e 00 0f e8 08 4e 0f bd 0f 29   ......N....N...)
         1821  +|     16: 08 65 00 00 00 00 00 00 00 00 00 00 00 00 00 00   .e..............
         1822  +|   2112: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 0a   ................
         1823  +|   2128: 03 00 30 00 00 00 00 01 03 02 01 03 01 01 01 02   ..0.............
         1824  +|   2144: 01 01 03 01 01 8d 28 8c 80 80 80 80 01 04 00 9a   ......(.........
         1825  +|   2160: 54 00 00 06 77 19 30 30 30 30 30 30 33 30 66 65   T...w.00000030fe
         1826  +|   2176: 65 30 30 30 66 66 61 30 66 66 34 30 66 65 65 05   e000ffa0ff40fee.
         1827  +|   2192: 02 19 02 0b 31 30 66 66 61 30 30 30 66 66 61 05   ....10ffa000ffa.
         1828  +|   2208: 06 13 18 09 02 25 33 34 33 35 32 34 35 34 31 35   .....%3435245415
         1829  +|   2224: 34 34 35 32 30 35 34 34 31 34 32 34 63 34 35 32   445205441424c452
         1830  +|   2240: 30 32 37 37 34 33 31 35 66 36 39 05 02 07 02 37   02774315f69....7
         1831  +|   2256: 34 30 33 30 33 30 30 30 65 30 31 30 34 30 32 30   40303000e0104020
         1832  +|   2272: 33 30 30 30 65 30 31 30 34 30 31 30 33 30 30 30   3000e01040103000
         1833  +|   2288: 65 30 31 30 61 30 30 30 30 30 30 30 31 30 66 66   e010a000000010ff
         1834  +|   2304: 34 30 30 30 66 66 34 05 02 1b 02 27 35 30 34 30   4000ff4....'5040
         1835  +|   2320: 39 30 63 30 31 30 32 30 64 30 30 30 30 30 30 30   90c01020d0000000
         1836  +|   2336: 33 30 66 65 30 30 30 30 66 66 36 30 66 65 63 30   30fe0000ff60fec0
         1837  +|   2352: 66 65 30 05 02 2c 27 02 66 30 05 02 16 02 1d 36   fe0..,'.f0.....6
         1838  +|   2368: 31 37 31 31 31 31 30 38 36 33 37 34 36 31 36 32   1711110863746162
         1839  +|   2384: 36 63 36 35 37 34 33 31 37 34 33 31 05 02 0d 02   6c6574317431....
         1840  +|   2400: 29 39 30 33 30 32 31 62 37 32 36 35 36 32 37 35   )903021b72656275
         1841  +|   2416: 36 34 36 31 37 34 36 31 37 34 33 31 35 66 36 34   6461746174315f64
         1842  +|   2432: 36 31 37 34 36 31 30 32 34 33 05 02 1f 02 43 61   6174610243....Ca
         1843  +|   2448: 30 33 30 33 30 30 31 62 36 31 36 32 36 31 36 65   0303001b6162616e
         1844  +|   2464: 36 34 36 66 36 65 30 38 30 32 30 33 30 30 31 37   646f6e0802030017
         1845  +|   2480: 36 31 36 32 36 31 36 36 37 34 30 38 30 31 30 33   6162616674080103
         1846  +|   2496: 30 30 31 37 36 31 36 32 36 31 36 33 36 62 30 64   0017616261636b0d
         1847  +|   2512: 30 30 05 02 18 34 1d 33 36 62 30 31 30 32 30 32   00...4.36b010202
         1848  +|   2528: 30 34 30 32 36 36 37 34 30 32 30 32 30 32 30 34   0402667402020204
         1849  +|   2544: 30 34 36 65 05 02 2e 02 33 62 30 33 31 62 30 31   046e....3b031b01
         1850  +|   2560: 37 36 36 35 37 32 37 33 36 39 36 66 36 65 30 34   76657273696f6e04
         1851  +|   2576: 30 64 30 30 30 30 30 30 30 33 30 66 64 36 30 30   0d000000030fd600
         1852  +|   2592: 30 66 66 34 30 66 65 31 30 66 64 36 05 02 1d 01   0ff40fe10fd6....
         1853  +|   2608: 04 31 66 62 64 05 04 10 18 01 01 32 05 02 14 02   .1fbd......2....
         1854  +|   2624: 43 34 38 34 38 30 38 30 38 30 38 30 30 31 30 33   C484808080800103
         1855  +|   2640: 30 30 34 65 30 30 30 30 30 30 31 65 30 36 33 30   004e0000001e0630
         1856  +|   2656: 36 31 36 32 36 31 36 33 36 62 30 31 30 32 30 32   616261636b010202
         1857  +|   2672: 30 34 30 32 36 36 37 34 30 32 30 32 30 32 30 34   0402667402020204
         1858  +|   2688: 30 34 36 65 05 04 11 18 02 01 66 05 02 2a 03 02   046e......f..*..
         1859  +|   2704: 65 72 05 02 31 01 08 33 35 32 38 36 33 36 66 05   er..1..3528636f.
         1860  +|   2720: 02 24 02 03 66 65 30 05 04 17 18 01 2b 34 31 35   .$..fe0.....+415
         1861  +|   2736: 32 35 39 32 30 34 62 34 35 35 39 32 63 32 30 36   259204b45592c206
         1862  +|   2752: 32 36 63 36 66 36 33 36 62 32 30 34 32 34 63 34   26c6f636b20424c4
         1863  +|   2768: 66 34 32 32 39 33 61 30 05 02 0c 2c 1f 31 30 36   f42293a0...,.106
         1864  +|   2784: 31 37 31 31 31 31 30 38 36 33 37 34 36 31 36 32   1711110863746162
         1865  +|   2800: 36 63 36 35 37 34 33 31 37 34 33 31 05 02 22 02   6c6574317431....
         1866  +|   2816: 40 33 35 32 34 35 34 31 35 34 34 35 32 30 35 36   @352454154452056
         1867  +|   2832: 34 39 35 32 35 34 37 35 34 31 34 63 32 30 35 34   49525475414c2054
         1868  +|   2848: 34 31 34 32 34 63 34 35 32 30 37 34 33 31 32 30   41424c4520743120
         1869  +|   2864: 35 35 35 33 34 39 34 65 34 37 32 30 36 36 37 34   5553494e47206674
         1870  +|   2880: 37 05 02 23 42 09 33 33 35 32 38 36 33 36 66 05   7..#B.33528636f.
         1871  +|   2896: 02 0e 02 03 66 65 65 05 02 1a 01 34 35 32 34 35   ....fee....45245
         1872  +|   2912: 34 31 35 34 34 35 32 30 35 34 34 31 34 32 34 63   415445205441424c
         1873  +|   2928: 34 35 32 30 32 37 37 34 33 31 35 66 36 34 36 31   45202774315f6461
         1874  +|   2944: 37 34 36 31 32 37 32 38 36 39 36 34 32 30 34 39   7461272869642049
         1875  +|   2960: 05 02 20 16 37 c3 b0 35 32 30 32 37 37 34 33 31   .. .7..520277431
         1876  +|   2976: 35 66 36 34 36 31 37 34 36 31 32 37 32 38 36 39   5f64617461272869
         1877  +|   2992: 36 34 32 30 34 39 34 65 35 34 34 35 34 37 34 35   6420494e54454745
         1878  +|   3008: 35 32 32 30 35 30 35 32 34 39 34 64 05 02 0b 03   52205052494d....
         1879  +|   3024: 48 35 39 32 30 34 62 34 35 35 39 32 63 32 30 36   H59204b45592c206
         1880  +|   3040: 33 33 30 32 39 36 39 30 33 30 30 30 31 35 37 35   3302969030001575
         1881  +|   3056: 33 31 31 39 32 36 64 37 34 36 31 36 32 36 63 36   311926d7461626c6
         1882  +|   3072: 35 37 34 33 31 35 66 36 39 36 34 37 38 37 34 33   574315f696478743
         1883  +|   3088: 31 35 66 36 39 36 34 37 38 05 02 06 02 38 34 32   15f696478....842
         1884  +|   3104: 30 35 32 34 66 35 37 34 39 34 34 35 35 30 32 30   0524f57494455020
         1885  +|   3120: 37 31 37 31 62 31 62 30 31 38 31 30 31 37 34 36   7171b1b018101746
         1886  +|   3136: 31 36 32 36 63 36 35 37 34 33 31 35 66 31 37 34   1626c6574315f174
         1887  +|   3152: 36 31 30 32 34 33 05 02 0a 02 03 66 66 34 05 02   610243.....ff4..
         1888  +|   3168: 1c 01 4a 36 34 36 66 36 65 30 33 30 32 30 32 30   ..J646f6e0302020
         1889  +|   3184: 34 30 61 30 37 30 35 30 31 30 33 30 30 31 30 30   40a0705010300100
         1890  +|   3200: 33 30 33 30 66 30 61 30 33 30 30 32 34 30 30 30   3030f0a030024000
         1891  +|   3216: 30 30 30 30 30 30 31 30 31 30 31 30 30 30 31 30   0000001010100010
         1892  +|   3232: 31 30 31 30 30 39 61 30 30 30 30 30 30 05 02 2f   101009a000000../
         1893  +|   3248: 42 09 31 30 61 30 30 30 30 30 30 05 02 28 08 43   B.10a000000..(.C
         1894  +|   3264: 74 30 32 30 32 30 34 30 61 30 37 30 35 30 31 30   t0202040a0705010
         1895  +|   3280: 33 30 30 31 30 30 33 30 33 30 66 30 61 30 33 30   3001003030f0a030
         1896  +|   3296: 30 32 34 30 30 30 30 30 30 30 30 30 31 30 31 30   0240000000001010
         1897  +|   3312: 31 30 30 30 31 30 31 30 31 30 31 30 61 30 30 30   100010101010a000
         1898  +|   3328: 30 30 30 05 02 12 02 49 37 36 65 36 66 32 63 32   000....I76e6f2c2
         1899  +|   3344: 30 35 30 35 32 34 39 34 64 34 31 35 32 35 39 32   05052494d4152592
         1900  +|   3360: 30 34 62 34 35 35 39 32 38 37 33 36 35 36 37 36   04b4559287365676
         1901  +|   3376: 39 36 34 32 63 32 30 37 34 36 35 37 32 36 64 32   9642c207465726d2
         1902  +|   3392: 39 32 39 32 30 35 37 34 39 35 34 34 38 34 66 35   92920574954484f5
         1903  +|   3408: 35 05 02 09 02 4c 39 37 61 36 35 37 34 33 31 35   5....L97a6574315
         1904  +|   3424: 66 36 34 36 66 36 33 37 33 36 39 37 61 36 35 30   f646f6373697a650
         1905  +|   3440: 35 34 33 35 32 34 35 34 31 35 34 34 35 32 30 35   5435245415445205
         1906  +|   3456: 34 38 36 39 36 34 32 30 34 39 34 65 35 34 34 35   48696420494e5445
         1907  +|   3472: 34 37 34 35 35 32 32 30 35 30 35 32 34 39 34 34   4745522050524944
         1908  +|   3488: 64 31 05 02 05 02 27 65 37 34 36 35 36 65 37 34   d1....'e74656e74
         1909  +|   3504: 32 39 30 64 30 30 30 30 30 30 30 33 30 66 62 64   290d000000030fbd
         1910  +|   3520: 30 30 30 62 65 38 30 66 65 66 30 66 62 64 05 02   000be80fef0fbd..
         1911  +|   3536: 0f 1e 0b 66 65 38 30 66 65 66 30 66 62 64 05 02   ...fe80fef0fbd..
         1912  +|   3552: 25 02 03 66 64 36 05 02 1e 01 4a 37 36 32 39 32   %..fd6....J76292
         1913  +|   3568: 30 35 37 34 39 35 34 34 38 34 66 35 35 35 34 32   0574954484f55542
         1914  +|   3584: 30 35 32 34 66 35 37 34 39 34 34 35 62 30 35 30   0524f5749445b050
         1915  +|   3600: 37 31 37 32 31 32 31 30 31 38 31 30 31 37 34 36   7172121018101746
         1916  +|   3616: 31 36 32 36 63 36 35 37 34 33 31 35 66 36 34 36   1626c6574315f646
         1917  +|   3632: 66 36 33 37 33 05 02 04 02 21 38 32 37 32 38 37   f6373....!827287
         1918  +|   3648: 33 36 35 36 37 36 39 36 34 32 63 32 30 37 34 36   3656769642c20746
         1919  +|   3664: 35 37 32 36 64 32 63 32 30 37 30 05 02 08 01 01   5726d2c2070.....
         1920  +|   3680: 61 05 02 2b 01 06 62 61 63 6b 75 70 05 02 32 02   a..+..backup..2.
         1921  +|   3696: 05 65 61 6d 65 72 05 02 02 02 05 6f 6f 6d 65 72   .eamer.....oomer
         1922  +|   3712: 05 01 02 40 75 6d 6d 32 34 63 34 35 32 30 32 37   ...@umm24c452027
         1923  +|   3728: 37 34 33 31 35 66 36 33 36 66 36 65 36 36 36 39   74315f636f6e6669
         1924  +|   3744: 36 37 32 37 32 38 36 62 32 30 35 30 35 32 34 39   6727286b20505249
         1925  +|   3760: 34 64 34 31 35 32 35 39 32 30 34 62 34 35 35 39   4d415259204b4559
         1926  +|   3776: 32 63 32 30 05 02 03 01 15 65 35 34 34 35 34 37   2c20.....e544547
         1927  +|   3792: 34 35 35 32 32 30 35 30 35 32 34 39 34 64 05 02   4552205052494d..
         1928  +|   3808: 21 01 02 66 61 05 02 15 04 1d 12 2a 3c 2c 07 22   !..fa......*<,..
         1929  +|   3824: 2e 48 22 38 0a 06 49 06 07 0d 09 30 24 45 0e 08   .H.8..I....0$E..
         1930  +|   3840: 39 3c 4d 3d 08 4f 0e 48 4e 51 2c 10 08 4f 26 06   9<M=.O.HNQ,..O&.
         1931  +|   3856: 0b 0a 09 45 1a 0f ef 00 14 2a 00 00 00 00 01 02   ...E.....*......
         1932  +|   3872: 01 01 02 01 01 01 02 01 01 81 0c 88 80 80 80 80   ................
         1933  +|   3888: 01 04 00 82 1c 00 00 00 7c 08 30 61 62 61 6e 64   ........|.0aband
         1934  +|   3904: 6f 6e 08 02 05 02 05 63 74 69 76 65 04 02 02 04   on.....ctive....
         1935  +|   3920: 02 0b 02 04 6c 70 68 61 08 04 02 0a 02 03 74 6b   ....lpha......tk
         1936  +|   3936: 6d 06 02 02 03 02 6f 6d 08 02 09 05 02 69 63 07   m.....om.....ic.
         1937  +|   3952: 02 02 01 06 62 61 63 6b 75 70 08 02 04 02 05 6f   ....backup.....o
         1938  +|   3968: 6f 6d 65 72 05 02 02 01 0c 63 68 61 6e 6e 65 62   omer.....channeb
         1939  +|   3984: 6f 6f 6d 65 72 08 02 08 07 01 6c 08 02 03 01 06   oomer.....l.....
         1940  +|   4000: 73 74 61 61 63 6b 08 02 07 01 03 74 65 62 08 02   staack.....teb..
         1941  +|   4016: 06 04 0c 0d 0a 08 07 07 0b 0a 11 06 0b 24 84 80   .............$..
         1942  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         1943  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
         1944  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 08 41 00   on............A.
         1945  +|   4080: 00 00 11 24 00 00 00 00 01 01 00 01 01 01 01 01   ...$............
         1946  +| page 3 offset 8192
         1947  +|      0: 0a 00 00 00 03 0f ec 00 ff 00 0f f3 0f ec 00 00   ................
         1948  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 06 04 01 0c   ................
         1949  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         1950  +| page 4 offset 12288
         1951  +|      0: 0d 0f ca 00 08 07 e1 00 0f f6 0f ec 0f e0 0f d5   ................
         1952  +|     16: 07 e1 0f c1 0f b6 0f 6a 00 00 00 00 00 00 00 00   .......j........
         1953  +|   2016: 00 8f 06 05 04 00 9e 11 62 65 61 6d 65 72 20 62   ........beamer b
         1954  +|   2032: 75 6d 6d 32 34 63 34 35 32 30 32 37 37 34 33 31   umm24c4520277431
         1955  +|   2048: 35 66 36 33 36 66 36 65 36 36 36 39 36 37 32 37   5f636f6e66696727
         1956  +|   2064: 32 38 36 62 32 30 35 30 35 32 34 39 34 64 34 31   286b205052494d41
         1957  +|   2080: 35 32 35 39 32 30 34 62 34 35 35 39 32 63 32 30   5259204b45592c20
         1958  +|   2096: 0a 37 36 32 39 32 30 35 37 34 39 35 34 34 38 34   .762920574954484
         1959  +|   2112: 66 35 35 35 34 32 30 35 32 34 66 35 37 34 39 34   f555420524f57494
         1960  +|   2128: 34 35 62 30 35 30 37 31 37 32 31 32 31 30 31 38   45b0507172121018
         1961  +|   2144: 31 30 31 37 34 36 31 36 32 36 63 36 35 37 34 33   1017461626c65743
         1962  +|   2160: 31 35 66 36 34 36 66 36 33 37 33 0a 36 39 37 61   15f646f6373.697a
         1963  +|   2176: 36 35 37 34 33 31 35 66 36 34 36 66 36 33 37 33   6574315f646f6373
         1964  +|   2192: 36 39 37 61 36 35 30 35 34 33 35 32 34 35 34 31   697a650543524541
         1965  +|   2208: 35 34 34 35 32 30 35 34 38 36 39 36 34 32 30 34   5445205486964204
         1966  +|   2224: 39 34 65 35 34 34 35 34 37 34 35 35 32 32 30 35   94e5445474552205
         1967  +|   2240: 30 35 32 34 39 34 34 64 31 0a 35 32 35 39 32 30   0524944d1.525920
         1968  +|   2256: 34 62 34 35 35 39 32 63 32 30 36 33 33 30 32 39   4b45592c20633029
         1969  +|   2272: 36 39 30 33 30 30 30 31 35 37 35 33 31 31 39 32   6903000157531192
         1970  +|   2288: 36 64 37 34 36 31 36 32 36 63 36 35 37 34 33 31   6d7461626c657431
         1971  +|   2304: 35 66 36 39 36 34 37 38 37 34 33 31 35 66 36 39   5f69647874315f69
         1972  +|   2320: 36 34 37 38 0a 30 33 34 33 35 32 34 35 34 31 35   6478.03435245415
         1973  +|   2336: 34 34 35 32 30 35 34 34 31 34 32 34 63 34 35 32   445205441424c452
         1974  +|   2352: 30 32 37 37 34 33 31 35 66 36 39 01 0e 37 38 32   02774315f69..782
         1975  +|   2368: 37 32 38 37 33 36 35 36 37 36 39 36 34 32 63 32   72873656769642c2
         1976  +|   2384: 30 37 34 36 35 37 32 36 64 32 63 32 30 37 30 0a   07465726d2c2070.
         1977  +|   2400: 36 37 36 65 36 66 32 63 32 30 35 30 35 32 34 39   676e6f2c20505249
         1978  +|   2416: 34 64 34 31 35 32 35 39 32 30 34 62 34 35 35 39   4d415259204b4559
         1979  +|   2432: 32 38 37 33 36 35 36 37 36 39 36 34 32 63 32 30   2873656769642c20
         1980  +|   2448: 37 34 36 35 37 32 36 64 32 39 32 39 32 30 35 37   7465726d29292057
         1981  +|   2464: 34 39 35 34 34 38 34 66 35 35 0a 35 34 32 30 35   4954484f55.54205
         1982  +|   2480: 32 34 66 35 37 34 39 34 34 35 35 30 32 30 37 31   24f5749445502071
         1983  +|   2496: 37 31 62 31 62 30 31 38 31 30 31 37 34 36 31 36   71b1b01810174616
         1984  +|   2512: 32 36 63 36 35 37 34 33 31 35 66 31 37 34 36 31   26c6574315f17461
         1985  +|   2528: 30 32 34 33 0a 35 32 34 35 34 31 35 34 34 35 32   0243.52454154452
         1986  +|   2544: 30 35 34 34 31 34 32 34 63 34 c3 b0 35 32 30 32   05441424c4..5202
         1987  +|   2560: 37 37 34 33 31 35 66 36 34 36 31 37 34 36 31 32   774315f646174612
         1988  +|   2576: 37 32 38 36 39 36 34 32 30 34 39 34 65 35 34 34   728696420494e544
         1989  +|   2592: 35 34 37 34 35 35 32 32 30 35 30 35 32 34 39 34   5474552205052494
         1990  +|   2608: 64 0a 34 31 35 32 35 39 32 30 34 62 34 35 35 39   d.415259204b4559
         1991  +|   2624: 32 63 32 30 36 32 36 63 36 66 36 33 36 62 32 30   2c20626c6f636b20
         1992  +|   2640: 34 32 34 63 34 66 34 32 32 39 33 61 30 21 30 36   424c4f42293a0!06
         1993  +|   2656: 31 37 31 31 31 31 30 38 36 33 37 34 36 31 36 32   1711110863746162
         1994  +|   2672: 36 63 36 35 37 34 33 31 37 34 33 31 0a 34 33 35   6c6574317431.435
         1995  +|   2688: 32 34 35 34 31 35 34 34 35 32 30 35 36 34 39 35   2454154452056495
         1996  +|   2704: 32 35 34 37 35 34 31 34 63 32 30 35 34 34 31 34   25475414c2054414
         1997  +|   2720: 32 34 63 34 35 32 30 37 34 33 31 32 30 35 35 35   24c4520743120555
         1998  +|   2736: 33 34 39 34 65 34 37 32 30 36 36 37 34 37 33 33   3494e47206674733
         1999  +|   2752: 35 32 38 36 33 36 66 0a 36 65 37 34 36 35 36 65   528636f.6e74656e
         2000  +|   2768: 37 34 32 39 30 64 30 30 30 30 30 30 30 33 30 66   74290d000000030f
         2001  +|   2784: 62 64 30 30 30 62 65 38 30 66 65 66 30 66 62 64   bd000be80fef0fbd
         2002  +|   2800: 0a 5b 31 66 62 64 5d 32 34 38 34 38 30 38 30 38   .[1fbd]248480808
         2003  +|   2816: 30 38 30 30 31 30 33 30 30 34 65 30 30 30 30 30   0800103004e00000
         2004  +|   2832: 30 31 65 30 36 33 30 36 31 36 32 36 31 36 33 36   01e0630616261636
         2005  +|   2848: 62 30 31 30 32 30 32 30 34 30 32 36 36 37 34 30   b010202040266740
         2006  +|   2864: 32 30 32 30 32 30 34 30 34 36 65 0a 36 34 36 66   2020204046e.646f
         2007  +|   2880: 36 65 30 54 30 32 30 32 30 34 30 61 30 37 30 35   6e0T0202040a0705
         2008  +|   2896: 30 31 30 33 30 30 31 30 30 33 30 33 30 66 30 61   0103001003030f0a
         2009  +|   2912: 30 33 30 30 32 34 30 30 30 30 30 30 30 30 30 31   0300240000000001
         2010  +|   2928: 30 31 30 31 30 30 30 31 30 31 30 31 30 31 30 61   010100010101010a
         2011  +|   2944: 30 30 30 30 30 30 0a 30 31 30 66 66 61 30 30 30   000000.010ffa000
         2012  +|   2960: 66 66 61 0a 5b 32 21 66 61 5d 30 35 30 34 30 39   ffa.[2!fa]050409
         2013  +|   2976: 30 63 30 31 30 32 30 64 30 30 30 30 30 30 30 33   0c01020d00000003
         2014  +|   2992: 30 66 65 30 30 30 30 66 66 36 30 66 65 63 30 66   0fe0000ff60fec0f
         2015  +|   3008: 66 30 0a 5b 33 66 65 30 5d 30 61 30 33 30 33 30   f0.[3fe0]0a03030
         2016  +|   3024: 30 31 62 36 31 36 32 36 31 36 65 36 34 36 66 36   01b6162616e646f6
         2017  +|   3040: 65 30 38 30 32 30 33 30 30 31 37 36 31 36 32 36   e080203001761626
         2018  +|   3056: 31 36 36 37 34 30 38 30 31 30 33 30 30 31 37 36   1667408010300176
         2019  +|   3072: 31 36 32 36 31 36 33 36 62 30 64 30 30 0a 30 30   16261636b0d00.00
         2020  +|   3088: 30 30 30 33 30 66 65 65 30 30 30 66 66 61 30 66   00030fee000ffa0f
         2021  +|   3104: 66 34 30 66 65 65 0a 5b 34 66 65 65 5d 30 34 30   f40fee.[4fee]040
         2022  +|   3120: 33 30 33 30 30 30 65 30 31 30 34 30 32 30 33 30   303000e010402030
         2023  +|   3136: 30 30 65 30 31 30 34 30 31 30 33 30 30 30 65 30   00e01040103000e0
         2024  +|   3152: 31 30 61 30 30 30 30 30 30 30 31 30 66 66 34 30   10a000000010ff40
         2025  +|   3168: 30 30 66 66 34 0a 5b 35 66 66 34 5d 30 62 30 33   00ff4.[5ff4]0b03
         2026  +|   3184: 31 62 30 31 37 36 36 35 37 32 37 33 36 39 36 66   1b0176657273696f
         2027  +|   3200: 36 65 30 34 30 64 30 30 30 30 30 30 30 33 30 66   6e040d000000030f
         2028  +|   3216: 64 36 30 30 30 66 66 34 30 66 65 31 30 66 64 36   d6000ff40fe10fd6
         2029  +|   3232: 0a 5b 36 66 64 36 5d 30 39 30 33 30 32 31 62 37   .[6fd6]0903021b7
         2030  +|   3248: 32 36 35 36 32 37 35 36 34 36 31 37 34 36 31 37   2656275646174617
         2031  +|   3264: 34 33 31 35 66 36 34 36 31 37 34 36 31 30 32 34   4315f64617461024
         2032  +|   3280: 33 0a 35 32 34 35 34 31 35 34 34 35 32 30 35 34   3.52454154452054
         2033  +|   3296: 34 31 34 32 34 63 34 35 32 30 32 37 37 34 33 31   41424c4520277431
         2034  +|   3312: 35 66 36 34 36 31 37 34 36 31 32 37 32 38 36 39   5f64617461272869
         2035  +|   3328: 36 34 32 30 34 39 c2 81 65 35 34 34 35 34 37 34   642049..e5445474
         2036  +|   3344: 35 35 32 32 30 35 30 35 32 34 39 34 64 0a 34 31   552205052494d.41
         2037  +|   3360: 35 32 35 39 32 30 34 62 34 35 35 39 32 63 32 30   5259204b45592c20
         2038  +|   3376: 36 32 36 63 36 66 36 33 36 62 32 30 34 32 34 63   626c6f636b20424c
         2039  +|   3392: 34 66 34 32 32 39 33 61 30 31 30 36 31 37 31 31   4f42293a01061711
         2040  +|   3408: 31 31 30 38 36 33 37 34 36 31 36 32 36 63 36 35   1108637461626c65
         2041  +|   3424: 37 34 33 31 37 34 33 31 0a 34 33 35 32 34 35 34   74317431.4352454
         2042  +|   3440: 31 35 34 34 35 32 30 35 36 34 39 35 32 35 34 37   1544520564952547
         2043  +|   3456: 35 34 31 34 63 32 30 35 34 34 31 34 32 34 63 34   5414c205441424c4
         2044  +|   3472: 35 32 30 37 34 33 31 32 30 35 35 35 33 34 39 34   5207431205553494
         2045  +|   3488: 65 34 37 32 30 36 36 37 34 37 3b 33 35 32 38 36   e472066747;35286
         2046  +|   3504: 33 36 66 0a 36 65 37 34 36 35 36 65 37 34 32 39   36f.6e74656e7429
         2047  +|   3520: 30 64 30 30 30 30 30 30 30 33 30 66 62 64 30 30   0d000000030fbd00
         2048  +|   3536: 30 66 65 38 30 66 65 66 30 66 62 64 0a 5b 31 66   0fe80fef0fbd.[1f
         2049  +|   3552: 62 64 5d 32 34 38 34 38 30 38 30 38 30 38 30 30   bd]2484808080800
         2050  +|   3568: 31 30 33 30 30 34 65 30 30 30 30 30 30 31 65 30   103004e0000001e0
         2051  +|   3584: 36 33 30 36 31 36 32 36 31 36 33 36 62 30 31 30   630616261636b010
         2052  +|   3600: 32 30 32 30 34 30 32 36 36 37 34 30 32 30 32 30   2020402667402020
         2053  +|   3616: 32 30 34 30 34 36 65 0a 36 34 36 66 36 65 30 33   204046e.646f6e03
         2054  +|   3632: 30 32 30 32 30 34 30 61 30 37 30 35 30 31 30 33   0202040a07050103
         2055  +|   3648: 30 30 31 30 30 33 30 33 30 66 30 61 30 33 30 30   001003030f0a0300
         2056  +|   3664: 32 34 30 30 30 30 30 30 30 30 30 31 30 31 30 31   2400000000010101
         2057  +|   3680: 30 30 30 31 30 31 30 31 30 31 30 61 30 30 30 30   00010101010a0000
         2058  +|   3696: 30 30 0a 30 31 30 66 66 61 30 30 30 66 66 61 0a   00.010ffa000ffa.
         2059  +|   3712: 5b 32 66 29 61 5d 30 35 30 34 30 39 30 63 30 31   [2f)a]0504090c01
         2060  +|   3728: 30 32 30 64 30 30 30 30 30 30 30 33 30 66 65 30   020d000000030fe0
         2061  +|   3744: 30 30 30 66 66 36 30 66 65 63 30 66 65 30 0a 5b   000ff60fec0fe0.[
         2062  +|   3760: 33 66 65 30 5d 30 61 30 33 30 33 30 30 31 62 36   3fe0]0a0303001b6
         2063  +|   3776: 31 36 32 36 31 36 65 36 34 36 66 36 65 30 38 30   162616e646f6e080
         2064  +|   3792: 32 30 33 30 30 31 37 36 31 36 32 36 31 36 36 37   2030017616261667
         2065  +|   3808: 34 30 38 30 31 30 33 30 33 36 62 30 31 30 32 30   4080103036b01020
         2066  +|   3824: 32 30 34 30 32 36 36 37 34 30 32 30 32 30 32 30   2040266740202020
         2067  +|   3840: 34 30 34 36 65 0a 36 34 36 66 36 65 30 33 30 32   4046e.646f6e0302
         2068  +|   3856: 30 32 30 34 30 61 30 37 30 35 30 31 30 33 30 30   02040a0705010300
         2069  +|   3872: 31 30 30 33 30 33 30 66 30 61 30 33 30 30 32 34   1003030f0a030024
         2070  +|   3888: 30 30 30 30 30 30 30 30 30 31 30 31 30 31 30 30   0000000001010100
         2071  +|   3904: 30 31 30 31 30 31 30 30 39 61 30 30 30 30 30 30   010101009a000000
         2072  +|   3920: 0a 30 31 30 66 66 61 30 30 30 66 66 61 0a 5b 32   .010ffa000ffa.[2
         2073  +|   3936: 66 65 72 20 62 61 63 6b 75 70 4a 08 04 00 81 19   fer backupJ.....
         2074  +|   3952: 61 6c 70 68 61 20 63 68 61 6e 6e 65 6c 20 62 61   alpha channel ba
         2075  +|   3968: 63 6b 75 70 20 61 62 61 6e 64 6f 6e 20 74 65 62   ckup abandon teb
         2076  +|   3984: 20 73 74 61 61 63 6b 20 63 68 61 6e 6e 65 62 6f    staack channebo
         2077  +|   4000: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         2078  +|   4016: 61 63 74 69 76 65 09 07 03 00 19 61 74 6f 6d 69   active.....atomi
         2079  +|   4032: 63 07 06 03 00 15 61 74 6b 6d 00 00 00 0b 19 62   c.....atkm.....b
         2080  +|   4048: 6f 6f 6d 65 72 09 04 03 00 19 61 63 74 69 76 65   oomer.....active
         2081  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         2082  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         2083  +| page 5 offset 16384
         2084  +|      0: 0d 00 00 00 08 0f d0 00 0f fa 0f f4 0f ee 0f e8   ................
         2085  +|     16: 0f e2 0f dc 0f d6 0f d0 00 00 00 00 00 00 00 00   ................
         2086  +|   4048: 04 08 03 00 0e 0a 04 07 03 00 0e 01 04 06 03 00   ................
         2087  +|   4064: 0e 01 04 05 03 00 0e 31 04 04 03 00 0e 01 04 03   .......1........
         2088  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         2089  +| page 6 offset 20480
         2090  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         2091  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         2092  +| page 7 offset 24576
         2093  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         2094  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         2095  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         2096  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         2097  +| end c22b.db
         2098  +}]} {}
         2099  +
         2100  +
         2101  +do_catchsql_test 22.1 {
         2102  +  INSERT INTO t1(t1) VALUES('optimize');
         2103  +} {1 {vtable constructor failed: t1}}
         2104  +
         2105  +#--------------------------------------------------------------------------
         2106  +reset_db
         2107  +do_test 23.0 {
         2108  +  sqlite3 db {}
         2109  +  db deserialize [decode_hexdb {
         2110  +| size 28672 pagesize 4096 filename c24b.db
         2111  +| page 1 offset 0
         2112  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         2113  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
         2114  +|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04   ................
         2115  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         2116  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
         2117  +|     96: 00 2e 30 38 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..08...........m
         2118  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
         2119  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         2120  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         2121  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         2122  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         2123  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         2124  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         2125  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         2126  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         2127  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         2128  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         2129  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         2130  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         2131  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         2132  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         2133  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         2134  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         2135  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         2136  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         2137  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         2138  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         2139  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         2140  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         2141  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         2142  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         2143  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         2144  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         2145  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         2146  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         2147  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         2148  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         2149  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         2150  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         2151  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         2152  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         2153  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         2154  +| page 2 offset 4096
         2155  +|      0: 0d 0f 1c 00 05 0e cb 00 0f e8 0e cb 0f bd 0f 30   ...............0
         2156  +|     16: 0e e2 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         2157  +|   3776: 00 00 00 00 00 00 00 00 00 00 00 15 0a 03 00 30   ...............0
         2158  +|   3792: 00 00 00 00 01 03 03 00 03 01 01 01 02 01 01 03   ................
         2159  +|   3808: 01 01 33 8c 80 80 80 80 01 03 00 6c 00 00 00 2c   ..3........l...,
         2160  +|   3824: 07 30 62 61 63 6b 75 70 05 02 04 02 05 65 61 6d   .0backup.....eam
         2161  +|   3840: 65 72 05 02 02 02 05 6f 6f 6d 65 72 05 01 02 05   er.....oomer....
         2162  +|   3856: 75 6d 6d 65 72 05 02 03 04 0b 0a 09 0f ef 00 14   ummer...........
         2163  +|   3872: 2a 00 00 00 00 01 02 02 00 02 01 01 01 02 01 01   *...............
         2164  +|   3888: 81 05 88 80 80 80 80 01 04 00 82 0e 00 00 00 76   ...............v
         2165  +|   3904: 06 30 61 62 61 63 6b 08 02 07 04 04 6e 64 6f 6e   .0aback.....ndon
         2166  +|   3920: 08 02 05 02 05 63 74 69 76 65 04 02 02 04 02 0b   .....ctive......
         2167  +|   3936: 02 04 6c 70 68 61 08 02 0a 02 03 74 6f 6d 06 02   ..lpha.....tom..
         2168  +|   3952: 02 02 02 09 05 02 69 63 07 02 02 01 06 62 61 63   ......ic.....bac
         2169  +|   3968: 6b 75 70 08 02 04 02 05 6f 6f 6d 65 72 05 02 02   kup.....oomer...
         2170  +|   3984: 03 02 08 01 07 63 68 61 6e 6e 65 6c 08 02 03 01   .....channel....
         2171  +|   4000: 05 65 6c 70 68 61 08 02 02 01 04 74 65 73 74 08   .elpha.....test.
         2172  +|   4016: 02 06 04 0a 09 0d 09 0b 07 0b 0d 0c 0a 24 84 80   .............$..
         2173  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 02 61 23 25 23   ......N.....a#%#
         2174  +|   4048: 27 2b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   '+.....ft.....nd
         2175  +|   4064: 6f 6e 03 02 00 a0 42 70 05 01 03 00 10 08 13 00   on....Bp........
         2176  +|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         2177  +| page 3 offset 8192
         2178  +|      0: 0a 00 00 00 03 0f ec 00 0f fa 0f f3 0f ec 00 00   ................
         2179  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 06 04 01 0c   ................
         2180  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         2181  +| page 4 offset 12288
         2182  +|      0: 0d 0f ca 00 08 0f 57 00 0f f6 0f ec 0f e0 0f d5   ......W.........
         2183  +|     16: 0f 57 0f c1 0f b6 0f 70 00 00 00 00 00 00 00 00   .W.....p........
         2184  +|   3920: 00 00 00 00 00 00 00 17 05 03 00 35 62 65 61 6d   ...........5beam
         2185  +|   3936: 65 72 20 62 75 6d 6d 65 72 20 62 61 63 6b 75 70   er bummer backup
         2186  +|   3952: 44 08 04 00 81 0d 65 6c 70 68 61 20 63 68 61 6e   D.....elpha chan
         2187  +|   3968: 6e 65 6c 20 62 61 63 6b 75 70 20 61 62 61 6e 64   nel backup aband
         2188  +|   3984: 6f 6e 20 74 65 73 74 20 61 62 61 63 6b 20 62 6f   on test aback bo
         2189  +|   4000: 6f 6d 65 72 20 61 74 6f 6d 20 61 6c 70 68 61 20   omer atom alpha 
         2190  +|   4016: 61 63 74 69 76 65 09 07 03 00 19 61 74 6f 6d 69   active.....atomi
         2191  +|   4032: 63 07 06 03 00 15 61 74 6f 6d 00 00 00 0b 19 62   c.....atom.....b
         2192  +|   4048: 6f 6f 6d 65 72 09 04 03 00 19 61 63 74 69 76 65   oomer.....active
         2193  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
         2194  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         2195  +| page 5 offset 16384
         2196  +|      0: 0d 00 00 00 08 0f d0 00 0f fa 0f f4 0f ee 0f e8   ................
         2197  +|     16: 0f e2 0f dc 0f d6 0f d0 00 00 00 00 00 00 00 00   ................
         2198  +|   4048: 04 08 03 00 0e 0a 04 07 03 00 0e 01 04 06 03 00   ................
         2199  +|   4064: 0e 01 04 05 03 00 0e 03 04 04 03 00 0e 01 04 03   ................
         2200  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         2201  +| page 6 offset 20480
         2202  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         2203  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         2204  +| page 7 offset 24576
         2205  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
         2206  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         2207  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         2208  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         2209  +| end c24b.db
         2210  +}]} {}
         2211  +
         2212  +do_catchsql_test 23.1 {
         2213  +  INSERT INTO t1(t1) VALUES('optimize');
         2214  +} {1 {database disk image is malformed}}
         2215  +
         2216  +#--------------------------------------------------------------------------
         2217  +reset_db
         2218  +do_test 24.0 {
         2219  +  sqlite3 db {}
         2220  +  db deserialize [decode_hexdb {
         2221  +| size 32768 pagesize 4096 filename crash-b87dfef02880fe.db
         2222  +| page 1 offset 0
         2223  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         2224  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 08   .....@  ........
         2225  +|     32: 00 00 00 02 00 00 00 01 00 00 00 09 00 00 00 04   ................
         2226  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         2227  +|     96: 00 00 00 00 0d 0f c7 00 07 0d 92 00 0f 8d 0f 36   ...............6
         2228  +|    112: 0e cb 0e 6b 0e 0e 0d b6 0d 92 0d 92 00 00 00 00   ...k............
         2229  +|   3472: 00 00 22 08 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         2230  +|   3488: 32 74 32 08 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         2231  +|   3504: 20 74 32 28 78 29 56 07 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         2232  +|   3520: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         2233  +|   3536: 6f 6e 66 69 67 07 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         2234  +|   3552: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         2235  +|   3568: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         2236  +|   3584: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 06    WITHOUT ROWID[.
         2237  +|   3600: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         2238  +|   3616: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         2239  +|   3632: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         2240  +|   3648: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         2241  +|   3664: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         2242  +|   3680: 59 2c 20 73 7a 20 42 4c 4f 42 29 5e 05 07 17 21   Y, sz BLOB)^...!
         2243  +|   3696: 21 01 81 07 74 61 62 6c 65 74 31 5f 63 6f 6e 74   !...tablet1_cont
         2244  +|   3712: 65 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 05 43 52   entt1_content.CR
         2245  +|   3728: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63   EATE TABLE 't1_c
         2246  +|   3744: 6f 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47   ontent'(id INTEG
         2247  +|   3760: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   ER PRIMARY KEY, 
         2248  +|   3776: 63 30 2c 20 63 31 2c 20 63 32 29 69 04 07 17 19   c0, c1, c2)i....
         2249  +|   3792: 19 01 81 2d 74 61 62 6c 65 74 31 5f 69 64 78 74   ...-tablet1_idxt
         2250  +|   3808: 31 5f 69 64 78 04 43 52 45 41 54 45 20 54 41 42   1_idx.CREATE TAB
         2251  +|   3824: 4c 45 20 27 74 31 5f 69 64 78 27 28 73 65 67 69   LE 't1_idx'(segi
         2252  +|   3840: 64 2c 20 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50   d, term, pgno, P
         2253  +|   3856: 52 49 4d 41 52 59 20 4b 45 59 28 73 65 67 69 64   RIMARY KEY(segid
         2254  +|   3872: 2c 20 74 65 72 6d 29 29 20 57 49 54 48 4f 55 54   , term)) WITHOUT
         2255  +|   3888: 20 52 4f 57 49 44 55 03 07 17 1b 1b 01 81 01 74    ROWIDU........t
         2256  +|   3904: 61 62 6c 65 74 31 5f 64 61 74 61 74 31 5f 64 61   ablet1_datat1_da
         2257  +|   3920: 74 61 03 43 52 45 41 54 45 20 54 41 42 4c 45 20   ta.CREATE TABLE 
         2258  +|   3936: 27 74 31 5f 64 61 74 61 27 28 69 64 20 49 4e 54   't1_data'(id INT
         2259  +|   3952: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59   EGER PRIMARY KEY
         2260  +|   3968: 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 38 02 06   , block BLOB)8..
         2261  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         2262  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         2263  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35   LE t1 USING fts5
         2264  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00   (a,b,c)...9.....
         2265  +| page 3 offset 8192
         2266  +|      0: 0d 00 00 00 03 0c 94 00 0f e6 0f ef 0c 94 00 00   ................
         2267  +|   3216: 00 00 00 00 86 4a 84 80 80 80 80 01 04 00 8d 18   .....J..........
         2268  +|   3232: 00 00 03 2b 02 30 30 01 02 06 01 02 06 01 02 06   ...+.00.........
         2269  +|   3248: 1f 02 03 01 02 03 01 02 03 01 08 32 30 31 36 30   ...........20160
         2270  +|   3264: 36 30 39 01 02 07 01 02 07 01 02 07 01 01 34 01   609...........4.
         2271  +|   3280: 02 05 01 02 05 01 02 05 01 01 35 01 02 04 01 02   ..........5.....
         2272  +|   3296: 04 01 02 04 02 07 30 30 30 30 30 30 30 1c 02 04   ......0000000...
         2273  +|   3312: 01 02 04 01 02 04 01 06 62 69 6e 61 72 79 03 06   ........binary..
         2274  +|   3328: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         2275  +|   3344: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         2276  +|   3360: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02   ................
         2277  +|   3376: 03 06 01 02 02 03 06 01 02 02 01 08 63 6f 6d 70   ............comp
         2278  +|   3392: 69 6c 65 72 01 02 02 01 02 02 01 02 02 01 06 64   iler...........d
         2279  +|   3408: 62 73 74 61 74 07 02 03 01 02 03 01 02 03 02 04   bstat...........
         2280  +|   3424: 65 62 75 67 04 02 02 01 02 02 01 02 02 01 06 65   ebug...........e
         2281  +|   3440: 6e 61 62 6c 65 07 02 02 01 02 02 01 02 02 01 02   nable...........
         2282  +|   3456: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02   ................
         2283  +|   3472: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01   ................
         2284  +|   3488: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02   ................
         2285  +|   3504: 02 01 02 02 02 08 78 74 65 6e 73 69 6f 6e 1f 02   ......xtension..
         2286  +|   3520: 04 01 02 04 01 02 04 01 04 66 74 73 34 1a 02 03   .........fts4...
         2287  +|   3536: 01 02 03 01 02 03 04 01 35 0d 02 03 01 02 03 01   ........5.......
         2288  +|   3552: 02 03 01 03 67 63 63 01 02 03 01 02 03 01 02 03   ....gcc.........
         2289  +|   3568: 02 06 65 6f 70 6f 6c 79 10 02 03 01 02 03 01 02   ..eopoly........
         2290  +|   3584: 03 01 05 6a 73 6f 6e 31 13 02 03 01 02 03 01 02   ...json1........
         2291  +|   3600: 03 01 04 6c 6f 61 64 1f 02 03 01 02 03 01 02 03   ...load.........
         2292  +|   3616: 01 03 6d 61 78 1c 02 02 01 02 02 01 02 02 02 05   ..max...........
         2293  +|   3632: 65 6d 6f 72 79 1c 02 03 01 02 03 01 02 03 04 04   emory...........
         2294  +|   3648: 73 79 73 35 16 02 03 01 02 03 01 02 03 01 06 6e   sys5...........n
         2295  +|   3664: 6f 63 61 73 65 02 06 01 02 02 03 06 01 02 02 03   ocase...........
         2296  +|   3680: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06   ................
         2297  +|   3696: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         2298  +|   3712: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         2299  +|   3728: 02 01 04 6f 6d 69 74 1f 02 02 01 02 02 01 02 02   ...omit.........
         2300  +|   3744: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 02   ................
         2301  +|   3760: 58 81 96 4d 01 06 01 02 02 03 06 01 02 02 03 06   X..M............
         2302  +|   3776: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         2303  +|   3792: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         2304  +|   3808: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02   ................
         2305  +|   3824: 01 0a 74 68 72 65 61 64 73 61 66 65 22 02 02 01   ..threadsafe....
         2306  +|   3840: 02 02 01 02 02 01 04 76 74 61 62 07 02 04 01 02   .......vtab.....
         2307  +|   3856: 04 01 02 04 01 01 78 01 06 01 01 02 01 06 01 01   ......x.........
         2308  +|   3872: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02   ................
         2309  +|   3888: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01   ................
         2310  +|   3904: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06   ................
         2311  +|   3920: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01   ................
         2312  +|   3936: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01   ................
         2313  +|   3952: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02   ................
         2314  +|   3968: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01   ................
         2315  +|   3984: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06   ................
         2316  +|   4000: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01   ................
         2317  +|   4016: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01   ................
         2318  +|   4032: 02 01 06 01 01 02 01 06 01 01 02 04 15 13 0c 0c   ................
         2319  +|   4048: 12 44 13 11 0f 47 13 0f 0c 0e 11 10 0f 0e 10 0f   .D...G..........
         2320  +|   4064: 44 0f 10 40 15 0f 07 01 03 00 14 24 5a 24 24 0f   D..@.......$Z$$.
         2321  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         2322  +| page 4 offset 12288
         2323  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
         2324  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         2325  +| page 5 offset 16384
         2326  +|      0: 0d 00 00 00 24 0c 0a 00 0f d8 0f af 0f 86 0f 74   ....$..........t
         2327  +|     16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5   .a.N./..........
         2328  +|     32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5   ...t.[.@.$......
         2329  +|     48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb   .......h.O.5....
         2330  +|     64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a   .......x.W.>.$..
         2331  +|   3072: 00 00 00 00 00 00 00 00 00 00 18 24 05 00 25 0f   ...........$..%.
         2332  +|   3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49   .THREADSAFE=0XBI
         2333  +|   3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41   NARY.#..%..THREA
         2334  +|   3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22   DSAFE=0XNOCASE..
         2335  +|   3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d   ..%..THREADSAFE=
         2336  +|   3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d   0XRTRIM.!..3..OM
         2337  +|   3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f   IT LOAD EXTENSIO
         2338  +|   3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f   NXBINARY. ..3..O
         2339  +|   3200: 4d 49 54 20 4c 4f 41 44 b2 04 55 85 44 54 e5 34   MIT LOAD..U.DT.4
         2340  +|   3216: 94 f4 e5 84 e4 f4 34 15 34 51 e1 f0 50 03 30 f1   ......4.4Q..P.0.
         2341  +|   3232: 74 f4 d4 95 42 04 c4 f4 14 42 04 55 85 44 54 e5   t...B....B.U.DT.
         2342  +|   3248: 34 94 f4 e5 85 25 45 24 94 d1 f1 e0 50 03 30 f1   4....%E$....P.0.
         2343  +|   3264: 94 d4 15 82 04 d4 54 d4 f5 25 93 d3 53 03 03 03   ......T..%..S...
         2344  +|   3280: 03 03 03 05 84 24 94 e4 15 25 91 f1 d0 50 03 30   .....$...%...P.0
         2345  +|   3296: f1 94 d4 15 82 04 d4 54 d4 f5 25 93 d3 53 03 03   .......T..%..S..
         2346  +|   3312: 03 03 03 03 05 84 e4 f4 34 15 34 51 e1 c0 50 03   ........4.4Q..P.
         2347  +|   3328: 30 f1 74 d4 15 82 04 d4 54 d4 f5 25 93 d3 53 03   0.t.....T..%..S.
         2348  +|   3344: 03 03 03 03 03 05 85 25 45 24 94 d1 81 b0 50 02   .......%E$....P.
         2349  +|   3360: 50 f1 94 54 e4 14 24 c4 52 05 25 45 24 54 55 84   P..T..$.R.%E$TU.
         2350  +|   3376: 24 94 e4 15 25 91 81 a0 50 02 50 f1 94 54 e4 14   $...%...P.P..T..
         2351  +|   3392: 24 c4 52 05 25 45 24 54 55 84 e4 f4 34 15 34 51   $.R.%E$TU...4.4Q
         2352  +|   3408: 71 90 50 02 50 f1 74 54 e4 14 24 c4 52 05 25 45   q.P.P.tT..$.R.%E
         2353  +|   3424: 24 54 55 85 25 45 24 94 d1 a1 80 50 02 90 f1 94   $TU.%E$....P....
         2354  +|   3440: 54 e4 14 24 c4 52 04 d4 54 d5 35 95 33 55 84 24   T..$.R..T.5.3U.$
         2355  +|   3456: 94 e4 15 25 91 a1 70 50 02 90 f1 94 54 e4 14 24   ...%..pP....T..$
         2356  +|   3472: c4 52 04 d4 54 d5 35 95 33 55 84 e4 f4 34 15 34   .R..T.5.3U...4.4
         2357  +|   3488: 51 91 60 50 02 90 f1 74 54 e4 14 24 c4 52 04 d4   Q.`P...tT..$.R..
         2358  +|   3504: 54 d5 35 95 33 55 85 25 45 24 94 d1 81 50 50 02   T.5.3U.%E$...PP.
         2359  +|   3520: 50 f1 94 54 e4 14 24 c4 52 04 a5 34 f4 e3 15 84   P..T..$.R..4....
         2360  +|   3536: 24 94 e4 15 25 91 81 40 50 02 50 f1 94 54 e4 14   $...%..@P.P..T..
         2361  +|   3552: 24 c4 52 04 a5 34 f4 e3 15 84 e4 f4 34 15 34 51   $.R..4......4.4Q
         2362  +|   3568: 71 30 50 02 50 f1 74 54 e4 14 24 c4 52 04 a5 34   q0P.P.tT..$.R..4
         2363  +|   3584: f4 e3 15 85 25 45 24 94 d1 a1 20 50 02 90 f1 94   ....%E$... P....
         2364  +|   3600: 54 e4 14 24 c4 52 04 74 54 f5 04 f4 c5 95 84 24   T..$.R.tT......$
         2365  +|   3616: 94 e4 15 25 91 a1 10 50 02 90 f1 94 54 e4 14 24   ...%...P....T..$
         2366  +|   3632: c4 52 04 74 54 f5 04 f4 c5 95 84 e4 f4 34 15 34   .R.tT........4.4
         2367  +|   3648: 51 91 00 50 02 90 f1 74 54 e4 14 24 c4 52 04 74   Q..P...tT..$.R.t
         2368  +|   3664: 54 f5 04 f4 c5 95 85 25 45 24 94 d1 70 f0 50 02   T......%E$..p.P.
         2369  +|   3680: 30 f1 94 54 e4 14 24 c5 20 46 54 53 35 58 42 49   0..T..$. FTS5XBI
         2370  +|   3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c   NARY....#..ENABL
         2371  +|   3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05   E FTS5XNOCASE...
         2372  +|   3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58   .#..ENABLE FTS5X
         2373  +|   3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42   RTRIM....#..ENAB
         2374  +|   3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 97 0b   LE FTS4XBINARY..
         2375  +|   3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34   ..#..ENABLE FTS4
         2376  +|   3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e   XNOCASE....#..EN
         2377  +|   3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e   ABLE FTS4XRTRIM.
         2378  +|   3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         2379  +|   3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e   TAT VTABXBINARY.
         2380  +|   3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         2381  +|   3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d   TAT VTABXNOCASE.
         2382  +|   3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         2383  +|   3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06   TAT VTABXRTRIM..
         2384  +|   3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52   .....DEBUGXBINAR
         2385  +|   3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f   Y.......DEBUGXNO
         2386  +|   3952: 43 41 53 45 10 02 02 50 08 5f 17 44 45 42 55 47   CASE...P._.DEBUG
         2387  +|   3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d   XRTRIM'...C..COM
         2388  +|   3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20   PILER=gcc-5.4.0 
         2389  +|   4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27   20160609XBINARY'
         2390  +|   4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67   ...C..COMPILER=g
         2391  +|   4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30   cc-5.4.0 2016060
         2392  +|   4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43   9XNOCASE&...C..C
         2393  +|   4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e   OMPILER=gcc-5.4.
         2394  +|   4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d   0 20160609XRTRIM
         2395  +| page 6 offset 20480
         2396  +|      0: 0d 00 00 00 24 0e e0 00 0f f8 0f f0 0f e8 0f e0   ....$...........
         2397  +|     16: 0f d8 0f d0 0f c8 0f c0 0f b8 0f b0 0f a8 0f a0   ................
         2398  +|     32: 0f 98 0f 90 0f 88 0f 80 0f 78 0f 70 0f 68 0f 60   .........x.p.h.`
         2399  +|     48: 0f 58 0f 50 0f 48 0f 40 0f 38 0f 30 0f 28 0f 20   .X.P.H.@.8.0.(. 
         2400  +|     64: 0f 18 0f 10 0f 08 0f 00 0e f8 0e f0 0e e8 0e e0   ................
         2401  +|   3808: 06 24 03 00 12 02 01 01 06 23 03 00 12 02 01 01   .$.......#......
         2402  +|   3824: 06 22 03 00 12 02 01 01 06 21 03 00 12 03 01 01   .........!......
         2403  +|   3840: 06 20 03 00 12 03 01 01 06 1f 03 00 12 03 01 01   . ..............
         2404  +|   3856: 06 1e 03 00 12 03 01 01 06 1d 03 00 12 03 01 01   ................
         2405  +|   3872: 06 1c 03 00 12 03 01 01 06 1b 03 00 12 02 01 01   ................
         2406  +|   3888: 06 1a 03 00 12 02 01 01 06 19 03 00 12 02 01 01   ................
         2407  +|   3904: 06 18 03 00 12 02 01 01 06 17 03 00 12 02 01 01   ................
         2408  +|   3920: 06 16 03 00 12 02 01 01 06 15 03 00 12 02 01 01   ................
         2409  +|   3936: 06 14 03 00 12 02 01 01 06 13 03 00 12 02 01 01   ................
         2410  +|   3952: 06 12 03 00 12 02 01 01 06 11 03 00 12 02 01 01   ................
         2411  +|   3968: 06 10 03 00 12 02 01 01 06 0f 03 00 12 02 01 01   ................
         2412  +|   3984: 06 0e 03 00 12 02 01 01 06 0d 03 00 12 02 01 01   ................
         2413  +|   4000: 06 0c 03 00 12 02 01 01 06 0b 03 00 12 02 01 01   ................
         2414  +|   4016: 06 0a 03 00 12 02 01 01 06 09 03 00 12 03 01 01   ................
         2415  +|   4032: 06 08 03 00 12 03 01 01 06 07 03 00 12 03 01 01   ................
         2416  +|   4048: 06 06 03 00 12 01 01 01 06 05 03 00 12 01 01 01   ................
         2417  +|   4064: 06 04 03 00 12 01 01 01 06 03 03 00 12 06 01 01   ................
         2418  +|   4080: 06 02 03 00 12 06 01 01 06 01 03 00 12 06 01 01   ................
         2419  +| page 7 offset 24576
         2420  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         2421  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         2422  +| page 8 offset 28672
         2423  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e9 0f d6 00 00   ................
         2424  +|   4048: 00 00 00 00 00 00 11 03 02 2b 69 6e 74 65 67 72   .........+integr
         2425  +|   4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity-check....reb
         2426  +|   4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   uild....optimize
         2427  +| end crash-b87dfef02880fe.db
         2428  +}]} {}
         2429  +
         2430  +do_catchsql_test 24.1 {
         2431  +  UPDATE t1 SET b=quote(zeroblob(200)) WHERE a MATCH 'thread*';
         2432  +} {1 {database disk image is malformed}}
         2433  +
         2434  +do_catchsql_test 24.2 {
         2435  +  INSERT INTO t1(t1) VALUES('integrity-check');
         2436  +} {1 {database disk image is malformed}}
         2437  +
         2438  +#--------------------------------------------------------------------------
         2439  +reset_db
         2440  +do_test 25.0 {
         2441  +  sqlite3 db {}
         2442  +  db deserialize [decode_hexdb {
         2443  +| size 28672 pagesize 4096 filename crash-e3b1b19e4d4bcc.db
         2444  +| page 1 offset 0
         2445  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         2446  +|     16: 10 00 01 01 00 40 20 20 00 00 00 06 00 00 00 00   .....@  ........
         2447  +|     32: 00 00 00 00 00 00 00 06 00 00 00 04 00 00 00 00   ................
         2448  +|     48: 03 20 54 35 24 54 15 44 52 04 94 e4 44 55 82 07   . T5$T.DR...DU..
         2449  +|     64: 43 27 a2 04 f4 e2 07 43 22 87 a2 95 30 30 71 71   C'.....C....00qq
         2450  +|     80: 11 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33   .SQLite format 3
         2451  +|     96: 00 10 00 01 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
         2452  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 03 30 01 00 00 10   .....N.....0....
         2453  +|    128: 10 04 02 02 00 00 00 00 00 00 00 00 30 00 00 00   ............0...
         2454  +|    144: 00 00 00 00 00 00 00 00 20 00 00 00 40 00 00 00   ........ ...@...
         2455  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         2456  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         2457  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         2458  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         2459  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         2460  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         2461  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         2462  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
         2463  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         2464  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         2465  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         2466  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         2467  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         2468  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
         2469  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
         2470  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
         2471  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
         2472  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
         2473  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
         2474  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
         2475  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
         2476  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
         2477  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
         2478  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
         2479  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
         2480  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
         2481  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
         2482  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
         2483  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
         2484  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 d9 44   (id INTEGER PR.D
         2485  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
         2486  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
         2487  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         2488  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         2489  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
         2490  +| page 2 offset 4096
         2491  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
         2492  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
         2493  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
         2494  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
         2495  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
         2496  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         2497  +| page 3 offset 8192
         2498  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
         2499  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         2500  +| page 4 offset 12288
         2501  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f e0 fe 00 00 00   ................
         2502  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 00 03   .....abandon....
         2503  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
         2504  +| page 5 offset 16384
         2505  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f4 0f ee 00 00   ................
         2506  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
         2507  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
         2508  +| page 6 offset 20480
         2509  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         2510  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         2511  +| page 7 offset 24576
         2512  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 01 fe 0f d6 00 00   ................
         2513  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
         2514  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
         2515  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
         2516  +| end crash-e3b1b19e4d4bcc.db
         2517  +}]} {}
         2518  +
         2519  +do_catchsql_test 25.1 {
         2520  +  INSERT INTO t1(t1) VALUES('rebuild');
         2521  +} {1 {database disk image is malformed}}
         2522  +
         2523  +do_execsql_test 25.2 {
         2524  +  PRAGMA page_size=512;
         2525  +} 
         2526  +
         2527  +#--------------------------------------------------------------------------
         2528  +reset_db
         2529  +do_test 26.0 {
         2530  +  sqlite3 db {}
         2531  +  db deserialize [decode_hexdb {
         2532  +| size 32768 pagesize 4096 filename c30b.db
         2533  +| page 1 offset 0
         2534  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         2535  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 08   .....@  ........
         2536  +|     32: 00 00 00 02 00 00 00 01 00 00 00 01 00 00 00 04   ................
         2537  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         2538  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
         2539  +|     96: 00 2e 30 38 0d 0f c7 00 07 0d 92 00 0f 8d 0f 36   ..08...........6
         2540  +|    112: 0e cb 0e 6b 0e 0e 0d b6 0d 92 0d 92 00 00 00 00   ...k............
         2541  +|   3472: 00 00 22 08 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         2542  +|   3488: 32 74 32 08 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         2543  +|   3504: 20 74 32 28 78 29 56 07 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         2544  +|   3520: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         2545  +|   3536: 6f 6e 66 69 67 07 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         2546  +|   3552: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         2547  +|   3568: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         2548  +|   3584: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 06    WITHOUT ROWID[.
         2549  +|   3600: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         2550  +|   3616: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         2551  +|   3632: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         2552  +|   3648: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         2553  +|   3664: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         2554  +|   3680: 59 2c 20 73 7a 20 42 4c 4f 42 29 5e 05 07 17 21   Y, sz BLOB)^...!
         2555  +|   3696: 21 01 81 07 74 61 62 6c 65 74 31 5f 63 6f 6e 74   !...tablet1_cont
         2556  +|   3712: 65 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 05 43 52   entt1_content.CR
         2557  +|   3728: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63   EATE TABLE 't1_c
         2558  +|   3744: 6f 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47   ontent'(id INTEG
         2559  +|   3760: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   ER PRIMARY KEY, 
         2560  +|   3776: 63 30 2c 20 63 31 2c 20 63 32 29 69 04 07 17 19   c0, c1, c2)i....
         2561  +|   3792: 19 01 81 2d 74 61 62 6c 65 74 31 5f 69 64 78 74   ...-tablet1_idxt
         2562  +|   3808: 31 5f 69 64 78 04 43 52 45 41 54 45 20 54 41 42   1_idx.CREATE TAB
         2563  +|   3824: 4c 45 20 27 74 31 5f 69 64 78 27 28 73 65 67 69   LE 't1_idx'(segi
         2564  +|   3840: 64 2c 20 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50   d, term, pgno, P
         2565  +|   3856: 52 49 4d 41 52 59 20 4b 45 59 28 73 65 67 69 64   RIMARY KEY(segid
         2566  +|   3872: 2c 20 74 65 72 6d 29 29 20 57 49 54 48 4f 55 54   , term)) WITHOUT
         2567  +|   3888: 20 52 4f 57 49 44 55 03 07 17 1b 1b 01 81 01 74    ROWIDU........t
         2568  +|   3904: 61 62 6c 65 74 31 5f 64 61 74 61 74 31 5f 64 61   ablet1_datat1_da
         2569  +|   3920: 74 61 03 43 52 45 41 54 45 20 54 41 42 4c 45 20   ta.CREATE TABLE 
         2570  +|   3936: 27 74 31 5f 64 61 74 61 27 28 69 64 20 49 4e 54   't1_data'(id INT
         2571  +|   3952: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59   EGER PRIMARY KEY
         2572  +|   3968: 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 38 02 06   , block BLOB)8..
         2573  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         2574  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         2575  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35   LE t1 USING fts5
         2576  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00   (a,b,c)...9.....
         2577  +| page 3 offset 8192
         2578  +|      0: 0d 0c 0f 00 05 09 fe 00 0f e6 09 fe 0c 94 0c 23   ...............#
         2579  +|     16: 0a 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         2580  +|   2544: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 15 0a   ................
         2581  +|   2560: 03 00 30 00 00 00 00 01 03 03 00 03 01 01 01 02   ..0.............
         2582  +|   2576: 01 01 03 01 01 83 72 8c 80 80 80 80 01 04 00 87   ......r.........
         2583  +|   2592: 68 00 00 01 e4 02 30 30 03 03 06 02 83 0f 30 30   h.....00......00
         2584  +|   2608: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2585  +|   2624: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2586  +|   2640: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2587  +|   2656: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2588  +|   2672: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2589  +|   2688: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2590  +|   2704: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2591  +|   2720: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2592  +|   2736: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2593  +|   2752: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2594  +|   2768: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2595  +|   2784: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2596  +|   2800: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2597  +|   2816: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2598  +|   2832: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2599  +|   2848: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2600  +|   2864: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2601  +|   2880: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2602  +|   2896: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2603  +|   2912: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2604  +|   2928: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2605  +|   2944: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2606  +|   2960: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2607  +|   2976: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2608  +|   2992: 30 30 30 30 30 30 30 30 30 30 30 30 30 03 06 01   0000000000000...
         2609  +|   3008: 01 03 01 08 32 30 31 36 30 36 30 39 03 03 07 01   ....20160609....
         2610  +|   3024: 01 34 03 03 05 01 01 35 03 03 04 01 06 62 69 6e   .4.....5.....bin
         2611  +|   3040: 61 72 79 03 07 01 02 02 01 08 63 6f 6d 70 69 6c   ary.......compil
         2612  +|   3056: 65 72 03 03 02 01 03 67 63 63 03 03 03 01 01 78   er.....gcc.....x
         2613  +|   3072: 03 07 01 01 02 04 06 83 17 0d 06 06 0d 0d 08 0f   ................
         2614  +|   3088: ef 00 14 2a 00 00 00 00 01 02 02 00 02 01 01 01   ...*............
         2615  +|   3104: 02 01 01 6a 88 80 80 80 80 01 04 00 81 58 00 00   ...j.........X..
         2616  +|   3120: 00 5f 07 30 62 69 6e 61 72 79 0c 01 03 01 01 06   ._.0binary......
         2617  +|   3136: 65 6e 61 62 6c 65 0a 01 01 01 01 01 01 01 01 01   enable..........
         2618  +|   3152: 01 01 01 04 66 74 73 34 0a 01 01 01 01 01 04 01   ....fts4........
         2619  +|   3168: 35 0d 01 01 01 01 01 01 06 6e 6f 63 61 73 65 0b   5........nocase.
         2620  +|   3184: 01 03 01 01 05 72 74 72 69 6d 0a 01 03 01 01 01   .....rtrim......
         2621  +|   3200: 78 0a 01 01 01 01 01 01 01 01 01 01 01 04 0c 14   x...............
         2622  +|   3216: 0c 09 0c 0b 86 4a 84 80 80 80 80 01 04 00 8d 18   .....J..........
         2623  +|   3232: 00 00 03 2b 02 30 30 01 02 06 01 02 06 01 02 06   ...+.00.........
         2624  +|   3248: 1f 02 03 01 02 03 01 02 03 01 08 32 30 31 36 30   ...........20160
         2625  +|   3264: 36 30 39 01 02 07 01 02 07 01 02 07 01 01 34 01   609...........4.
         2626  +|   3280: 02 05 01 02 05 01 02 05 01 01 35 01 02 04 01 02   ..........5.....
         2627  +|   3296: 04 01 02 04 02 07 30 30 30 30 30 30 30 1c 02 04   ......0000000...
         2628  +|   3312: 01 02 04 01 02 04 01 06 62 69 6e 61 72 79 03 06   ........binary..
         2629  +|   3328: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         2630  +|   3344: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         2631  +|   3360: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02   ................
         2632  +|   3376: 03 06 01 02 02 03 06 01 02 02 01 08 63 6f 6d 70   ............comp
         2633  +|   3392: 69 6c 65 72 01 02 02 01 02 02 01 02 02 01 06 64   iler...........d
         2634  +|   3408: 62 73 74 61 74 07 02 03 01 02 03 01 02 03 02 04   bstat...........
         2635  +|   3424: 65 62 75 67 04 02 02 01 02 02 01 02 02 01 06 65   ebug...........e
         2636  +|   3440: 6e 61 62 6c 65 07 02 02 01 02 02 01 02 02 01 02   nable...........
         2637  +|   3456: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02   ................
         2638  +|   3472: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01   ................
         2639  +|   3488: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02   ................
         2640  +|   3504: 02 01 02 02 02 08 78 74 65 6e 73 69 6f 6e 1f 02   ......xtension..
         2641  +|   3520: 04 01 02 04 01 02 04 01 04 66 74 73 34 0a 02 03   .........fts4...
         2642  +|   3536: 01 02 03 01 02 03 04 01 35 0d 02 03 01 02 03 01   ........5.......
         2643  +|   3552: 02 03 01 03 67 63 63 01 02 03 01 02 03 01 02 03   ....gcc.........
         2644  +|   3568: 02 06 65 6f 70 6f 6c 79 10 02 03 01 02 03 01 02   ..eopoly........
         2645  +|   3584: 03 01 05 6a 73 6f 6e 31 13 02 03 01 02 03 01 02   ...json1........
         2646  +|   3600: 03 01 04 6c 6f 61 64 1f 02 03 01 02 03 01 02 03   ...load.........
         2647  +|   3616: 01 03 6d 61 78 1c 02 02 01 02 02 01 02 02 02 05   ..max...........
         2648  +|   3632: 65 6d 6f 72 79 1c 02 03 01 02 03 01 02 03 04 04   emory...........
         2649  +|   3648: 73 79 73 35 16 02 03 01 02 03 01 02 03 01 06 6e   sys5...........n
         2650  +|   3664: 6f 63 61 73 65 02 06 01 02 02 03 06 01 02 02 03   ocase...........
         2651  +|   3680: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06   ................
         2652  +|   3696: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         2653  +|   3712: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         2654  +|   3728: 02 01 04 6f 6d 69 74 1f 02 02 01 02 02 01 02 02   ...omit.........
         2655  +|   3744: 01 05 72 74 72 65 65 19 02 03 01 02 03 01 02 03   ..rtree.........
         2656  +|   3760: 04 02 69 6d 01 06 01 02 02 03 06 01 02 02 03 06   ..im............
         2657  +|   3776: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         2658  +|   3792: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         2659  +|   3808: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02   ................
         2660  +|   3824: 01 0a 74 68 72 65 61 64 73 61 66 65 03 57 34 56   ..threadsafe.W4V
         2661  +|   3840: 94 64 91 46 85 84 04 76 74 61 62 07 02 04 01 02   .d.F...vtab.....
         2662  +|   3856: 04 01 02 04 01 01 78 01 06 01 01 02 01 06 01 01   ......x.........
         2663  +|   3872: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 10 02   ................
         2664  +|   3888: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01   ................
         2665  +|   3904: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06   ................
         2666  +|   3920: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01   ................
         2667  +|   3936: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01   ................
         2668  +|   3952: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02   ................
         2669  +|   3968: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01   ................
         2670  +|   3984: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06   ................
         2671  +|   4000: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01   ................
         2672  +|   4016: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01   ................
         2673  +|   4032: 02 01 06 01 01 02 01 06 01 01 02 04 15 13 0c 0c   ................
         2674  +|   4048: 12 44 13 11 0f 47 13 0f 0c 0e 11 10 0f 0e 10 0f   .D...G..........
         2675  +|   4064: 44 0f 10 40 15 0f 07 01 03 00 14 1e 4e 1f 1e 00   D..@........N...
         2676  +|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         2677  +| page 4 offset 12288
         2678  +|      0: 0a 00 00 00 03 0f ec 00 0f fa 0f f3 0f ec 00 00   ................
         2679  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 06 04 01 0c   ................
         2680  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         2681  +| page 5 offset 16384
         2682  +|      0: 0d 0e 5b 00 1e 0a 4d 00 0f d8 0f af 0a 4d 0f 74   ..[...M......M.t
         2683  +|     16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e 40 0e 24 0e 08   .a.N./.....@.$..
         2684  +|     32: 0d ef 0d d5 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35   ...........h.O.5
         2685  +|     48: 0d 1b 0c fb 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e   ...........x.W.>
         2686  +|     64: 0c 24 0c 0a 0c 0a 0c 0a 0c 0a 0c 0a 0c 0a 0c 0a   .$..............
         2687  +|   2624: 00 00 00 00 00 00 00 00 00 00 00 00 00 83 3a 03   ..............:.
         2688  +|   2640: 06 00 43 86 33 19 43 4f 4d 50 49 4c 45 52 3d 67   ..C.3.COMPILER=g
         2689  +|   2656: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30   cc-5.4.0 2016060
         2690  +|   2672: 39 58 27 30 30 30 30 30 30 30 30 30 30 30 30 30   9X'0000000000000
         2691  +|   2688: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2692  +|   2704: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2693  +|   2720: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2694  +|   2736: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2695  +|   2752: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2696  +|   2768: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2697  +|   2784: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2698  +|   2800: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2699  +|   2816: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2700  +|   2832: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2701  +|   2848: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2702  +|   2864: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2703  +|   2880: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2704  +|   2896: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2705  +|   2912: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2706  +|   2928: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2707  +|   2944: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2708  +|   2960: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2709  +|   2976: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2710  +|   2992: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2711  +|   3008: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2712  +|   3024: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2713  +|   3040: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2714  +|   3056: 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30   0000000000000000
         2715  +|   3072: 30 30 30 27 42 49 4e 41 52 59 18 24 05 00 25 0f   000'BINARY.$..%.
         2716  +|   3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49   .THREADSAFE=0XBI
         2717  +|   3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41   NARY.#..%..THREA
         2718  +|   3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22   DSAFE=0XNOCASE..
         2719  +|   3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d   ..%..THREADSAFE=
         2720  +|   3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d   0XRTRIM.!..3..OM
         2721  +|   3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f   IT LOAD EXTENSIO
         2722  +|   3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f   NXBINARY. ..3..O
         2723  +|   3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49   MIT LOAD EXTENSI
         2724  +|   3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17   ONXNOCASE....3..
         2725  +|   3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53   OMIT LOAD EXTENS
         2726  +|   3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19   IONXRTRIM....3..
         2727  +|   3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30   MAX MEMORY=50000
         2728  +|   3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f   000XBINARY....3.
         2729  +|   3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30   .MAX MEMORY=5000
         2730  +|   3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33   0000XNOCASE....3
         2731  +|   3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30   ..MAX MEMORY=500
         2732  +|   3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25   00000XRTRIM....%
         2733  +|   3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42   ..ENABLE RTREEXB
         2734  +|   3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         2735  +|   3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17   LE RTREEXNOCASE.
         2736  +|   3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52   ...%..ENABLE RTR
         2737  +|   3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45   EEXRTRIM....)..E
         2738  +|   3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49   NABLE MEMSYS5XBI
         2739  +|   3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         2740  +|   3472: 42 60 2d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45   B`-EMSYS5XNOCASE
         2741  +|   3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45   ....)..ENABLE ME
         2742  +|   3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25   MSYS5XRTRIM....%
         2743  +|   3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42   ..ENABLE JSON1XB
         2744  +|   3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         2745  +|   3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17   LE JSON1XNOCASE.
         2746  +|   3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f   ...%..ENABLE JSO
         2747  +|   3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45   N1XRTRIM....)..E
         2748  +|   3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49   NABLE GEOPOLYXBI
         2749  +|   3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         2750  +|   3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45   E GEOPOLYXNOCASE
         2751  +|   3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45   ....)..ENABLE GE
         2752  +|   3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 0f 86 00 94 23   OPOLYXRTRIM....#
         2753  +|   3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49   ..ENABLE FTS5XBI
         2754  +|   3696: 4e 41 52 59 00 00 00 7b 23 0f 19 45 4e 41 42 4c   NARY....#..ENABL
         2755  +|   3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 00 00 00   E FTS5XNOCASE...
         2756  +|   3728: 62 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58   b#..ENABLE FTS5X
         2757  +|   3744: 52 54 52 49 4d 00 00 00 4a 23 0f 19 45 4e 41 42   RTRIM...J#..ENAB
         2758  +|   3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 00 00   LE FTS4XBINARY..
         2759  +|   3776: 00 31 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34   .1#..ENABLE FTS4
         2760  +|   3792: 58 4e 4f 43 41 53 45 00 00 00 18 23 0f 17 45 4e   XNOCASE....#..EN
         2761  +|   3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e   ABLE FTS4XRTRIM.
         2762  +|   3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         2763  +|   3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e   TAT VTABXBINARY.
         2764  +|   3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         2765  +|   3872: 54 41 54 20 56 54 24 15 48 4e 4f 43 41 53 45 1d   TAT VT$.HNOCASE.
         2766  +|   3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         2767  +|   3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06   TAT VTABXRTRIM..
         2768  +|   3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52   .....DEBUGXBINAR
         2769  +|   3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f   Y.......DEBUGXNO
         2770  +|   3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47   CASE.......DEBUG
         2771  +|   3968: 58 52 54 52 49 4d 00 00 00 29 43 0f 19 43 4f 4d   XRTRIM...)C..COM
         2772  +|   3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20   PILER=gcc-5.4.0 
         2773  +|   4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27   20160609XBINARY'
         2774  +|   4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67   ...C..COMPILER=g
         2775  +|   4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30   cc-5.4.0 2016060
         2776  +|   4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43   9XNOCASE&...C..C
         2777  +|   4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e   OMPILER=gcc-5.4.
         2778  +|   4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d   0 20160609XRTRIM
         2779  +| page 6 offset 20480
         2780  +|      0: 0d 0f 88 00 1e 0e e0 00 0f f8 0f f0 0f b0 0f e0   ................
         2781  +|     16: 0f d8 0f d0 0f c8 0f c0 0f b8 0f 80 0f 78 0f 70   .............x.p
         2782  +|     32: 0f 68 0f 60 0f 58 0f 50 0f 48 0f 40 0f 38 0f 30   .h.`.X.P.H.@.8.0
         2783  +|     48: 0f 28 0f 20 0f 18 0f 10 0f 08 0f 00 0e f8 0e f0   .(. ............
         2784  +|     64: 0e e8 0e e0 0e e0 0e e0 0e e0 0e e0 0e e0 0e e0   ................
         2785  +|   3808: 06 24 03 00 12 02 01 01 06 23 03 00 12 02 01 01   .$.......#......
         2786  +|   3824: 06 22 03 00 12 02 01 01 06 21 03 00 12 03 01 01   .........!......
         2787  +|   3840: 06 20 03 00 12 03 01 01 06 1f 03 00 12 03 01 01   . ..............
         2788  +|   3856: 06 1e 03 00 12 03 01 01 06 1d 03 00 12 03 01 01   ................
         2789  +|   3872: 06 1c 03 00 12 03 01 01 06 1b 03 00 12 02 01 01   ................
         2790  +|   3888: 06 1a 03 00 12 02 01 01 06 19 03 00 12 02 01 01   ................
         2791  +|   3904: 06 18 03 00 12 02 01 01 06 17 03 00 12 02 01 01   ................
         2792  +|   3920: 06 16 03 00 12 02 01 01 06 15 03 00 12 02 01 01   ................
         2793  +|   3936: 06 14 03 00 12 02 01 01 06 13 03 00 12 02 01 01   ................
         2794  +|   3952: 06 12 03 00 12 02 01 01 06 11 03 00 12 02 01 01   ................
         2795  +|   3968: 06 10 03 00 12 02 01 01 0f e8 00 28 12 02 01 01   ...........(....
         2796  +|   3984: 00 00 00 28 12 02 01 01 00 00 00 20 12 02 01 01   ...(....... ....
         2797  +|   4000: 00 00 00 18 12 02 01 01 00 00 00 10 12 02 01 01   ................
         2798  +|   4016: 06 03 03 00 12 06 02 01 06 09 03 00 12 03 01 01   ................
         2799  +|   4032: 06 08 03 00 12 03 01 01 06 07 03 00 12 03 01 01   ................
         2800  +|   4048: 06 06 03 00 12 01 01 01 06 05 03 00 12 01 01 01   ................
         2801  +|   4064: 06 04 03 00 12 01 01 01 00 00 00 08 12 06 01 01   ................
         2802  +|   4080: 06 02 03 00 12 06 01 01 06 01 03 00 12 06 01 01   ................
         2803  +| page 7 offset 24576
         2804  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         2805  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         2806  +| page 8 offset 28672
         2807  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e9 0f d6 00 00   ................
         2808  +|   4048: 00 00 00 00 00 00 11 03 02 2b 69 6e 74 65 67 72   .........+integr
         2809  +|   4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity-check....reb
         2810  +|   4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   uild....optimize
         2811  +| end c30b.db
         2812  +}]} {}
         2813  +
         2814  +do_catchsql_test 26.1 {
         2815  +  BEGIN;
         2816  +    INSERT INTO t1(t1) VALUES('rebuild');
         2817  +    INSERT INTO t1(t1) VALUES('integrity-check');
         2818  +  COMMIT;
         2819  +} {0 {}}
         2820  +
         2821  +#--------------------------------------------------------------------------
         2822  +reset_db
         2823  +do_test 27.0 {
         2824  +  sqlite3 db {}
         2825  +  db deserialize [decode_hexdb {
         2826  +| size 32768 pagesize 4096 filename timeout-2ca5b0658c98.db
         2827  +| page 1 offset 0
         2828  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         2829  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 08   .....@  ........
         2830  +|     32: 00 00 00 02 00 00 00 01 00 00 00 09 00 00 00 04   ................
         2831  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         2832  +|     96: 00 00 00 00 0d 0f c7 00 07 0d 92 00 0f 8d 0f 36   ...............6
         2833  +|    112: 0e cb 0e 6b 0e 0e 0d b6 0d 92 0d 92 00 00 00 00   ...k............
         2834  +|   3472: 00 00 22 08 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         2835  +|   3488: 32 74 32 08 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         2836  +|   3504: 20 74 32 28 78 29 56 07 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         2837  +|   3520: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         2838  +|   3536: 6f 6e 66 69 67 07 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         2839  +|   3552: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         2840  +|   3568: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         2841  +|   3584: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 06    WITHOUT ROWID[.
         2842  +|   3600: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         2843  +|   3616: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         2844  +|   3632: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         2845  +|   3648: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         2846  +|   3664: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         2847  +|   3680: 59 2c 20 73 7a 20 42 4c 4f 42 29 5e 05 07 17 21   Y, sz BLOB)^...!
         2848  +|   3696: 21 01 81 07 74 61 62 6c 65 74 31 5f 63 6f 6e 74   !...tablet1_cont
         2849  +|   3712: 65 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 05 43 52   entt1_content.CR
         2850  +|   3728: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63   EATE TABLE 't1_c
         2851  +|   3744: 6f 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47   ontent'(id INTEG
         2852  +|   3760: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   ER PRIMARY KEY, 
         2853  +|   3776: 63 30 2c 20 63 31 2c 20 63 32 29 69 04 07 17 19   c0, c1, c2)i....
         2854  +|   3792: 19 01 81 2d 74 61 62 6c 65 74 31 5f 69 64 78 74   ...-tablet1_idxt
         2855  +|   3808: 31 5f 69 64 78 04 43 52 45 41 54 45 20 54 41 42   1_idx.CREATE TAB
         2856  +|   3824: 4c 45 20 27 74 31 5f 69 64 78 27 28 73 65 67 69   LE 't1_idx'(segi
         2857  +|   3840: 64 2c 20 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50   d, term, pgno, P
         2858  +|   3856: 52 49 4d 41 52 59 20 4b 45 59 28 73 65 67 69 64   RIMARY KEY(segid
         2859  +|   3872: 2c 20 74 65 72 6d 29 29 20 57 49 54 48 4f 55 54   , term)) WITHOUT
         2860  +|   3888: 20 52 4f 57 49 44 55 03 07 17 1b 1b 01 81 01 74    ROWIDU........t
         2861  +|   3904: 61 62 6c 65 74 31 5f 64 61 74 61 74 31 5f 64 61   ablet1_datat1_da
         2862  +|   3920: 74 61 03 43 52 45 41 54 45 20 54 41 42 4c 45 20   ta.CREATE TABLE 
         2863  +|   3936: 27 74 31 5f 64 61 74 61 27 28 69 64 20 49 4e 54   't1_data'(id INT
         2864  +|   3952: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59   EGER PRIMARY KEY
         2865  +|   3968: 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 38 02 06   , block BLOB)8..
         2866  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         2867  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         2868  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35   LE t1 USING fts5
         2869  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00   (a,b,c)...9.....
         2870  +| page 3 offset 8192
         2871  +|      0: 0d 00 00 00 03 0c 94 00 0f e6 0f ef 0c 94 00 00   ................
         2872  +|   3216: 00 00 00 00 86 4a 84 80 80 80 80 01 04 00 8d 18   .....J..........
         2873  +|   3232: 00 00 03 2b 02 30 30 01 02 06 01 02 06 01 02 06   ...+.00.........
         2874  +|   3248: 1f 02 03 01 02 03 01 02 03 01 08 32 30 31 36 30   ...........20160
         2875  +|   3264: 36 30 39 01 02 07 01 02 07 01 02 07 01 01 34 01   609...........4.
         2876  +|   3280: 02 05 01 02 05 01 02 05 01 01 35 01 02 04 01 02   ..........5.....
         2877  +|   3296: 04 01 02 04 02 07 30 30 30 30 30 30 30 1c 02 04   ......0000000...
         2878  +|   3312: 01 02 04 01 02 04 01 06 62 69 6e 61 72 79 03 06   ........binary..
         2879  +|   3328: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         2880  +|   3344: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         2881  +|   3360: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02   ................
         2882  +|   3376: 03 06 01 02 02 03 06 01 02 02 01 08 63 6f 6d 70   ............comp
         2883  +|   3392: 69 6c 65 72 01 20 01 02 02 02 01 02 02 01 06 64   iler. .........d
         2884  +|   3408: 62 73 7c cc cc cc cc cc cc cc cc cc cc cc cc cc   bs|.............
         2885  +|   3424: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc   ................
         2886  +|   3440: cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc cc   ................
         2887  +|   3456: cc cc cc cc cc cc c4 61 74 07 02 03 01 02 03 01   .......at.......
         2888  +|   3472: 02 03 02 04 65 62 75 67 04 02 02 01 02 02 01 02   ....ebug........
         2889  +|   3488: 02 01 06 65 6e 61 62 6c 65 07 02 02 01 02 02 01   ...enable.......
         2890  +|   3504: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02   ................
         2891  +|   3520: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02   ................
         2892  +|   3536: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 05 23   ...............#
         2893  +|   3552: d6 76 36 32 d3 52 e3 42 e3 02 03 23 03 13 63 03   .v62.R.B...#..c.
         2894  +|   3568: 63 03 95 84 e4 f4 34 15 34 52 60 10 50 04 30 f1   c.....4.4R`.P.0.
         2895  +|   3584: 74 34 f4 d5 04 94 c4 55 23 d6 76 36 32 d3 52 e3   t4.....U#.v62.R.
         2896  +|   3600: 42 e3 02 03 23 03 13 63 03 63 03 95 85 25 45 24   B...#..c.c...%E$
         2897  +|   3616: 94 d0 d0 00 00 02 40 ee 00 00 ff 80 ff 00 fe 80   ......@.........
         2898  +|   3632: fe 00 fd 80 fd 00 fc 80 fc 00 fb 80 fb 00 fa 80   ................
         2899  +|   3648: fa 00 f9 80 f9 00 f8 80 f8 00 f7 80 f7 00 f6 80   ................
         2900  +|   3664: f6 00 f5 80 f5 00 f4 80 f4 00 f8 0f 30 0f 28 0f   ............0.(.
         2901  +|   3680: 20 0f 18 0f 10 0f 08 0f 00 0e f8 0e f0 0e e8 0e    ...............
         2902  +|   3696: e0 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         2903  +|   3712: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         2904  +|   3728: 02 01 04 6f 6d 69 74 1f 02 02 01 02 02 01 02 02   ...omit.........
         2905  +|   3744: 01 05 72 74 72 65 65 19 02 03 01 02 03 01 02 03   ..rtree.........
         2906  +|   3760: 04 02 69 6d 01 06 01 02 02 03 06 01 02 02 03 06   ..im............
         2907  +|   3776: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         2908  +|   3792: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         2909  +|   3808: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02   ................
         2910  +|   3824: 01 0a 74 68 72 65 61 64 73 61 66 65 22 02 02 01   ..threadsafe....
         2911  +|   3840: 02 02 01 02 02 01 04 76 74 61 62 07 02 04 01 02   .......vtab.....
         2912  +|   3856: 04 01 02 04 01 01 78 01 06 01 01 02 01 06 01 01   ......x.........
         2913  +|   3872: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02   ................
         2914  +|   3888: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01   ................
         2915  +|   3904: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06   ................
         2916  +|   3920: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01   ................
         2917  +|   3936: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01   ................
         2918  +|   3952: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02   ................
         2919  +|   3968: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01   ................
         2920  +|   3984: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06   ................
         2921  +|   4000: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01   ................
         2922  +|   4016: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01   ................
         2923  +|   4032: 02 01 06 01 01 02 01 06 01 01 02 04 15 13 0c 0c   ................
         2924  +|   4048: 12 44 13 11 0f 47 13 0f 0c 0e 11 10 0f 0e 10 0f   .D...G..........
         2925  +|   4064: 44 0f 10 40 15 0f 07 01 03 00 14 24 5a 24 24 0f   D..@.......$Z$$.
         2926  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         2927  +| page 4 offset 12288
         2928  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
         2929  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         2930  +| page 5 offset 16384
         2931  +|      0: 0d 00 00 00 24 0c 0a 00 0f d8 0f af 0f 86 0f 74   ....$..........t
         2932  +|     16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5   .a.N./..........
         2933  +|     32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5   ...t.[.@.$......
         2934  +|     48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb   .......h.O.5....
         2935  +|     64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a   .......x.W.>.$..
         2936  +|   3072: 00 00 00 00 00 00 00 00 00 00 18 24 05 00 25 0f   ...........$..%.
         2937  +|   3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49   .THREADSAFE=0XBI
         2938  +|   3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41   NARY.#..%..THREA
         2939  +|   3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22   DSAFE=0XNOCASE..
         2940  +|   3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d   ..%..THREADSAFE=
         2941  +|   3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d   0XRTRIM.!..3..OM
         2942  +|   3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f   IT LOAD EXTENSIO
         2943  +|   3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f   NXBINARY. ..3..O
         2944  +|   3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49   MIT LOAD EXTENSI
         2945  +|   3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17   ONXNOCASE....3..
         2946  +|   3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 5f e8 54 45 4e   OMIT LOAD E_.TEN
         2947  +|   3248: 53 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f   SIONXRTRIM....3.
         2948  +|   3264: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 31 81   .MAX MEMORY=501.
         2949  +|   3280: 40 50 02 50 f1 94 54 e4 14 24 c4 52 04 a5 35 f4   @P.P..T..$.R..5.
         2950  +|   3296: e3 15 84 e4 f4 34 15 34 51 71 30 50 02 50 f1 74   .....4.4Qq0P.P.t
         2951  +|   3312: 54 e4 14 24 c4 52 04 a5 34 f4 e3 15 85 25 45 24   T..$.R..4....%E$
         2952  +|   3328: 94 d1 a1 20 50 02 90 f1 94 54 e4 14 24 c4 52 04   ... P....T..$.R.
         2953  +|   3344: 74 54 f5 04 f4 c5 95 84 24 94 e4 15 25 91 a1 10   tT......$...%...
         2954  +|   3360: 50 02 90 f1 94 54 e4 14 24 c4 52 04 74 54 f5 04   P....T..$.R.tT..
         2955  +|   3376: f4 c5 95 84 e4 f4 34 15 34 51 91 00 50 02 90 f1   ......4.4Q..P...
         2956  +|   3392: 74 54 e4 14 24 c4 52 04 74 54 f5 04 f4 c5 95 85   tT..$.R.tT......
         2957  +|   3408: 25 45 24 94 d1 70 f0 50 02 30 f1 94 54 e4 14 24   %E$..p.P.0..T..$
         2958  +|   3424: c4 52 04 65 45 33 55 84 24 94 e4 15 25 91 70 e0   .R.eE3U.$...%.p.
         2959  +|   3440: 50 02 30 f1 94 54 e4 14 24 c4 52 04 65 45 33 55   P.0..T..$.R.eE3U
         2960  +|   3456: 84 e4 f4 34 15 34 51 60 d0 50 02 30 f1 74 54 e4   ...4.4Q`.P.0.tT.
         2961  +|   3472: 14 24 c4 52 04 65 45 33 55 85 25 45 24 94 d1 70   .$.R.eE3U.%E$..p
         2962  +|   3488: c0 50 02 30 f1 94 54 e4 14 24 c4 52 04 65 45 33   .P.0..T..$.R.eE3
         2963  +|   3504: 45 84 24 94 e4 15 25 91 70 b0 50 02 30 f1 94 54   E.$...%.p.P.0..T
         2964  +|   3520: e4 14 24 c4 52 04 65 45 33 45 84 e4 f4 34 15 34   ..$.R.eE3E...4.4
         2965  +|   3536: 51 60 a0 50 02 30 f1 74 54 e4 14 24 c4 52 04 65   Q`.P.0.tT..$.R.e
         2966  +|   3552: 45 33 45 85 25 45 24 94 d1 e0 90 50 03 10 f1 94   E3E.%E$....P....
         2967  +|   3568: 54 e4 42 4c 45 20 44 42 53 54 41 54 20 56 54 41   T.BLE DBSTAT VTA
         2968  +|   3584: 42 58 42 49 4e 41 52 59 1e 08 05 00 31 0f 19 45   BXBINARY....1..E
         2969  +|   3600: e4 14 24 c4 52 04 44 25 35 44 15 42 05 65 42 41   ..$.R.D%5D.B.eBA
         2970  +|   3616: 54 84 e4 f4 34 15 34 51 d0 70 50 03 10 f1 74 54   T...4.4Q.pP...tT
         2971  +|   3632: e4 14 24 c4 52 04 44 25 35 44 15 42 05 65 44 14   ..$.R.D%5D.B.eD.
         2972  +|   3648: 25 85 25 45 24 94 d1 10 60 50 01 70 f1 94 44 54   %.%E$...`P.p..DT
         2973  +|   3664: 25 54 75 84 24 94 e4 15 25 91 10 50 50 01 70 f1   %Tu.$...%..PP.p.
         2974  +|   3680: 94 44 54 25 54 75 84 e4 f4 34 15 34 51 00 40 50   .DT%Tu...4.4Q.@P
         2975  +|   3696: 01 70 f1 74 44 54 25 54 75 85 25 45 24 94 d2 70   .p.tDT%Tu.%E$..p
         2976  +|   3712: 30 50 04 30 f1 94 34 f4 d5 04 94 c4 55 23 d6 76   0P.0..4.....U#.v
         2977  +|   3728: 36 32 d3 52 e3 42 e3 02 03 23 03 13 63 03 63 03   62.R.B...#..c.c.
         2978  +|   3744: 95 84 24 94 e4 15 25 92 70 20 50 04 30 f1 94 34   ..$...%.p P.0..4
         2979  +|   3760: f4 d5 04 94 c4 53 30 01 00 00 10 10 04 02 02 00   .....S0.........
         2980  +|   3776: 00 00 00 00 00 00 00 80 00 00 00 20 00 00 00 10   ........... ....
         2981  +|   3792: 00 00 00 90 00 00 00 40 00 00 00 00 00 00 00 00   .......@........
         2982  +| page 6 offset 20480
         2983  +|   3808: 06 24 03 00 12 02 01 01 06 23 03 00 12 02 01 01   .$.......#......
         2984  +|   3824: 06 22 03 00 12 02 01 01 06 21 03 00 12 03 01 01   .........!......
         2985  +|   3840: 06 20 03 00 12 03 01 01 06 1f 03 00 12 03 01 01   . ..............
         2986  +|   3856: 06 1e 03 00 12 03 01 01 06 1d 03 00 12 03 01 01   ................
         2987  +|   3872: 06 1c 03 00 12 03 01 01 06 1b 03 00 12 02 01 01   ................
         2988  +|   3888: 06 1a 03 00 12 02 01 01 06 19 03 00 12 02 01 01   ................
         2989  +|   3904: 06 18 03 00 12 02 01 01 06 17 03 00 12 02 01 01   ................
         2990  +|   3920: 06 16 03 00 12 02 01 01 06 15 03 00 12 02 01 01   ................
         2991  +|   3936: 06 14 03 00 12 02 01 01 06 13 03 00 12 02 01 01   ................
         2992  +|   3952: 06 12 03 00 12 02 01 01 06 11 03 00 12 02 01 01   ................
         2993  +|   3968: 06 10 03 00 12 02 01 01 06 0f 03 00 12 02 01 01   ................
         2994  +|   3984: 06 0e 03 00 12 02 01 01 06 0d 03 00 12 02 01 01   ................
         2995  +|   4000: 06 0c 03 00 12 02 01 01 06 0b 03 00 12 02 01 01   ................
         2996  +|   4016: 06 0a 03 00 12 02 01 01 06 09 03 00 12 03 01 01   ................
         2997  +|   4032: 06 08 03 00 12 03 01 01 06 07 03 00 12 03 01 01   ................
         2998  +|   4048: 06 06 03 00 12 01 01 01 06 05 03 00 12 01 01 01   ................
         2999  +|   4064: 06 04 03 00 12 01 01 01 06 03 03 00 12 06 01 01   ................
         3000  +|   4080: 06 02 03 00 12 06 01 01 06 01 03 00 12 06 01 01   ................
         3001  +| page 7 offset 24576
         3002  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         3003  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         3004  +| page 8 offset 28672
         3005  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e9 0f d6 00 00   ................
         3006  +|   4048: 00 00 00 00 00 00 11 03 02 2b 69 6e 74 65 67 72   .........+integr
         3007  +|   4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity-check....reb
         3008  +|   4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   uild....optimize
         3009  +| end timeout-2ca5b0658c98.db
         3010  +}]} {}
         3011  +
         3012  +do_catchsql_test 27.1 {
         3013  +  DELETE FROM t1 WHERE a MATCH 'fts*';
         3014  +} {1 {database disk image is malformed}}
         3015  +
         3016  +#-------------------------------------------------------------------------
         3017  +reset_db
         3018  +do_test 28.0 {
         3019  +  sqlite3 db {}
         3020  +  db deserialize [decode_hexdb {
         3021  +| size 40960 pagesize 4096 filename crash-e2d47e0624a42c.db
         3022  +| page 1 offset 0
         3023  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         3024  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 0a   .....@  ........
         3025  +|     32: 00 00 00 00 00 00 00 00 00 00 00 0d 00 00 00 04   ................
         3026  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         3027  +|     96: 00 00 00 00 0d 00 00 00 0d 0b 6e 00 0f a3 0f 4c   ..........n....L
         3028  +|    112: 0e e1 0e 81 0e 24 0d cc 0d 72 0d 1b 0c b0 0c 50   .....$...r.....P
         3029  +|    128: 0b f8 0b b3 0b 6e 00 00 00 00 00 00 00 00 00 00   .....n..........
         3030  +|   2912: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 43 0d   ..............C.
         3031  +|   2928: 06 17 11 11 08 75 74 61 62 6c 65 74 34 74 34 43   .....utablet4t4C
         3032  +|   2944: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41   REATE VIRTUAL TA
         3033  +|   2960: 42 4c 45 20 74 34 20 55 53 49 4e 47 20 66 74 73   BLE t4 USING fts
         3034  +|   2976: 35 76 6f 63 61 62 28 27 74 32 27 2c 20 27 72 6f   5vocab('t2', 'ro
         3035  +|   2992: 77 27 29 43 0c 06 17 11 11 08 75 74 61 62 6c 65   w')C......utable
         3036  +|   3008: 74 33 74 33 43 52 45 41 54 45 20 56 49 52 54 55   t3t3CREATE VIRTU
         3037  +|   3024: 41 4c 20 54 41 42 4c 45 20 74 33 20 55 53 49 4e   AL TABLE t3 USIN
         3038  +|   3040: 47 20 66 74 73 35 76 6f 63 61 62 28 27 74 31 27   G fts5vocab('t1'
         3039  +|   3056: 2c 20 27 72 6f 77 27 29 56 0b 06 17 1f 1f 01 7d   , 'row')V.......
         3040  +|   3072: 74 61 62 6c 65 74 32 5f 63 6f 6e 66 69 67 74 32   tablet2_configt2
         3041  +|   3088: 5f 63 6f 6e 66 69 67 0a 43 52 45 41 54 45 20 54   _config.CREATE T
         3042  +|   3104: 41 42 4c 45 20 27 74 32 5f 63 6f 6e 66 69 67 27   ABLE 't2_config'
         3043  +|   3120: 28 6b 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   (k PRIMARY KEY, 
         3044  +|   3136: 76 29 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44   v) WITHOUT ROWID
         3045  +|   3152: 5e 0a 07 17 21 21 01 81 07 74 61 62 6c 65 74 32   ^...!!...tablet2
         3046  +|   3168: 5f 63 6f 6e 74 65 6e 74 74 32 5f 63 6f 6e 74 65   _contentt2_conte
         3047  +|   3184: 6e 74 09 43 52 45 41 54 45 20 54 41 42 4c 45 20   nt.CREATE TABLE 
         3048  +|   3200: 27 74 32 5f 63 6f 6e 74 65 6e 74 27 28 69 64 20   't2_content'(id 
         3049  +|   3216: 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20   INTEGER PRIMARY 
         3050  +|   3232: 4b 45 59 2c 20 63 30 2c 20 63 31 2c 20 63 32 29   KEY, c0, c1, c2)
         3051  +|   3248: 69 09 07 17 19 19 01 81 2d 74 61 62 6c 65 74 32   i.......-tablet2
         3052  +|   3264: 5f 69 64 78 74 32 5f 69 64 78 08 43 52 45 41 54   _idxt2_idx.CREAT
         3053  +|   3280: 45 20 54 41 42 4c 45 20 27 74 32 5f 69 64 78 27   E TABLE 't2_idx'
         3054  +|   3296: 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20 70 67   (segid, term, pg
         3055  +|   3312: 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45 59 28   no, PRIMARY KEY(
         3056  +|   3328: 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20 57 49   segid, term)) WI
         3057  +|   3344: 54 48 4f 55 54 20 52 4f 57 49 44