/ Check-in [31efcc37]
Login

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

Overview
Comment:Merge enhancements from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | apple-osx
Files: files | file ages | folders
SHA3-256: 31efcc3775608efd7509e7178abf65b180cfb44d9166b39d13d066c75ed6eb5a
User & Date: drh 2019-01-29 19:17:47
Context
2019-02-07
18:49
Merge the offical 3.27.0 release. check-in: 62829164 user: drh tags: apple-osx
2019-01-29
19:17
Merge enhancements from trunk. check-in: 31efcc37 user: drh tags: apple-osx
16:54
Fix harmless compiler warnings. check-in: 9a93c68a user: drh tags: trunk
2019-01-17
15:47
Sync up with the latest enhancements on trunk. check-in: 475a179a user: drh tags: apple-osx
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to Makefile.in.

   599    599   FUZZDATA = \
   600    600     $(TOP)/test/fuzzdata1.db \
   601    601     $(TOP)/test/fuzzdata2.db \
   602    602     $(TOP)/test/fuzzdata3.db \
   603    603     $(TOP)/test/fuzzdata4.db \
   604    604     $(TOP)/test/fuzzdata5.db \
   605    605     $(TOP)/test/fuzzdata6.db \
   606         -  $(TOP)/test/fuzzdata7.db
          606  +  $(TOP)/test/fuzzdata7.db \
          607  +  $(TOP)/test/fuzzdata8.db
   607    608   
   608    609   # Standard options to testfixture
   609    610   #
   610    611   TESTOPTS = --verbose=file --output=test-out.txt
   611    612   
   612    613   # Extra compiler options for various shell tools
   613    614   #
................................................................................
   622    623   SHELL_OPT += -DSQLITE_ENABLE_OFFSET_SQL_FUNC
   623    624   SHELL_OPT += -DSQLITE_ENABLE_DESERIALIZE
   624    625   SHELL_OPT += -DSQLITE_INTROSPECTION_PRAGMAS
   625    626   FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1
   626    627   FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5 -DSQLITE_OSS_FUZZ
   627    628   FUZZCHECK_OPT += -DSQLITE_MAX_MEMORY=50000000
   628    629   FUZZCHECK_OPT += -DSQLITE_PRINTF_PRECISION_LIMIT=1000
          630  +FUZZCHECK_OPT += -DSQLITE_ENABLE_DESERIALIZE
          631  +FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS4
          632  +#FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS5
          633  +FUZZCHECK_OPT += -DSQLITE_ENABLE_RTREE
          634  +FUZZCHECK_OPT += -DSQLITE_ENABLE_GEOPOLY
          635  +FUZZCHECK_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
   629    636   FUZZCHECK_SRC = $(TOP)/test/fuzzcheck.c $(TOP)/test/ossfuzz.c
   630    637   DBFUZZ_OPT =
   631    638   
   632    639   # This is the default Makefile target.  The objects listed here
   633    640   # are what get build when you type just "make" with no arguments.
   634    641   #
   635    642   all:	sqlite3.h libsqlite3.la sqlite3$(TEXE) $(HAVE_TCL:1=libtclsqlite3.la)
................................................................................
  1077   1084   	$(TOP)/ext/misc/shathree.c \
  1078   1085   	$(TOP)/ext/misc/fileio.c \
  1079   1086   	$(TOP)/ext/misc/completion.c \
  1080   1087   	$(TOP)/ext/misc/sqlar.c \
  1081   1088   	$(TOP)/ext/expert/sqlite3expert.c \
  1082   1089   	$(TOP)/ext/expert/sqlite3expert.h \
  1083   1090   	$(TOP)/ext/misc/zipfile.c \
         1091  +	$(TOP)/ext/misc/memtrace.c \
  1084   1092           $(TOP)/src/test_windirent.c
  1085   1093   
  1086   1094   shell.c:	$(SHELL_SRC) $(TOP)/tool/mkshellc.tcl
  1087   1095   	$(TCLSH_CMD) $(TOP)/tool/mkshellc.tcl >shell.c
  1088   1096   
  1089   1097   
  1090   1098   

Changes to Makefile.msc.

  1622   1622   FUZZDATA = \
  1623   1623     $(TOP)\test\fuzzdata1.db \
  1624   1624     $(TOP)\test\fuzzdata2.db \
  1625   1625     $(TOP)\test\fuzzdata3.db \
  1626   1626     $(TOP)\test\fuzzdata4.db \
  1627   1627     $(TOP)\test\fuzzdata5.db \
  1628   1628     $(TOP)\test\fuzzdata6.db \
  1629         -  $(TOP)\test\fuzzdata7.db
         1629  +  $(TOP)\test\fuzzdata7.db \
         1630  +  $(TOP)\test\fuzzdata8.db
  1630   1631   # <</mark>>
  1631   1632   
  1632   1633   # Additional compiler options for the shell.  These are only effective
  1633   1634   # when the shell is not being dynamically linked.
  1634   1635   #
  1635   1636   !IF $(DYNAMIC_SHELL)==0 && $(FOR_WIN10)==0
  1636   1637   SHELL_COMPILE_OPTS = $(SHELL_COMPILE_OPTS) -DSQLITE_ENABLE_FTS4=1
................................................................................
  1640   1641   !ENDIF
  1641   1642   
  1642   1643   # <<mark>>
  1643   1644   # Extra compiler options for various test tools.
  1644   1645   #
  1645   1646   MPTESTER_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_FTS5
  1646   1647   FUZZERSHELL_COMPILE_OPTS = -DSQLITE_ENABLE_JSON1
  1647         -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  +
  1648   1655   FUZZCHECK_SRC = $(TOP)\test\fuzzcheck.c $(TOP)\test\ossfuzz.c
  1649   1656   OSSSHELL_SRC = $(TOP)\test\ossshell.c $(TOP)\test\ossfuzz.c
  1650   1657   DBFUZZ_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_OMIT_LOAD_EXTENSION
  1651   1658   KV_COMPILE_OPTS = -DSQLITE_THREADSAFE=0 -DSQLITE_DIRECT_OVERFLOW_READ
  1652   1659   ST_COMPILE_OPTS = -DSQLITE_THREADSAFE=0
  1653   1660   
  1654   1661   # Standard options to testfixture.
................................................................................
  1727   1734   fuzzershell.exe:	$(TOP)\tool\fuzzershell.c $(SQLITE3C) $(SQLITE3H)
  1728   1735   	$(LTLINK) $(NO_WARN) $(FUZZERSHELL_COMPILE_OPTS) $(TOP)\tool\fuzzershell.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1729   1736   
  1730   1737   dbfuzz.exe:	$(TOP)\test\dbfuzz.c $(SQLITE3C) $(SQLITE3H)
  1731   1738   	$(LTLINK) $(NO_WARN) $(DBFUZZ_COMPILE_OPTS) $(TOP)\test\dbfuzz.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1732   1739   
  1733   1740   fuzzcheck.exe:	$(FUZZCHECK_SRC) $(SQLITE3C) $(SQLITE3H)
  1734         -	$(LTLINK) $(NO_WARN) $(FUZZCHECK_COMPILE_OPTS) $(FUZZCHECK_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
         1741  +	$(LTLINK) $(NO_WARN) $(FUZZCHECK_OPTS) $(FUZZCHECK_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1735   1742   
  1736   1743   ossshell.exe:	$(OSSSHELL_SRC) $(SQLITE3C) $(SQLITE3H)
  1737         -	$(LTLINK) $(NO_WARN) $(FUZZCHECK_COMPILE_OPTS) $(OSSSHELL_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
         1744  +	$(LTLINK) $(NO_WARN) $(FUZZCHECK_OPTS) $(OSSSHELL_SRC) $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1738   1745   
  1739   1746   sessionfuzz.exe:	zlib $(TOP)\test\sessionfuzz.c $(SQLITE3C) $(SQLITE3H)
  1740   1747   	$(LTLINK) $(NO_WARN) -I$(ZLIBINCDIR) $(TOP)\test\sessionfuzz.c /link $(LDFLAGS) $(LTLINKOPTS) /LIBPATH:$(ZLIBLIBDIR) $(ZLIBLIB)
  1741   1748   
  1742   1749   mptester.exe:	$(TOP)\mptest\mptest.c $(SQLITE3C) $(SQLITE3H)
  1743   1750   	$(LTLINK) $(NO_WARN) $(MPTESTER_COMPILE_OPTS) $(TOP)\mptest\mptest.c $(SQLITE3C) /link $(LDFLAGS) $(LTLINKOPTS)
  1744   1751   
................................................................................
  2127   2134   	$(TOP)\src\shell.c.in \
  2128   2135   	$(TOP)\ext\misc\appendvfs.c \
  2129   2136   	$(TOP)\ext\misc\shathree.c \
  2130   2137   	$(TOP)\ext\misc\fileio.c \
  2131   2138   	$(TOP)\ext\misc\completion.c \
  2132   2139   	$(TOP)\ext\expert\sqlite3expert.c \
  2133   2140   	$(TOP)\ext\expert\sqlite3expert.h \
         2141  +	$(TOP)\ext\misc\memtrace.c \
  2134   2142   	$(TOP)\src\test_windirent.c
  2135   2143   
  2136   2144   # If use of zlib is enabled, add the "zipfile.c" source file.
  2137   2145   #
  2138   2146   !IF $(USE_ZLIB)!=0
  2139   2147   SHELL_SRC = $(SHELL_SRC) $(TOP)\ext\misc\sqlar.c
  2140   2148   SHELL_SRC = $(SHELL_SRC) $(TOP)\ext\misc\zipfile.c

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;
................................................................................
   557    565   static int fts3DestroyMethod(sqlite3_vtab *pVtab){
   558    566     Fts3Table *p = (Fts3Table *)pVtab;
   559    567     int rc = SQLITE_OK;              /* Return code */
   560    568     const char *zDb = p->zDb;        /* Name of database (e.g. "main", "temp") */
   561    569     sqlite3 *db = p->db;             /* Database handle */
   562    570   
   563    571     /* Drop the shadow tables */
   564         -  if( p->zContentTbl==0 ){
   565         -    fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_content'", zDb, p->zName);
   566         -  }
   567         -  fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segments'", zDb,p->zName);
   568         -  fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_segdir'", zDb, p->zName);
   569         -  fts3DbExec(&rc, db, "DROP TABLE IF EXISTS %Q.'%q_docsize'", zDb, p->zName);
   570         -  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  +  );
   571    584   
   572    585     /* If everything has worked, invoke fts3DisconnectMethod() to free the
   573    586     ** memory associated with the Fts3Table structure and return SQLITE_OK.
   574    587     ** Otherwise, return an SQLite error code.
   575    588     */
   576    589     return (rc==SQLITE_OK ? fts3DisconnectMethod(pVtab) : rc);
   577    590   }
................................................................................
  2131   2144   /*
  2132   2145   ** Compute the union of two position lists.  The output written
  2133   2146   ** into *pp contains all positions of both *pp1 and *pp2 in sorted
  2134   2147   ** order and with any duplicates removed.  All pointers are
  2135   2148   ** updated appropriately.   The caller is responsible for insuring
  2136   2149   ** that there is enough space in *pp to hold the complete output.
  2137   2150   */
  2138         -static void fts3PoslistMerge(
         2151  +static int fts3PoslistMerge(
  2139   2152     char **pp,                      /* Output buffer */
  2140   2153     char **pp1,                     /* Left input list */
  2141   2154     char **pp2                      /* Right input list */
  2142   2155   ){
  2143   2156     char *p = *pp;
  2144   2157     char *p1 = *pp1;
  2145   2158     char *p2 = *pp2;
  2146   2159   
  2147   2160     while( *p1 || *p2 ){
  2148   2161       int iCol1;         /* The current column index in pp1 */
  2149   2162       int iCol2;         /* The current column index in pp2 */
  2150   2163   
  2151         -    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  +    }
  2152   2168       else if( *p1==POS_END ) iCol1 = POSITION_LIST_END;
  2153   2169       else iCol1 = 0;
  2154   2170   
  2155         -    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  +    }
  2156   2175       else if( *p2==POS_END ) iCol2 = POSITION_LIST_END;
  2157   2176       else iCol2 = 0;
  2158   2177   
  2159   2178       if( iCol1==iCol2 ){
  2160   2179         sqlite3_int64 i1 = 0;       /* Last position from pp1 */
  2161   2180         sqlite3_int64 i2 = 0;       /* Last position from pp2 */
  2162   2181         sqlite3_int64 iPrev = 0;
................................................................................
  2196   2215       }
  2197   2216     }
  2198   2217   
  2199   2218     *p++ = POS_END;
  2200   2219     *pp = p;
  2201   2220     *pp1 = p1 + 1;
  2202   2221     *pp2 = p2 + 1;
         2222  +  return SQLITE_OK;
  2203   2223   }
  2204   2224   
  2205   2225   /*
  2206   2226   ** This function is used to merge two position lists into one. When it is
  2207   2227   ** called, *pp1 and *pp2 must both point to position lists. A position-list is
  2208   2228   ** the part of a doclist that follows each document id. For example, if a row
  2209   2229   ** contains:
................................................................................
  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_malloc64((sqlite3_int64)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.
................................................................................
  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;
................................................................................
  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   }
  3848   3876   
  3849   3877   /*
  3850   3878   ** Return true if zName is the extension on one of the shadow tables used
................................................................................
  5602   5630   static void fts3EvalUpdateCounts(Fts3Expr *pExpr, int nCol){
  5603   5631     if( pExpr ){
  5604   5632       Fts3Phrase *pPhrase = pExpr->pPhrase;
  5605   5633       if( pPhrase && pPhrase->doclist.pList ){
  5606   5634         int iCol = 0;
  5607   5635         char *p = pPhrase->doclist.pList;
  5608   5636   
  5609         -      assert( *p );
  5610   5637         do{
  5611   5638           u8 c = 0;
  5612   5639           int iCnt = 0;
  5613   5640           while( 0xFE & (*p | c) ){
  5614   5641             if( (c&0x80)==0 ) iCnt++;
  5615   5642             c = *p++ & 0x80;
  5616   5643           }

Changes to ext/fts3/fts3Int.h.

   125    125   
   126    126   /*
   127    127   ** Terminator values for position-lists and column-lists.
   128    128   */
   129    129   #define POS_COLUMN  (1)     /* Column-list terminator */
   130    130   #define POS_END     (0)     /* Position-list terminator */ 
   131    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  +
   132    144   /*
   133    145   ** This section provides definitions to allow the
   134    146   ** FTS3 extension to be compiled outside of the 
   135    147   ** amalgamation.
   136    148   */
   137    149   #ifndef SQLITE_AMALGAMATION
   138    150   /*

Changes to ext/fts3/fts3_aux.c.

   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

Changes to ext/fts3/fts3_snippet.c.

   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   
................................................................................
   656    657     if( hlmask ){
   657    658       int nLeft;                    /* Tokens to the left of first highlight */
   658    659       int nRight;                   /* Tokens to the right of last highlight */
   659    660       int nDesired;                 /* Ideal number of tokens to shift forward */
   660    661   
   661    662       for(nLeft=0; !(hlmask & ((u64)1 << nLeft)); nLeft++);
   662    663       for(nRight=0; !(hlmask & ((u64)1 << (nSnippet-1-nRight))); nRight++);
          664  +    assert( (nSnippet-1-nRight)<=63 && (nSnippet-1-nRight)>=0 );
   663    665       nDesired = (nLeft-nRight)/2;
   664    666   
   665    667       /* Ideally, the start of the snippet should be pushed forward in the
   666    668       ** document nDesired tokens. This block checks if there are actually
   667    669       ** nDesired tokens to the right of the snippet. If so, *piPos and
   668    670       ** *pHlMask are updated to shift the snippet nDesired tokens to the
   669    671       ** right. Otherwise, the snippet is shifted by the number of tokens
................................................................................
  1428   1430     SnippetFragment aSnippet[4];    /* Maximum of 4 fragments per snippet */
  1429   1431     int nFToken = -1;               /* Number of tokens in each fragment */
  1430   1432   
  1431   1433     if( !pCsr->pExpr ){
  1432   1434       sqlite3_result_text(pCtx, "", 0, SQLITE_STATIC);
  1433   1435       return;
  1434   1436     }
         1437  +
         1438  +  /* Limit the snippet length to 64 tokens. */
         1439  +  if( nToken<-64 ) nToken = -64;
         1440  +  if( nToken>+64 ) nToken = +64;
  1435   1441   
  1436   1442     for(nSnippet=1; 1; nSnippet++){
  1437   1443   
  1438   1444       int iSnip;                    /* Loop counter 0..nSnippet-1 */
  1439   1445       u64 mCovered = 0;             /* Bitmask of phrases covered by snippet */
  1440   1446       u64 mSeen = 0;                /* Bitmask of phrases seen by BestSnippet() */
  1441   1447   

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_write.c.

   563    563   static sqlite3_int64 getAbsoluteLevel(
   564    564     Fts3Table *p,                   /* FTS3 table handle */
   565    565     int iLangid,                    /* Language id */
   566    566     int iIndex,                     /* Index in p->aIndex[] */
   567    567     int iLevel                      /* Level of segments */
   568    568   ){
   569    569     sqlite3_int64 iBase;            /* First absolute level for iLangid/iIndex */
   570         -  assert( iLangid>=0 );
          570  +  assert_fts3_nc( iLangid>=0 );
   571    571     assert( p->nIndex>0 );
   572    572     assert( iIndex>=0 && iIndex<p->nIndex );
   573    573   
   574    574     iBase = ((sqlite3_int64)iLangid * p->nIndex + iIndex) * FTS3_SEGDIR_MAXLEVEL;
   575    575     return iBase + iLevel;
   576    576   }
   577    577   
................................................................................
  2250   2250       rc = sqlite3_reset(pStmt);
  2251   2251       if( rc!=SQLITE_OK ) return rc;
  2252   2252     }
  2253   2253     nData = pWriter->nData;
  2254   2254   
  2255   2255     nPrefix = fts3PrefixCompress(pWriter->zTerm, pWriter->nTerm, zTerm, nTerm);
  2256   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;
  2257   2262   
  2258   2263     /* Figure out how many bytes are required by this new entry */
  2259   2264     nReq = sqlite3Fts3VarintLen(nPrefix) +    /* varint containing prefix size */
  2260   2265       sqlite3Fts3VarintLen(nSuffix) +         /* varint containing suffix size */
  2261   2266       nSuffix +                               /* Term suffix */
  2262   2267       sqlite3Fts3VarintLen(nDoclist) +        /* Size of doclist */
  2263   2268       nDoclist;                               /* Doclist data */

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   **

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[] */
................................................................................
   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. 

Changes to ext/fts5/fts5_aux.c.

   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;
................................................................................
   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);

Changes to ext/fts5/fts5_buffer.c.

    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   /*

Changes to ext/fts5/fts5_index.c.

   602    602   ** Return -ve if pLeft is smaller than pRight, 0 if they are equal or
   603    603   ** +ve if pRight is smaller than pLeft. In other words:
   604    604   **
   605    605   **     res = *pLeft - *pRight
   606    606   */
   607    607   static int fts5BufferCompare(Fts5Buffer *pLeft, Fts5Buffer *pRight){
   608    608     int nCmp = MIN(pLeft->n, pRight->n);
   609         -  int res = memcmp(pLeft->p, pRight->p, nCmp);
          609  +  int res = fts5Memcmp(pLeft->p, pRight->p, nCmp);
   610    610     return (res==0 ? (pLeft->n - pRight->n) : res);
   611    611   }
   612    612   
   613    613   static int fts5LeafFirstTermOff(Fts5Data *pLeaf){
   614    614     int ret;
   615    615     fts5GetVarint32(&pLeaf->p[pLeaf->szLeaf], ret);
   616    616     return ret;
................................................................................
  1648   1648   */
  1649   1649   static void fts5SegIterLoadTerm(Fts5Index *p, Fts5SegIter *pIter, int nKeep){
  1650   1650     u8 *a = pIter->pLeaf->p;        /* Buffer to read data from */
  1651   1651     int iOff = pIter->iLeafOffset;  /* Offset to read at */
  1652   1652     int nNew;                       /* Bytes of new data */
  1653   1653   
  1654   1654     iOff += fts5GetVarint32(&a[iOff], nNew);
  1655         -  if( iOff+nNew>pIter->pLeaf->nn || nKeep>pIter->term.n ){
         1655  +  if( iOff+nNew>pIter->pLeaf->szLeaf || nKeep>pIter->term.n ){
  1656   1656       p->rc = FTS5_CORRUPT;
  1657   1657       return;
  1658   1658     }
  1659   1659     pIter->term.n = nKeep;
  1660   1660     fts5BufferAppendBlob(&p->rc, &pIter->term, nNew, &a[iOff]);
  1661   1661     assert( pIter->term.n<=pIter->term.nSpace );
  1662   1662     iOff += nNew;
................................................................................
  2530   2530     if( p1->pLeaf || p2->pLeaf ){
  2531   2531       if( p1->pLeaf==0 ){
  2532   2532         assert( pRes->iFirst==i2 );
  2533   2533       }else if( p2->pLeaf==0 ){
  2534   2534         assert( pRes->iFirst==i1 );
  2535   2535       }else{
  2536   2536         int nMin = MIN(p1->term.n, p2->term.n);
  2537         -      int res = memcmp(p1->term.p, p2->term.p, nMin);
         2537  +      int res = fts5Memcmp(p1->term.p, p2->term.p, nMin);
  2538   2538         if( res==0 ) res = p1->term.n - p2->term.n;
  2539   2539   
  2540   2540         if( res==0 ){
  2541   2541           assert( pRes->bTermEq==1 );
  2542   2542           assert( p1->iRowid!=p2->iRowid );
  2543   2543           res = ((p1->iRowid > p2->iRowid)==pIter->bRev) ? -1 : 1;
  2544   2544         }else{
................................................................................
  3576   3576         int iLvl, iSeg;
  3577   3577         int i;
  3578   3578         u32 mask;
  3579   3579         memset(aUsed, 0, sizeof(aUsed));
  3580   3580         for(iLvl=0; iLvl<pStruct->nLevel; iLvl++){
  3581   3581           for(iSeg=0; iSeg<pStruct->aLevel[iLvl].nSeg; iSeg++){
  3582   3582             int iId = pStruct->aLevel[iLvl].aSeg[iSeg].iSegid;
  3583         -          if( iId<=FTS5_MAX_SEGMENT ){
         3583  +          if( iId<=FTS5_MAX_SEGMENT && iId>0 ){
  3584   3584               aUsed[(iId-1) / 32] |= (u32)1 << ((iId-1) % 32);
  3585   3585             }
  3586   3586           }
  3587   3587         }
  3588   3588   
  3589   3589         for(i=0; aUsed[i]==0xFFFFFFFF; i++);
  3590   3590         mask = aUsed[i];
................................................................................
  4123   4123   ** incremental merge operation. This function is called if the incremental
  4124   4124   ** merge step has finished but the input has not been completely exhausted.
  4125   4125   */
  4126   4126   static void fts5TrimSegments(Fts5Index *p, Fts5Iter *pIter){
  4127   4127     int i;
  4128   4128     Fts5Buffer buf;
  4129   4129     memset(&buf, 0, sizeof(Fts5Buffer));
  4130         -  for(i=0; i<pIter->nSeg; i++){
         4130  +  for(i=0; i<pIter->nSeg && p->rc==SQLITE_OK; i++){
  4131   4131       Fts5SegIter *pSeg = &pIter->aSeg[i];
  4132   4132       if( pSeg->pSeg==0 ){
  4133   4133         /* no-op */
  4134   4134       }else if( pSeg->pLeaf==0 ){
  4135   4135         /* All keys from this input segment have been transfered to the output.
  4136   4136         ** Set both the first and last page-numbers to 0 to indicate that the
  4137   4137         ** segment is now empty. */
................................................................................
  4141   4141         int iOff = pSeg->iTermLeafOffset;     /* Offset on new first leaf page */
  4142   4142         i64 iLeafRowid;
  4143   4143         Fts5Data *pData;
  4144   4144         int iId = pSeg->pSeg->iSegid;
  4145   4145         u8 aHdr[4] = {0x00, 0x00, 0x00, 0x00};
  4146   4146   
  4147   4147         iLeafRowid = FTS5_SEGMENT_ROWID(iId, pSeg->iTermLeafPgno);
  4148         -      pData = fts5DataRead(p, iLeafRowid);
         4148  +      pData = fts5LeafRead(p, iLeafRowid);
  4149   4149         if( pData ){
         4150  +        if( iOff>pData->szLeaf ){
         4151  +          /* This can occur if the pages that the segments occupy overlap - if
         4152  +          ** a single page has been assigned to more than one segment. In
         4153  +          ** this case a prior iteration of this loop may have corrupted the
         4154  +          ** segment currently being trimmed.  */
         4155  +          p->rc = FTS5_CORRUPT;
         4156  +        }else{
  4150   4157           fts5BufferZero(&buf);
  4151   4158           fts5BufferGrow(&p->rc, &buf, pData->nn);
  4152   4159           fts5BufferAppendBlob(&p->rc, &buf, sizeof(aHdr), aHdr);
  4153   4160           fts5BufferAppendVarint(&p->rc, &buf, pSeg->term.n);
  4154   4161           fts5BufferAppendBlob(&p->rc, &buf, pSeg->term.n, pSeg->term.p);
  4155   4162           fts5BufferAppendBlob(&p->rc, &buf, pData->szLeaf-iOff, &pData->p[iOff]);
  4156   4163           if( p->rc==SQLITE_OK ){
................................................................................
  4166   4173             int nDiff = pData->szLeaf - pSeg->iEndofDoclist;
  4167   4174             fts5BufferAppendVarint(&p->rc, &buf, buf.n - 1 - nDiff - 4);
  4168   4175             fts5BufferAppendBlob(&p->rc, &buf, 
  4169   4176                 pData->nn - pSeg->iPgidxOff, &pData->p[pSeg->iPgidxOff]
  4170   4177             );
  4171   4178           }
  4172   4179   
  4173         -        fts5DataRelease(pData);
  4174   4180           pSeg->pSeg->pgnoFirst = pSeg->iTermLeafPgno;
  4175   4181           fts5DataDelete(p, FTS5_SEGMENT_ROWID(iId, 1), iLeafRowid);
  4176   4182           fts5DataWrite(p, iLeafRowid, buf.p, buf.n);
  4177   4183         }
         4184  +        fts5DataRelease(pData);
         4185  +      }
  4178   4186       }
  4179   4187     }
  4180   4188     fts5BufferFree(&buf);
  4181   4189   }
  4182   4190   
  4183   4191   static void fts5MergeChunkCallback(
  4184   4192     Fts5Index *p, 
................................................................................
  4261   4269     ){
  4262   4270       Fts5SegIter *pSegIter = &pIter->aSeg[ pIter->aFirst[1].iFirst ];
  4263   4271       int nPos;                     /* position-list size field value */
  4264   4272       int nTerm;
  4265   4273       const u8 *pTerm;
  4266   4274   
  4267   4275       pTerm = fts5MultiIterTerm(pIter, &nTerm);
  4268         -    if( nTerm!=term.n || memcmp(pTerm, term.p, nTerm) ){
         4276  +    if( nTerm!=term.n || fts5Memcmp(pTerm, term.p, nTerm) ){
  4269   4277         if( pnRem && writer.nLeafWritten>nRem ){
  4270   4278           break;
  4271   4279         }
  4272   4280         fts5BufferSet(&p->rc, &term, nTerm, pTerm);
  4273   4281         bTermWritten =0;
  4274   4282       }
  4275   4283   
................................................................................
  4955   4963           /* Merge the two position lists. */ 
  4956   4964           i64 iPos1 = 0;
  4957   4965           i64 iPos2 = 0;
  4958   4966           int iOff1 = 0;
  4959   4967           int iOff2 = 0;
  4960   4968           u8 *a1 = &i1.aPoslist[i1.nSize];
  4961   4969           u8 *a2 = &i2.aPoslist[i2.nSize];
         4970  +        int nCopy;
         4971  +        u8 *aCopy;
  4962   4972   
  4963   4973           i64 iPrev = 0;
  4964   4974           Fts5PoslistWriter writer;
  4965   4975           memset(&writer, 0, sizeof(writer));
  4966   4976   
  4967   4977           fts5MergeAppendDocid(&out, iLastRowid, i2.iRowid);
  4968   4978           fts5BufferZero(&tmp);
................................................................................
  4998   5008             }
  4999   5009           }
  5000   5010   
  5001   5011           if( iPos1>=0 ){
  5002   5012             if( iPos1!=iPrev ){
  5003   5013               sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos1);
  5004   5014             }
  5005         -          fts5BufferSafeAppendBlob(&tmp, &a1[iOff1], i1.nPoslist-iOff1);
         5015  +          aCopy = &a1[iOff1];
         5016  +          nCopy = i1.nPoslist - iOff1;
  5006   5017           }else{
  5007   5018             assert( iPos2>=0 && iPos2!=iPrev );
  5008   5019             sqlite3Fts5PoslistSafeAppend(&tmp, &iPrev, iPos2);
  5009         -          fts5BufferSafeAppendBlob(&tmp, &a2[iOff2], i2.nPoslist-iOff2);
         5020  +          aCopy = &a2[iOff2];
         5021  +          nCopy = i2.nPoslist - iOff2;
         5022  +        }
         5023  +        if( nCopy>0 ){
         5024  +          fts5BufferSafeAppendBlob(&tmp, aCopy, nCopy);
  5010   5025           }
  5011   5026   
  5012   5027           /* WRITEPOSLISTSIZE */
  5013   5028           fts5BufferSafeAppendVarint(&out, tmp.n * 2);
  5014   5029           fts5BufferSafeAppendBlob(&out, tmp.p, tmp.n);
  5015   5030           fts5DoclistIterNext(&i1);
  5016   5031           fts5DoclistIterNext(&i2);
         5032  +        assert( out.n<=(p1->n+p2->n+9) );
  5017   5033           if( i1.aPoslist==0 || i2.aPoslist==0 ) break;
  5018   5034         }
  5019   5035       }
  5020   5036   
  5021   5037       if( i1.aPoslist ){
  5022   5038         fts5MergeAppendDocid(&out, iLastRowid, i1.iRowid);
  5023   5039         fts5BufferSafeAppendBlob(&out, i1.aPoslist, i1.aEof - i1.aPoslist);
................................................................................
  5111   5127         if( p->rc==SQLITE_OK ){
  5112   5128           xMerge(p, &doclist, &aBuf[i]);
  5113   5129         }
  5114   5130         fts5BufferFree(&aBuf[i]);
  5115   5131       }
  5116   5132       fts5MultiIterFree(p1);
  5117   5133   
  5118         -    pData = fts5IdxMalloc(p, sizeof(Fts5Data) + doclist.n);
         5134  +    pData = fts5IdxMalloc(p, sizeof(Fts5Data)+doclist.n+FTS5_DATA_ZERO_PADDING);
  5119   5135       if( pData ){
  5120   5136         pData->p = (u8*)&pData[1];
  5121   5137         pData->nn = pData->szLeaf = doclist.n;
  5122   5138         if( doclist.n ) memcpy(pData->p, doclist.p, doclist.n);
  5123   5139         fts5MultiIterNew2(p, pData, bDesc, ppIter);
  5124   5140       }
  5125   5141       fts5BufferFree(&doclist);
................................................................................
  5877   5893   
  5878   5894         iOff = fts5LeafFirstTermOff(pLeaf);
  5879   5895         iRowidOff = fts5LeafFirstRowidOff(pLeaf);
  5880   5896         if( iRowidOff>=iOff || iOff>=pLeaf->szLeaf ){
  5881   5897           p->rc = FTS5_CORRUPT;
  5882   5898         }else{
  5883   5899           iOff += fts5GetVarint32(&pLeaf->p[iOff], nTerm);
  5884         -        res = memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
         5900  +        res = fts5Memcmp(&pLeaf->p[iOff], zIdxTerm, MIN(nTerm, nIdxTerm));
  5885   5901           if( res==0 ) res = nTerm - nIdxTerm;
  5886   5902           if( res<0 ) p->rc = FTS5_CORRUPT;
  5887   5903         }
  5888   5904   
  5889   5905         fts5IntegrityCheckPgidx(p, pLeaf);
  5890   5906       }
  5891   5907       fts5DataRelease(pLeaf);

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   
................................................................................
   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    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);
................................................................................
   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    908     sqlite3_int64 nByte;
   910    909     int rc;
   911    910     const char *zRank = pCsr->zRank;
   912    911     const char *zRankArgs = pCsr->zRankArgs;
   913    912     
................................................................................
   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);
................................................................................
  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   1499     assert( sqlite3_value_type(apVal[0])==SQLITE_INTEGER 
  1501   1500          || sqlite3_value_type(apVal[0])==SQLITE_NULL 
  1502   1501     );
  1503         -  assert( pTab->pConfig->pzErrmsg==0 );
  1504         -  pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg;
         1502  +  assert( pTab->p.pConfig->pzErrmsg==0 );
         1503  +  pTab->p.pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
  1505   1504   
  1506   1505     /* Put any active cursors into REQUIRE_SEEK state. */
  1507   1506     fts5TripCursors(pTab);
  1508   1507   
  1509   1508     eType0 = sqlite3_value_type(apVal[0]);
  1510   1509     if( eType0==SQLITE_NULL 
  1511   1510      && sqlite3_value_type(apVal[2+pConfig->nCol])!=SQLITE_NULL 
................................................................................
  1538   1537   
  1539   1538       assert( eType0==SQLITE_INTEGER || eType0==SQLITE_NULL );
  1540   1539       assert( nArg!=1 || eType0==SQLITE_INTEGER );
  1541   1540   
  1542   1541       /* Filter out attempts to run UPDATE or DELETE on contentless tables.
  1543   1542       ** This is not suported.  */
  1544   1543       if( eType0==SQLITE_INTEGER && fts5IsContentless(pTab) ){
  1545         -      pTab->base.zErrMsg = sqlite3_mprintf(
         1544  +      pTab->p.base.zErrMsg = sqlite3_mprintf(
  1546   1545             "cannot %s contentless fts5 table: %s", 
  1547   1546             (nArg>1 ? "UPDATE" : "DELETE from"), pConfig->zName
  1548   1547         );
  1549   1548         rc = SQLITE_ERROR;
  1550   1549       }
  1551   1550   
  1552   1551       /* DELETE */
................................................................................
  1596   1595             rc = sqlite3Fts5StorageDelete(pTab->pStorage, iOld, 0);
  1597   1596             fts5StorageInsert(&rc, pTab, apVal, pRowid);
  1598   1597           }
  1599   1598         }
  1600   1599       }
  1601   1600     }
  1602   1601   
  1603         -  pTab->pConfig->pzErrmsg = 0;
         1602  +  pTab->p.pConfig->pzErrmsg = 0;
  1604   1603     return rc;
  1605   1604   }
  1606   1605   
  1607   1606   /*
  1608   1607   ** Implementation of xSync() method. 
  1609   1608   */
  1610   1609   static int fts5SyncMethod(sqlite3_vtab *pVtab){
  1611   1610     int rc;
  1612         -  Fts5Table *pTab = (Fts5Table*)pVtab;
         1611  +  Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
  1613   1612     fts5CheckTransactionState(pTab, FTS5_SYNC, 0);
  1614         -  pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg;
         1613  +  pTab->p.pConfig->pzErrmsg = &pTab->p.base.zErrMsg;
  1615   1614     fts5TripCursors(pTab);
  1616   1615     rc = sqlite3Fts5StorageSync(pTab->pStorage);
  1617         -  pTab->pConfig->pzErrmsg = 0;
         1616  +  pTab->p.pConfig->pzErrmsg = 0;
  1618   1617     return rc;
  1619   1618   }
  1620   1619   
  1621   1620   /*
  1622   1621   ** Implementation of xBegin() method. 
  1623   1622   */
  1624   1623   static int fts5BeginMethod(sqlite3_vtab *pVtab){
  1625         -  fts5CheckTransactionState((Fts5Table*)pVtab, FTS5_BEGIN, 0);
  1626         -  fts5NewTransaction((Fts5Table*)pVtab);
         1624  +  fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_BEGIN, 0);
         1625  +  fts5NewTransaction((Fts5FullTable*)pVtab);
  1627   1626     return SQLITE_OK;
  1628   1627   }
  1629   1628   
  1630   1629   /*
  1631   1630   ** Implementation of xCommit() method. This is a no-op. The contents of
  1632   1631   ** the pending-terms hash-table have already been flushed into the database
  1633   1632   ** by fts5SyncMethod().
  1634   1633   */
  1635   1634   static int fts5CommitMethod(sqlite3_vtab *pVtab){
  1636   1635     UNUSED_PARAM(pVtab);  /* Call below is a no-op for NDEBUG builds */
  1637         -  fts5CheckTransactionState((Fts5Table*)pVtab, FTS5_COMMIT, 0);
         1636  +  fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_COMMIT, 0);
  1638   1637     return SQLITE_OK;
  1639   1638   }
  1640   1639   
  1641   1640   /*
  1642   1641   ** Implementation of xRollback(). Discard the contents of the pending-terms
  1643   1642   ** hash-table. Any changes made to the database are reverted by SQLite.
  1644   1643   */
  1645   1644   static int fts5RollbackMethod(sqlite3_vtab *pVtab){
  1646   1645     int rc;
  1647         -  Fts5Table *pTab = (Fts5Table*)pVtab;
         1646  +  Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
  1648   1647     fts5CheckTransactionState(pTab, FTS5_ROLLBACK, 0);
  1649   1648     rc = sqlite3Fts5StorageRollback(pTab->pStorage);
  1650   1649     return rc;
  1651   1650   }
  1652   1651   
  1653   1652   static int fts5CsrPoslist(Fts5Cursor*, int, const u8**, int*);
  1654   1653   
................................................................................
  1664   1663   
  1665   1664   static int fts5ApiColumnTotalSize(
  1666   1665     Fts5Context *pCtx, 
  1667   1666     int iCol, 
  1668   1667     sqlite3_int64 *pnToken
  1669   1668   ){
  1670   1669     Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
  1671         -  Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
         1670  +  Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
  1672   1671     return sqlite3Fts5StorageSize(pTab->pStorage, iCol, pnToken);
  1673   1672   }
  1674   1673   
  1675   1674   static int fts5ApiRowCount(Fts5Context *pCtx, i64 *pnRow){
  1676   1675     Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
  1677         -  Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
         1676  +  Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
  1678   1677     return sqlite3Fts5StorageRowCount(pTab->pStorage, pnRow);
  1679   1678   }
  1680   1679   
  1681   1680   static int fts5ApiTokenize(
  1682   1681     Fts5Context *pCtx, 
  1683   1682     const char *pText, int nText, 
  1684   1683     void *pUserData,
................................................................................
  1705   1704     Fts5Context *pCtx, 
  1706   1705     int iCol, 
  1707   1706     const char **pz, 
  1708   1707     int *pn
  1709   1708   ){
  1710   1709     int rc = SQLITE_OK;
  1711   1710     Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
  1712         -  if( fts5IsContentless((Fts5Table*)(pCsr->base.pVtab)) ){
         1711  +  if( fts5IsContentless((Fts5FullTable*)(pCsr->base.pVtab)) 
         1712  +   || pCsr->ePlan==FTS5_PLAN_SPECIAL 
         1713  +  ){
  1713   1714       *pz = 0;
  1714   1715       *pn = 0;
  1715   1716     }else{
  1716   1717       rc = fts5SeekCursor(pCsr, 0);
  1717   1718       if( rc==SQLITE_OK ){
  1718   1719         *pz = (const char*)sqlite3_column_text(pCsr->pStmt, iCol+1);
  1719   1720         *pn = sqlite3_column_bytes(pCsr->pStmt, iCol+1);
................................................................................
  1774   1775   ** correctly for the current view. Return SQLITE_OK if successful, or an
  1775   1776   ** SQLite error code otherwise.
  1776   1777   */
  1777   1778   static int fts5CacheInstArray(Fts5Cursor *pCsr){
  1778   1779     int rc = SQLITE_OK;
  1779   1780     Fts5PoslistReader *aIter;       /* One iterator for each phrase */
  1780   1781     int nIter;                      /* Number of iterators/phrases */
         1782  +  int nCol = ((Fts5Table*)pCsr->base.pVtab)->pConfig->nCol;
  1781   1783     
  1782   1784     nIter = sqlite3Fts5ExprPhraseCount(pCsr->pExpr);
  1783   1785     if( pCsr->aInstIter==0 ){
  1784   1786       sqlite3_int64 nByte = sizeof(Fts5PoslistReader) * nIter;
  1785   1787       pCsr->aInstIter = (Fts5PoslistReader*)sqlite3Fts5MallocZero(&rc, nByte);
  1786   1788     }
  1787   1789     aIter = pCsr->aInstIter;
................................................................................
  1827   1829             }
  1828   1830           }
  1829   1831   
  1830   1832           aInst = &pCsr->aInst[3 * (nInst-1)];
  1831   1833           aInst[0] = iBest;
  1832   1834           aInst[1] = FTS5_POS2COLUMN(aIter[iBest].iPos);
  1833   1835           aInst[2] = FTS5_POS2OFFSET(aIter[iBest].iPos);
         1836  +        if( aInst[1]<0 || aInst[1]>=nCol ){
         1837  +          rc = FTS5_CORRUPT;
         1838  +          break;
         1839  +        }
  1834   1840           sqlite3Fts5PoslistReaderNext(&aIter[iBest]);
  1835   1841         }
  1836   1842       }
  1837   1843   
  1838   1844       pCsr->nInstCount = nInst;
  1839   1845       CsrFlagClear(pCsr, FTS5CSR_REQUIRE_INST);
  1840   1846     }
................................................................................
  1899   1905       (*pCnt)++;
  1900   1906     }
  1901   1907     return SQLITE_OK;
  1902   1908   }
  1903   1909   
  1904   1910   static int fts5ApiColumnSize(Fts5Context *pCtx, int iCol, int *pnToken){
  1905   1911     Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
  1906         -  Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
  1907         -  Fts5Config *pConfig = pTab->pConfig;
         1912  +  Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
         1913  +  Fts5Config *pConfig = pTab->p.pConfig;
  1908   1914     int rc = SQLITE_OK;
  1909   1915   
  1910   1916     if( CsrFlagTest(pCsr, FTS5CSR_REQUIRE_DOCSIZE) ){
  1911   1917       if( pConfig->bColumnsize ){
  1912   1918         i64 iRowid = fts5CursorRowid(pCsr);
  1913   1919         rc = sqlite3Fts5StorageDocsize(pTab->pStorage, iRowid, pCsr->aColumnSize);
  1914   1920       }else if( pConfig->zContent==0 ){
................................................................................
  2156   2162   static int fts5ApiQueryPhrase(
  2157   2163     Fts5Context *pCtx, 
  2158   2164     int iPhrase, 
  2159   2165     void *pUserData,
  2160   2166     int(*xCallback)(const Fts5ExtensionApi*, Fts5Context*, void*)
  2161   2167   ){
  2162   2168     Fts5Cursor *pCsr = (Fts5Cursor*)pCtx;
  2163         -  Fts5Table *pTab = (Fts5Table*)(pCsr->base.pVtab);
         2169  +  Fts5FullTable *pTab = (Fts5FullTable*)(pCsr->base.pVtab);
  2164   2170     int rc;
  2165   2171     Fts5Cursor *pNew = 0;
  2166   2172   
  2167   2173     rc = fts5OpenMethod(pCsr->base.pVtab, (sqlite3_vtab_cursor**)&pNew);
  2168   2174     if( rc==SQLITE_OK ){
  2169   2175       pNew->ePlan = FTS5_PLAN_MATCH;
  2170   2176       pNew->iFirstRowid = SMALLEST_INT64;
................................................................................
  2233   2239     }else{
  2234   2240       fts5ApiInvoke(pAux, pCsr, context, argc-1, &argv[1]);
  2235   2241     }
  2236   2242   }
  2237   2243   
  2238   2244   
  2239   2245   /*
  2240         -** Given cursor id iId, return a pointer to the corresponding Fts5Index 
         2246  +** Given cursor id iId, return a pointer to the corresponding Fts5Table 
  2241   2247   ** object. Or NULL If the cursor id does not exist.
  2242         -**
  2243         -** If successful, set *ppConfig to point to the associated config object 
  2244         -** before returning.
  2245   2248   */
  2246         -Fts5Index *sqlite3Fts5IndexFromCsrid(
         2249  +Fts5Table *sqlite3Fts5TableFromCsrid(
  2247   2250     Fts5Global *pGlobal,            /* FTS5 global context for db handle */
  2248         -  i64 iCsrId,                     /* Id of cursor to find */
  2249         -  Fts5Config **ppConfig           /* OUT: Configuration object */
         2251  +  i64 iCsrId                      /* Id of cursor to find */
  2250   2252   ){
  2251   2253     Fts5Cursor *pCsr;
  2252   2254     pCsr = fts5CursorFromCsrid(pGlobal, iCsrId);
  2253   2255     if( pCsr ){
  2254         -    Fts5Table *pTab = (Fts5Table*)pCsr->base.pVtab;
  2255         -    *ppConfig = pTab->pConfig;
  2256         -    return pTab->pIndex;
         2256  +    return (Fts5Table*)pCsr->base.pVtab;
  2257   2257     }
  2258   2258     return 0;
  2259   2259   }
  2260   2260   
  2261   2261   /*
  2262   2262   ** Return a "position-list blob" corresponding to the current position of
  2263   2263   ** cursor pCsr via sqlite3_result_blob(). A position-list blob contains
................................................................................
  2331   2331   ** the row that the supplied cursor currently points to.
  2332   2332   */
  2333   2333   static int fts5ColumnMethod(
  2334   2334     sqlite3_vtab_cursor *pCursor,   /* Cursor to retrieve value from */
  2335   2335     sqlite3_context *pCtx,          /* Context for sqlite3_result_xxx() calls */
  2336   2336     int iCol                        /* Index of column to read value from */
  2337   2337   ){
  2338         -  Fts5Table *pTab = (Fts5Table*)(pCursor->pVtab);
  2339         -  Fts5Config *pConfig = pTab->pConfig;
         2338  +  Fts5FullTable *pTab = (Fts5FullTable*)(pCursor->pVtab);
         2339  +  Fts5Config *pConfig = pTab->p.pConfig;
  2340   2340     Fts5Cursor *pCsr = (Fts5Cursor*)pCursor;
  2341   2341     int rc = SQLITE_OK;
  2342   2342     
  2343   2343     assert( CsrFlagTest(pCsr, FTS5CSR_EOF)==0 );
  2344   2344   
  2345   2345     if( pCsr->ePlan==FTS5_PLAN_SPECIAL ){
  2346   2346       if( iCol==pConfig->nCol ){
................................................................................
  2384   2384   static int fts5FindFunctionMethod(
  2385   2385     sqlite3_vtab *pVtab,            /* Virtual table handle */
  2386   2386     int nUnused,                    /* Number of SQL function arguments */
  2387   2387     const char *zName,              /* Name of SQL function */
  2388   2388     void (**pxFunc)(sqlite3_context*,int,sqlite3_value**), /* OUT: Result */
  2389   2389     void **ppArg                    /* OUT: User data for *pxFunc */
  2390   2390   ){
  2391         -  Fts5Table *pTab = (Fts5Table*)pVtab;
         2391  +  Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
  2392   2392     Fts5Auxiliary *pAux;
  2393   2393   
  2394   2394     UNUSED_PARAM(nUnused);
  2395   2395     pAux = fts5FindAuxiliary(pTab, zName);
  2396   2396     if( pAux ){
  2397   2397       *pxFunc = fts5ApiCallback;
  2398   2398       *ppArg = (void*)pAux;
................................................................................
  2406   2406   /*
  2407   2407   ** Implementation of FTS5 xRename method. Rename an fts5 table.
  2408   2408   */
  2409   2409   static int fts5RenameMethod(
  2410   2410     sqlite3_vtab *pVtab,            /* Virtual table handle */
  2411   2411     const char *zName               /* New name of table */
  2412   2412   ){
  2413         -  Fts5Table *pTab = (Fts5Table*)pVtab;
         2413  +  Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
  2414   2414     return sqlite3Fts5StorageRename(pTab->pStorage, zName);
  2415   2415   }
         2416  +
         2417  +int sqlite3Fts5FlushToDisk(Fts5Table *pTab){
         2418  +  fts5TripCursors((Fts5FullTable*)pTab);
         2419  +  return sqlite3Fts5StorageSync(((Fts5FullTable*)pTab)->pStorage);
         2420  +}
  2416   2421   
  2417   2422   /*
  2418   2423   ** The xSavepoint() method.
  2419   2424   **
  2420   2425   ** Flush the contents of the pending-terms table to disk.
  2421   2426   */
  2422   2427   static int fts5SavepointMethod(sqlite3_vtab *pVtab, int iSavepoint){
  2423         -  Fts5Table *pTab = (Fts5Table*)pVtab;
  2424   2428     UNUSED_PARAM(iSavepoint);  /* Call below is a no-op for NDEBUG builds */
  2425         -  fts5CheckTransactionState(pTab, FTS5_SAVEPOINT, iSavepoint);
  2426         -  fts5TripCursors(pTab);
  2427         -  return sqlite3Fts5StorageSync(pTab->pStorage);
         2429  +  fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_SAVEPOINT, iSavepoint);
         2430  +  return sqlite3Fts5FlushToDisk((Fts5Table*)pVtab);
  2428   2431   }
  2429   2432   
  2430   2433   /*
  2431   2434   ** The xRelease() method.
  2432   2435   **
  2433   2436   ** This is a no-op.
  2434   2437   */
  2435   2438   static int fts5ReleaseMethod(sqlite3_vtab *pVtab, int iSavepoint){
  2436         -  Fts5Table *pTab = (Fts5Table*)pVtab;
  2437   2439     UNUSED_PARAM(iSavepoint);  /* Call below is a no-op for NDEBUG builds */
  2438         -  fts5CheckTransactionState(pTab, FTS5_RELEASE, iSavepoint);
  2439         -  fts5TripCursors(pTab);
  2440         -  return sqlite3Fts5StorageSync(pTab->pStorage);
         2440  +  fts5CheckTransactionState((Fts5FullTable*)pVtab, FTS5_RELEASE, iSavepoint);
         2441  +  return sqlite3Fts5FlushToDisk((Fts5Table*)pVtab);
  2441   2442   }
  2442   2443   
  2443   2444   /*
  2444   2445   ** The xRollbackTo() method.
  2445   2446   **
  2446   2447   ** Discard the contents of the pending terms table.
  2447   2448   */
  2448   2449   static int fts5RollbackToMethod(sqlite3_vtab *pVtab, int iSavepoint){
  2449         -  Fts5Table *pTab = (Fts5Table*)pVtab;
         2450  +  Fts5FullTable *pTab = (Fts5FullTable*)pVtab;
  2450   2451     UNUSED_PARAM(iSavepoint);  /* Call below is a no-op for NDEBUG builds */
  2451   2452     fts5CheckTransactionState(pTab, FTS5_ROLLBACKTO, iSavepoint);
  2452   2453     fts5TripCursors(pTab);
  2453   2454     return sqlite3Fts5StorageRollback(pTab->pStorage);
  2454   2455   }
  2455   2456   
  2456   2457   /*

Changes to ext/fts5/fts5_storage.c.

  1074   1074     }
  1075   1075     return rc;
  1076   1076   }
  1077   1077   
  1078   1078   int sqlite3Fts5StorageRowCount(Fts5Storage *p, i64 *pnRow){
  1079   1079     int rc = fts5StorageLoadTotals(p, 0);
  1080   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.  */
  1081   1086       *pnRow = p->nTotalRow;
         1087  +    if( p->nTotalRow<=0 ) rc = FTS5_CORRUPT;
  1082   1088     }
  1083   1089     return rc;
  1084   1090   }
  1085   1091   
  1086   1092   /*
  1087   1093   ** Flush any data currently held in-memory to disk.
  1088   1094   */

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 ){
          351  +  if( rc==SQLITE_OK ){
          352  +    if( pFts5==0 ){
   354    353       rc = sqlite3_finalize(pStmt);
   355    354       pStmt = 0;
   356    355       if( rc==SQLITE_OK ){
   357    356         pVTab->zErrMsg = sqlite3_mprintf(
   358    357             "no such fts5 table: %s.%s", pTab->zFts5Db, pTab->zFts5Tbl
   359    358         );
   360    359         rc = SQLITE_ERROR;
   361    360       }
          361  +    }else{
          362  +      rc = sqlite3Fts5FlushToDisk(pFts5);
          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     
   434    436     assert( sqlite3Fts5IterEof(pIter)==0 );
   435    437     assert( pCsr->bEof==0 );
................................................................................
   456    458   /*
   457    459   ** Advance the cursor to the next row in the table.
   458    460   */
   459    461   static int fts5VocabNextMethod(sqlite3_vtab_cursor *pCursor){
   460    462     Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor;
   461    463     Fts5VocabTable *pTab = (Fts5VocabTable*)pCursor->pVtab;
   462    464     int rc = SQLITE_OK;
   463         -  int nCol = pCsr->pConfig->nCol;
          465  +  int nCol = pCsr->pFts5->pConfig->nCol;
   464    466   
   465    467     pCsr->rowid++;
   466    468   
   467    469     if( pTab->eType==FTS5_VOCAB_INSTANCE ){
   468    470       return fts5VocabInstanceNext(pCsr);
   469    471     }
   470    472   
................................................................................
   494    496         sqlite3Fts5BufferSet(&rc, &pCsr->term, nTerm, (const u8*)zTerm);
   495    497         memset(pCsr->aCnt, 0, nCol * sizeof(i64));
   496    498         memset(pCsr->aDoc, 0, nCol * sizeof(i64));
   497    499         pCsr->iCol = 0;
   498    500   
   499    501         assert( pTab->eType==FTS5_VOCAB_COL || pTab->eType==FTS5_VOCAB_ROW );
   500    502         while( rc==SQLITE_OK ){
   501         -        int eDetail = pCsr->pConfig->eDetail;
          503  +        int eDetail = pCsr->pFts5->pConfig->eDetail;
   502    504           const u8 *pPos; int nPos;   /* Position list */
   503    505           i64 iPos = 0;               /* 64-bit position read from poslist */
   504    506           int iOff = 0;               /* Current offset within position list */
   505    507   
   506    508           pPos = pCsr->pIter->pData;
   507    509           nPos = pCsr->pIter->nData;
   508    510   
................................................................................
   554    556           if( rc==SQLITE_OK ){
   555    557             rc = sqlite3Fts5IterNextScan(pCsr->pIter);
   556    558           }
   557    559           if( pTab->eType==FTS5_VOCAB_INSTANCE ) break;
   558    560   
   559    561           if( rc==SQLITE_OK ){
   560    562             zTerm = sqlite3Fts5IterTerm(pCsr->pIter, &nTerm);
   561         -          if( nTerm!=pCsr->term.n || memcmp(zTerm, pCsr->term.p, nTerm) ){
          563  +          if( nTerm!=pCsr->term.n 
          564  +          || (nTerm>0 && memcmp(zTerm, pCsr->term.p, nTerm)) 
          565  +          ){
   562    566               break;
   563    567             }
   564    568             if( sqlite3Fts5IterEof(pCsr->pIter) ) break;
   565    569           }
   566    570         }
   567    571       }
   568    572     }
   569    573   
   570    574     if( rc==SQLITE_OK && pCsr->bEof==0 && pTab->eType==FTS5_VOCAB_COL ){
   571    575       while( pCsr->aDoc[pCsr->iCol]==0 ) pCsr->iCol++;
   572         -    assert( pCsr->iCol<pCsr->pConfig->nCol );
          576  +    assert( pCsr->iCol<pCsr->pFts5->pConfig->nCol );
   573    577     }
   574    578     return rc;
   575    579   }
   576    580   
   577    581   /*
   578    582   ** This is the xFilter implementation for the virtual table.
   579    583   */
................................................................................
   612    616     }else{
   613    617       if( pGe ){
   614    618         zTerm = (const char *)sqlite3_value_text(pGe);
   615    619         nTerm = sqlite3_value_bytes(pGe);
   616    620       }
   617    621       if( pLe ){
   618    622         const char *zCopy = (const char *)sqlite3_value_text(pLe);
          623  +      if( zCopy==0 ) zCopy = "";
   619    624         pCsr->nLeTerm = sqlite3_value_bytes(pLe);
   620    625         pCsr->zLeTerm = sqlite3_malloc(pCsr->nLeTerm+1);
   621    626         if( pCsr->zLeTerm==0 ){
   622    627           rc = SQLITE_NOMEM;
   623    628         }else{
   624    629           memcpy(pCsr->zLeTerm, zCopy, pCsr->nLeTerm+1);
   625    630         }
   626    631       }
   627    632     }
   628    633   
   629    634     if( rc==SQLITE_OK ){
   630         -    rc = sqlite3Fts5IndexQuery(pCsr->pIndex, zTerm, nTerm, f, 0, &pCsr->pIter);
          635  +    Fts5Index *pIndex = pCsr->pFts5->pIndex;
          636  +    rc = sqlite3Fts5IndexQuery(pIndex, zTerm, nTerm, f, 0, &pCsr->pIter);
   631    637     }
   632    638     if( rc==SQLITE_OK && eType==FTS5_VOCAB_INSTANCE ){
   633    639       rc = fts5VocabInstanceNewTerm(pCsr);
   634    640     }
   635         -  if( rc==SQLITE_OK 
   636         -   && !pCsr->bEof 
   637         -   && (eType!=FTS5_VOCAB_INSTANCE || pCsr->pConfig->eDetail!=FTS5_DETAIL_NONE)
          641  +  if( rc==SQLITE_OK && !pCsr->bEof 
          642  +   && (eType!=FTS5_VOCAB_INSTANCE 
          643  +    || pCsr->pFts5->pConfig->eDetail!=FTS5_DETAIL_NONE)
   638    644     ){
   639    645       rc = fts5VocabNextMethod(pCursor);
   640    646     }
   641    647   
   642    648     return rc;
   643    649   }
   644    650   
................................................................................
   653    659   
   654    660   static int fts5VocabColumnMethod(
   655    661     sqlite3_vtab_cursor *pCursor,   /* Cursor to retrieve value from */
   656    662     sqlite3_context *pCtx,          /* Context for sqlite3_result_xxx() calls */
   657    663     int iCol                        /* Index of column to read value from */
   658    664   ){
   659    665     Fts5VocabCursor *pCsr = (Fts5VocabCursor*)pCursor;
   660         -  int eDetail = pCsr->pConfig->eDetail;
          666  +  int eDetail = pCsr->pFts5->pConfig->eDetail;
   661    667     int eType = ((Fts5VocabTable*)(pCursor->pVtab))->eType;
   662    668     i64 iVal = 0;
   663    669   
   664    670     if( iCol==0 ){
   665    671       sqlite3_result_text(
   666    672           pCtx, (const char*)pCsr->term.p, pCsr->term.n, SQLITE_TRANSIENT
   667    673       );
   668    674     }else if( eType==FTS5_VOCAB_COL ){
   669    675       assert( iCol==1 || iCol==2 || iCol==3 );
   670    676       if( iCol==1 ){
   671    677         if( eDetail!=FTS5_DETAIL_NONE ){
   672         -        const char *z = pCsr->pConfig->azCol[pCsr->iCol];
          678  +        const char *z = pCsr->pFts5->pConfig->azCol[pCsr->iCol];
   673    679           sqlite3_result_text(pCtx, z, -1, SQLITE_STATIC);
   674    680         }
   675    681       }else if( iCol==2 ){
   676    682         iVal = pCsr->aDoc[pCsr->iCol];
   677    683       }else{
   678    684         iVal = pCsr->aCnt[pCsr->iCol];
   679    685       }
................................................................................
   693    699         case 2: {
   694    700           int ii = -1;
   695    701           if( eDetail==FTS5_DETAIL_FULL ){
   696    702             ii = FTS5_POS2COLUMN(pCsr->iInstPos);
   697    703           }else if( eDetail==FTS5_DETAIL_COLUMNS ){
   698    704             ii = (int)pCsr->iInstPos;
   699    705           }
   700         -        if( ii>=0 && ii<pCsr->pConfig->nCol ){
   701         -          const char *z = pCsr->pConfig->azCol[ii];
          706  +        if( ii>=0 && ii<pCsr->pFts5->pConfig->nCol ){
          707  +          const char *z = pCsr->pFts5->pConfig->azCol[ii];
   702    708             sqlite3_result_text(pCtx, z, -1, SQLITE_STATIC);
   703    709           }
   704    710           break;
   705    711         }
   706    712         default: {
   707    713           assert( iCol==3 );
   708    714           if( eDetail==FTS5_DETAIL_FULL ){

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

  4046   4046   do_catchsql_test 34.1 {
  4047   4047     SELECT fts5_decode(id, block) FROM t1_data;
  4048   4048   } {1 {database disk image is malformed}}
  4049   4049   
  4050   4050   do_catchsql_test 34.2 {
  4051   4051     SELECT fts5_decode(id, block) FROM t2_data;
  4052   4052   } {1 {database disk image is malformed}}
         4053  +
         4054  +#-------------------------------------------------------------------------
         4055  +reset_db
         4056  +do_test 35.0 {
         4057  +  sqlite3 db {}
         4058  +  db deserialize [decode_hexdb {
         4059  +| size 32768 pagesize 4096 filename crash-ae135cb10977c7.db
         4060  +| page 1 offset 0
         4061  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         4062  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 08   .....@  ........
         4063  +|     32: 00 00 00 02 00 00 00 01 00 00 00 09 00 00 00 04   ................
         4064  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         4065  +|     96: 00 00 00 00 0d 0f c7 00 07 0d 92 00 0f 8d 0f 36   ...............6
         4066  +|    112: 0e cb 0e 6b 0e 0e 0d b6 0d 92 0d 92 00 00 00 00   ...k............
         4067  +|   3472: 00 00 22 08 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         4068  +|   3488: 32 74 32 08 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         4069  +|   3504: 20 74 32 28 78 29 56 07 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         4070  +|   3520: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         4071  +|   3536: 6f 6e 66 69 67 07 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         4072  +|   3552: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         4073  +|   3568: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         4074  +|   3584: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 06    WITHOUT ROWID[.
         4075  +|   3600: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         4076  +|   3616: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         4077  +|   3632: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         4078  +|   3648: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         4079  +|   3664: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         4080  +|   3680: 59 2c 20 73 7a 20 42 4c 4f 42 29 5e 05 07 17 21   Y, sz BLOB)^...!
         4081  +|   3696: 21 01 81 07 74 61 62 6c 65 74 31 5f 63 6f 6e 74   !...tablet1_cont
         4082  +|   3712: 65 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 05 43 52   entt1_content.CR
         4083  +|   3728: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63   EATE TABLE 't1_c
         4084  +|   3744: 6f 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47   ontent'(id INTEG
         4085  +|   3760: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   ER PRIMARY KEY, 
         4086  +|   3776: 63 30 2c 20 63 31 2c 20 63 32 29 69 04 07 17 19   c0, c1, c2)i....
         4087  +|   3792: 19 01 81 2d 74 61 62 6c 65 74 31 5f 69 64 78 74   ...-tablet1_idxt
         4088  +|   3808: 31 5f 69 64 78 04 43 52 45 41 54 45 20 54 41 42   1_idx.CREATE TAB
         4089  +|   3824: 4c 45 20 27 74 31 5f 69 64 78 27 28 73 65 67 69   LE 't1_idx'(segi
         4090  +|   3840: 64 2c 20 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50   d, term, pgno, P
         4091  +|   3856: 52 49 4d 41 52 59 20 4b 45 59 28 73 65 67 69 64   RIMARY KEY(segid
         4092  +|   3872: 2c 20 74 65 72 6d 29 29 20 57 49 54 48 4f 55 54   , term)) WITHOUT
         4093  +|   3888: 20 52 4f 57 49 44 55 03 07 17 1b 1b 01 81 01 74    ROWIDU........t
         4094  +|   3904: 61 62 6c 65 74 31 5f 64 61 74 61 74 31 5f 64 61   ablet1_datat1_da
         4095  +|   3920: 74 61 03 43 52 45 41 54 45 20 54 41 42 4c 45 20   ta.CREATE TABLE 
         4096  +|   3936: 27 74 31 5f 64 61 74 61 27 28 69 64 20 49 4e 54   't1_data'(id INT
         4097  +|   3952: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59   EGER PRIMARY KEY
         4098  +|   3968: 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 38 02 06   , block BLOB)8..
         4099  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         4100  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         4101  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35   LE t1 USING fts5
         4102  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00   (a,b,c)...9.....
         4103  +| page 3 offset 8192
         4104  +|      0: 0d 00 00 00 03 0c 94 00 0f e6 0f ef 0c 94 00 00   ................
         4105  +|   3216: 00 00 00 00 86 4a 84 80 80 80 80 01 04 00 8d 18   .....J..........
         4106  +|   3232: 00 00 03 2b 02 30 30 01 02 06 01 02 06 01 02 06   ...+.00.........
         4107  +|   3248: 1f 02 03 01 02 03 01 02 03 01 08 32 30 31 36 30   ...........20160
         4108  +|   3264: 36 30 39 01 02 07 01 02 07 01 02 07 01 01 34 01   609...........4.
         4109  +|   3280: 02 05 01 02 05 01 02 05 01 01 35 01 02 04 01 02   ..........5.....
         4110  +|   3296: 04 01 02 04 02 07 30 30 30 30 30 30 30 1c 02 3d   ......0000000..=
         4111  +|   3312: 01 02 04 01 02 04 01 06 62 69 6e 61 72 79 03 06   ........binary..
         4112  +|   3328: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         4113  +|   3344: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         4114  +|   3360: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02   ................
         4115  +|   3376: 03 06 01 02 02 03 06 01 02 02 01 08 63 6f 6d 70   ............comp
         4116  +|   3392: 69 6c 65 72 01 02 02 01 02 02 01 02 02 01 06 64   iler...........d
         4117  +|   3408: 62 73 74 61 74 07 02 03 01 02 03 01 02 03 02 04   bstat...........
         4118  +|   3424: 65 62 75 67 04 02 02 01 02 02 01 02 02 01 07 65   ebug...........e
         4119  +|   3440: 6e 61 62 6c 65 07 02 02 01 02 02 01 02 02 01 02   nable...........
         4120  +|   3456: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02   ................
         4121  +|   3472: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01   ................
         4122  +|   3488: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02   ................
         4123  +|   3504: 02 01 02 02 02 08 78 74 65 6e 73 69 6f 6e 1f 02   ......xtension..
         4124  +|   3520: 04 01 02 04 01 02 04 01 04 66 74 73 34 0a 02 03   .........fts4...
         4125  +|   3536: 01 02 03 01 02 03 04 01 35 0d 02 03 01 02 03 01   ........5.......
         4126  +|   3552: 02 03 01 03 67 63 63 01 02 03 01 02 03 01 02 03   ....gcc.........
         4127  +|   3568: 02 06 65 6f 70 6f 6c 79 10 02 03 01 02 03 01 02   ..eopoly........
         4128  +|   3584: 03 01 05 6a 73 6f 6e 31 13 02 03 01 02 03 01 02   ...json1........
         4129  +|   3600: 03 01 04 6c 6f 61 64 1f 02 03 01 02 03 01 02 03   ...load.........
         4130  +|   3616: 01 03 6d 61 78 1c 02 02 01 02 02 01 02 02 02 05   ..max...........
         4131  +|   3632: 65 6d 6f 72 79 1c 02 03 01 02 03 01 02 03 04 04   emory...........
         4132  +|   3648: 73 79 73 35 16 02 03 01 02 03 01 02 03 01 06 6e   sys5...........n
         4133  +|   3664: 6f 63 61 73 65 02 06 01 02 02 03 06 01 02 02 03   ocase...........
         4134  +|   3680: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06   ................
         4135  +|   3696: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         4136  +|   3712: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         4137  +|   3728: 02 01 04 6f 6d 69 74 1f 02 02 01 02 02 01 02 02   ...omit.........
         4138  +|   3744: 01 05 72 74 72 65 65 19 02 03 01 02 03 01 02 03   ..rtree.........
         4139  +|   3760: 04 02 69 6d 01 06 01 02 02 03 06 01 02 02 03 06   ..im............
         4140  +|   3776: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         4141  +|   3792: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         4142  +|   3808: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02   ................
         4143  +|   3824: 01 0a 74 68 72 65 61 64 73 61 66 65 22 02 02 01   ..threadsafe....
         4144  +|   3840: 02 02 01 02 02 01 04 76 74 61 62 07 02 04 01 02   .......vtab.....
         4145  +|   3856: 04 01 02 04 01 01 78 01 06 01 01 02 01 06 01 01   ......x.........
         4146  +|   3872: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02   ................
         4147  +|   3888: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01   ................
         4148  +|   3904: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06   ................
         4149  +|   3920: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01   ................
         4150  +|   3936: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01   ................
         4151  +|   3952: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02   ................
         4152  +|   3968: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01   ................
         4153  +|   3984: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06   ................
         4154  +|   4000: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01   ................
         4155  +|   4016: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01   ................
         4156  +|   4032: 02 01 06 01 01 02 01 06 01 01 02 04 15 13 0c 0c   ................
         4157  +|   4048: 12 44 13 11 0f 47 13 0e fc 0e 11 10 0f 0e 10 0f   .D...G..........
         4158  +|   4064: 44 0f 10 40 15 0f 07 01 03 00 14 24 5a 24 24 0f   D..@.......$Z$$.
         4159  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         4160  +| page 4 offset 12288
         4161  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
         4162  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         4163  +| page 5 offset 16384
         4164  +|      0: 0d 00 00 00 24 0c 0a 00 0f d8 0f af 0f 86 0f 74   ....$..........t
         4165  +|     16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5   .a.N./..........
         4166  +|     32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 01 2f 0d d5   ...t.[.@.$.../..
         4167  +|     48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb   .......h.O.5....
         4168  +|     64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a   .......x.W.>.$..
         4169  +|   3072: 00 00 00 00 00 00 00 00 00 00 18 24 05 00 25 0f   ...........$..%.
         4170  +|   3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49   .THREADSAFE=0XBI
         4171  +|   3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41   NARY.#..%..THREA
         4172  +|   3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 8f   DSAFE=0XNOCASE..
         4173  +|   3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d   ..%..THREADSAFE=
         4174  +|   3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d   0XRTRIM.!..3..OM
         4175  +|   3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f   IT LOAD EXTENSIO
         4176  +|   3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f   NXBINARY. ..3..O
         4177  +|   3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49   MIT LOAD EXTENSI
         4178  +|   3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17   ONXNOCASE....3..
         4179  +|   3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53   OMIT LOAD EXTENS
         4180  +|   3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19   IONXRTRIM....3..
         4181  +|   3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30   MAX MEMORY=50000
         4182  +|   3280: 30 30 30 57 42 49 4e 41 52 59 1f 1d 05 00 33 0f   000WBINARY....3.
         4183  +|   3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30   .MAX MEMORY=5000
         4184  +|   3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33   0000XNOCASE....3
         4185  +|   3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30   ..MAX MEMORY=500
         4186  +|   3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25   00000XRTRIM....%
         4187  +|   3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42   ..ENABLE RTREEXB
         4188  +|   3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         4189  +|   3392: 4c 45 20 52 54 52 45 45 59 4e 4f 43 41 53 45 17   LE RTREEYNOCASE.
         4190  +|   3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52   ...%..ENABLE RTR
         4191  +|   3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45   EEXRTRIM....)..E
         4192  +|   3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49   NABLE MEMSYS5XBI
         4193  +|   3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         4194  +|   3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45   E MEMSYS5XNOCASE
         4195  +|   3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45   ....)..ENABLE ME
         4196  +|   3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25   MSYS5XRTRIM....%
         4197  +|   3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42   ..ENABLE JSON1XB
         4198  +|   3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         4199  +|   3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17   LE JSON1XNOCASE.
         4200  +|   3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f   ...%..ENABLE JSO
         4201  +|   3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45   N1XRTRIM....)..E
         4202  +|   3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49   NABLE GEOPOLYXBI
         4203  +|   3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4f 41 42 4c   NARY....)..EOABL
         4204  +|   3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 51 53 45   E GEOPOLYXNOCQSE
         4205  +|   3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45   ....)..ENABLE GE
         4206  +|   3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23   OPOLYXRTRIM....#
         4207  +|   3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49   ..ENABLE FTS5XBI
         4208  +|   3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c   NARY....#..ENABL
         4209  +|   3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 1d 05   E FTS5XNOCASE...
         4210  +|   3728: 00 23 0f a4 45 4e 41 42 4c 45 20 46 54 53 35 58   .#..ENABLE FTS5X
         4211  +|   3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42   RTRIM....#..ENAB
         4212  +|   3760: 4c 45 20 46 55 53 34 58 42 49 4e 41 52 59 17 0b   LE FUS4XBINARY..
         4213  +|   3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34   ..#..ENABLE FTS4
         4214  +|   3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e   XNOCASE....#..EN
         4215  +|   3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e   ABLE FTS4XRTRIM.
         4216  +|   3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         4217  +|   3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e   TAT VTABXBINARY.
         4218  +|   3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         4219  +|   3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d   TAT VTABXNOCASE.
         4220  +|   3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         4221  +|   3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06   TAT VTABXRTRIM..
         4222  +|   3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52   .....DEBUGXBINAR
         4223  +|   3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f   Y.......DEBUGXNO
         4224  +|   3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47   CASE.......DEBUG
         4225  +|   3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d   XRTRIM'...C..COM
         4226  +|   3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20   PILER=gcc-5.4.0 
         4227  +|   4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27   20160609XBINARY'
         4228  +|   4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67   ...C..COMPILER=g
         4229  +|   4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30   cc-5.4.0 2016060
         4230  +|   4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43   9XNOCASE&...C..C
         4231  +|   4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e   OMPILER=gcc-5.4.
         4232  +|   4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d   0 20160609XRTRIM
         4233  +| page 6 offset 20480
         4234  +|      0: 0d 00 00 00 24 0e e0 00 0f f8 0f f0 0f e8 0f e0   ....$...........
         4235  +|     16: 0f d8 0f d0 0f c8 0f c0 0f b8 0f b0 0f a8 0f a0   ................
         4236  +|     32: 0f 98 0f 90 0f 88 0f 80 0f 78 0f 70 0f 68 0f 60   .........x.p.h.`
         4237  +|     48: 0f 58 0f 50 0f 48 0f 40 0f 38 0f 30 0f 28 0f 20   .X.P.H.@.8.0.(. 
         4238  +|     64: 0f 18 0f 10 0f 08 0f 00 0e f8 0e f0 0e e8 0e e0   ................
         4239  +|   3808: 06 24 03 00 12 02 01 01 06 23 03 00 12 02 01 01   .$.......#......
         4240  +|   3824: 06 22 03 00 12 02 01 01 06 21 03 00 12 03 01 01   .........!......
         4241  +|   3840: 06 20 03 00 12 03 01 01 06 1f 03 00 12 03 01 01   . ..............
         4242  +|   3856: 06 1e 03 00 12 03 01 01 06 1d 03 00 12 03 01 01   ................
         4243  +|   3872: 06 1c 03 00 12 03 01 01 06 1b 03 00 12 02 01 01   ................
         4244  +|   3888: 06 1a 03 00 12 02 01 01 06 19 03 00 12 02 01 01   ................
         4245  +|   3904: 06 18 03 00 12 02 01 01 06 17 03 00 12 02 01 01   ................
         4246  +|   3920: 06 16 03 00 12 02 01 01 06 15 03 00 12 02 01 01   ................
         4247  +|   3936: 06 14 03 00 12 02 01 01 06 13 03 00 12 02 01 01   ................
         4248  +|   3952: 06 12 03 00 12 02 01 01 06 11 03 00 12 02 01 01   ................
         4249  +|   3968: 06 10 03 00 12 02 01 01 06 0f 03 00 12 02 01 01   ................
         4250  +|   3984: 06 0e 03 00 12 02 01 01 06 0d 03 00 12 02 01 01   ................
         4251  +|   4000: 06 0c 03 00 12 02 01 01 06 0b 03 00 12 02 01 01   ................
         4252  +|   4016: 06 0a 03 00 12 02 01 01 06 09 03 00 12 03 01 01   ................
         4253  +|   4032: 06 08 03 00 12 03 01 01 06 07 03 00 12 03 01 01   ................
         4254  +|   4048: 06 06 03 00 12 01 01 01 06 05 03 00 12 01 01 01   ................
         4255  +|   4064: 06 04 03 00 12 01 01 01 06 03 03 00 12 06 01 01   ................
         4256  +|   4080: 06 02 03 00 12 06 01 01 06 01 03 00 12 06 01 01   ................
         4257  +| page 7 offset 24576
         4258  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         4259  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         4260  +| page 8 offset 28672
         4261  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e9 0f d6 00 00   ................
         4262  +|   4048: 00 00 00 00 00 00 11 03 02 2b 69 6e 74 65 67 72   .........+integr
         4263  +|   4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity-check....reb
         4264  +|   4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   uild....optimize
         4265  +| end crash-ae135cb10977c7.db
         4266  +}]} {}
         4267  +
         4268  +do_catchsql_test 35.1 {
         4269  +  SELECT * FROM t1 WHERE t1 MATCH 'e*';
         4270  +} {1 {database disk image is malformed}}
         4271  +
         4272  +#-------------------------------------------------------------------------
         4273  +reset_db
         4274  +do_test 36.0 {
         4275  +  sqlite3 db {}
         4276  +  db deserialize [decode_hexdb {
         4277  +| size 24576 pagesize 4096 filename crash-a6651222df1bd1.db
         4278  +| page 1 offset 0
         4279  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         4280  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 06   .....@  ........
         4281  +|     32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04   ................
         4282  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         4283  +|     96: 00 00 00 00 0d 00 00 00 06 0e 0f 00 0f aa 0f 53   ...............S
         4284  +|    112: 0e e8 0e 8b 0e 33 0e 0f 00 00 00 00 00 00 00 00   .....3..........
         4285  +|   3584: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22   ................
         4286  +|   3600: 06 06 17 11 11 01 31 74 61 62 6c 65 62 62 62 62   ......1tablebbbb
         4287  +|   3616: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 62 62   .CREATE TABLE bb
         4288  +|   3632: 28 61 29 56 05 06 17 1f 1f 01 7d 74 61 62 6c 65   (a)V.......table
         4289  +|   3648: 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63 6f 6e 66   t1_configt1_conf
         4290  +|   3664: 69 67 05 43 52 45 41 54 45 20 54 41 42 4c 45 20   ig.CREATE TABLE 
         4291  +|   3680: 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b 20 50 52   't1_config'(k PR
         4292  +|   3696: 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 20 57 49   IMARY KEY, v) WI
         4293  +|   3712: 54 48 4f 55 54 20 52 4f 57 49 44 5b 04 07 17 21   THOUT ROWID[...!
         4294  +|   3728: 21 01 81 01 74 61 62 6c 65 74 31 5f 64 6f 63 73   !...tablet1_docs
         4295  +|   3744: 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65 04 43 52   izet1_docsize.CR
         4296  +|   3760: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 64   EATE TABLE 't1_d
         4297  +|   3776: 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 54 45 47   ocsize'(id INTEG
         4298  +|   3792: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   ER PRIMARY KEY, 
         4299  +|   3808: 73 7a 20 42 4c 4f 42 29 69 03 07 17 19 19 01 81   sz BLOB)i.......
         4300  +|   3824: 2d 74 61 62 6c 65 74 31 5f 69 64 78 74 31 5f 69   -tablet1_idxt1_i
         4301  +|   3840: 64 78 03 43 52 45 41 54 45 20 54 41 42 4c 45 20   dx.CREATE TABLE 
         4302  +|   3856: 27 74 31 5f 69 64 78 27 28 73 65 67 69 64 2c 20   't1_idx'(segid, 
         4303  +|   3872: 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50 52 49 4d   term, pgno, PRIM
         4304  +|   3888: 41 52 59 20 4b 45 59 28 73 65 67 69 64 2c 20 74   ARY KEY(segid, t
         4305  +|   3904: 65 72 6d 29 29 20 57 49 54 48 4f 55 54 20 52 4f   erm)) WITHOUT RO
         4306  +|   3920: 57 49 44 55 02 07 17 1b 1b 01 81 01 74 61 62 6c   WIDU........tabl
         4307  +|   3936: 65 74 31 5f 64 61 74 61 74 31 5f 64 61 74 61 02   et1_datat1_data.
         4308  +|   3952: 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 31   CREATE TABLE 't1
         4309  +|   3968: 5f 64 61 74 61 27 28 69 64 20 49 4e 54 45 47 45   _data'(id INTEGE
         4310  +|   3984: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62   R PRIMARY KEY, b
         4311  +|   4000: 6c 6f 63 6b 20 42 4c 4f 42 29 54 01 07 17 11 11   lock BLOB)T.....
         4312  +|   4016: 08 81 15 74 61 62 6c 65 74 31 74 31 43 52 45 41   ...tablet1t1CREA
         4313  +|   4032: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45   TE VIRTUAL TABLE
         4314  +|   4048: 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28 61    t1 USING fts5(a
         4315  +|   4064: 2c 62 2c 70 72 65 66 69 78 3d 22 31 2c 32 2c 33   ,b,prefix=.1,2,3
         4316  +|   4080: 2c 34 22 2c 20 63 6f 6e 74 65 6e 74 3d 22 22 29   ,4., content=..)
         4317  +| page 2 offset 4096
         4318  +|      0: 0d 0b 6a 00 37 09 4c 02 0f e7 09 4c 0f c6 0f a4   ..j.7.L....L....
         4319  +|     16: 0f 88 0f 6d 0f 4b 0f 2c 0f 0e 0e ec 0e cd 0e ad   ...m.K.,........
         4320  +|     32: 0e 8e 0e 6c 0e 4b 0e 29 0e 08 0d e6 0d c4 0d b5   ...l.K.)........
         4321  +|     48: 0d 97 0d 76 0d 54 0d 31 0d 15 0c f3 0c d3 0c b5   ...v.T.1........
         4322  +|     64: 0c 95 0c 73 0c 54 0c 32 0c 10 0b ee 0b cc 0b b0   ...s.T.2........
         4323  +|     80: 0b 8d 0b 7e 0b 48 0b 2e 0b 0b 0a ef 0a cc 0a ad   ...~.H..........
         4324  +|     96: 0a 8c 0a 6d 0a 4d 0a 2b 0a 0c 09 ec 09 ca 09 a8   ...m.M.+........
         4325  +|    112: 09 86 09 63 0f f1 00 00 00 00 00 00 00 00 00 00   ...c............
         4326  +|   2368: 00 00 00 00 00 00 00 00 00 00 00 00 15 0a 03 00   ................
         4327  +|   2384: 30 00 00 00 01 01 03 35 00 03 01 11 12 02 01 12   0......5........
         4328  +|   2400: 03 01 11 1c 8c 80 80 80 80 10 03 00 3e 00 00 00   ............>...
         4329  +|   2416: 17 01 05 05 34 74 61 62 6c 03 02 03 01 04 77 68   ....4tabl.....wh
         4330  +|   2432: 65 72 03 02 06 09 1b 8c 80 80 80 80 0f 03 00 3c   er.............<
         4331  +|   2448: 00 00 00 16 05 34 66 74 73 34 03 02 02 01 04 6e   .....4fts4.....n
         4332  +|   2464: 75 6d 62 03 06 01 04 09 1b 8c 80 80 80 80 0e 03   umb.............
         4333  +|   2480: 00 3c 00 00 00 16 04 33 74 68 65 03 06 01 01 04   .<.....3the.....
         4334  +|   2496: 01 03 77 68 65 03 02 04 04 0a 1b 8c 80 80 80 80   ..whe...........
         4335  +|   2512: 0d 03 00 3c 00 00 00 16 04 33 6e 75 6d 03 06 01   ...<.....3num...
         4336  +|   2528: 01 05 01 03 74 61 62 03 02 03 04 0a 19 8c 80 80   ....tab.........
         4337  +|   2544: 80 80 0c 03 00 38 00 00 00 14 03 32 77 68 03 02   .....8.....2wh..
         4338  +|   2560: 04 00 04 33 66 74 73 03 02 02 04 07 18 8c 80 80   ...3fts.........
         4339  +|   2576: 80 80 0b 03 00 36 00 00 00 13 03 32 74 61 03 02   .....6.....2ta..
         4340  +|   2592: 03 02 01 68 03 06 01 01 04 04 07 1b 8c 80 80 80   ...h............
         4341  +|   2608: 80 0a 03 00 3c 00 00 00 16 03 32 6e 75 03 06 01   ....<.....2nu...
         4342  +|   2624: 01 05 01 02 6f 66 03 06 01 01 06 04 09 19 8c 80   ....of..........
         4343  +|   2640: 80 80 80 09 03 00 38 00 00 00 14 03 32 66 74 03   ......8.....2ft.
         4344  +|   2656: 02 02 01 02 69 73 03 06 01 01 03 04 07 18 8c 80   ....is..........
         4345  +|   2672: 80 80 80 08 03 00 36 00 00 00 13 02 31 74 03 08   ......6.....1t..
         4346  +|   2688: 03 01 01 04 01 01 77 03 02 04 04 09 1a 8c 80 80   ......w.........
         4347  +|   2704: 80 80 07 03 00 3a 00 00 00 15 02 31 6e 03 08 01   .....:.....1n...
         4348  +|   2720: 01 02 05 01 00 6f 03 06 01 01 06 04 09 18 8c 80   .....o..........
         4349  +|   2736: 80 80 80 06 03 00 36 00 00 00 13 04 02 31 66 03   ......6......1f.
         4350  +|   2752: 02 02 01 01 69 03 06 01 01 03 05 06 1c 8c 80 80   ....i...........
         4351  +|   2768: 80 80 05 03 00 3e 00 00 00 17 04 30 74 68 65 03   .....>.....0the.
         4352  +|   2784: 06 01 01 04 01 05 77 68 65 72 65 03 02 04 0a 15   ......where.....
         4353  +|   2800: 8c 80 80 80 80 04 03 00 30 00 00 00 11 01 01 06   ........0.......
         4354  +|   2816: 06 30 74 61 62 6c 65 03 02 03 07 1c 8c 80 80 80   .0table.........
         4355  +|   2832: 80 03 03 00 3e 00 00 00 17 07 30 6e 75 6d 62 65   ....>.....0numbe
         4356  +|   2848: 72 03 06 01 01 05 01 02 6f 66 03 06 04 0d 13 8c   r.......of......
         4357  +|   2864: 80 80 80 80 02 03 00 2c 00 00 00 0f 01 01 03 02   .......,........
         4358  +|   2880: 30 6e 03 06 01 01 02 07 1b 8c 80 80 80 80 01 03   0n..............
         4359  +|   2896: 00 3c 00 00 00 16 08 30 66 74 73 34 61 75 78 03   .<.....0fts4aux.
         4360  +|   2912: 02 02 01 02 69 73 03 06 04 0c 00 00 00 14 2a 00   ....is........*.
         4361  +|   2928: 00 00 01 01 02 24 00 02 01 01 12 02 01 12 08 88   .....$..........
         4362  +|   2944: 80 80 80 80 12 03 00 16 00 00 00 05 02 1c 88 80   ................
         4363  +|   2960: 80 80 80 11 03 00 3e 00 00 00 17 05 34 72 6f 77   ......>.....4row
         4364  +|   2976: 73 02 06 01 01 05 01 04 74 68 65 72 02 02 04 0b   s.......ther....
         4365  +|   2992: 15 88 80 80 80 80 10 03 00 30 00 00 00 11 02 01   .........0......
         4366  +|   3008: 01 07 05 34 62 65 74 77 02 02 04 08 1b 88 80 80   ...4betw........
         4367  +|   3024: 80 80 0f 03 00 3c 00 00 00 16 04 04 33 72 6f 77   .....<......3row
         4368  +|   3040: 02 06 01 01 05 01 03 74 68 65 02 08 05 0a 1b 88   .......the......
         4369  +|   3056: 80 80 80 80 0e 03 00 3c 00 00 00 16 01 01 02 04   .......<........
         4370  +|   3072: 33 61 72 65 02 02 03 01 03 62 65 74 02 02 07 08   3are.....bet....
         4371  +|   3088: 1b 88 80 80 80 80 0d 03 00 3c 00 00 00 16 13 32   .........<.....2
         4372  +|   3104: 74 68 02 08 02 01 01 07 00 04 33 61 6e 64 02 06   th........3and..
         4373  +|   3120: 04 0a 1b 88 80 80 80 80 0c 03 00 3c 00 00 00 16   ...........<....
         4374  +|   3136: 03 32 69 6e 02 06 01 01 06 01 02 72 6f 02 06 01   .2in.......ro...
         4375  +|   3152: 01 05 04 09 18 88 80 80 80 80 0b 03 00 36 00 00   .............6..
         4376  +|   3168: 00 13 02 03 32 61 72 02 02 03 01 02 62 65 02 02   ....2ar.....be..
         4377  +|   3184: 04 05 07 1b 88 80 80 80 80 0a 03 00 3c 00 00 00   ............<...
         4378  +|   3200: 16 02 31 74 02 08 02 01 01 07 00 03 32 61 6e 02   ..1t........2an.
         4379  +|   3216: 06 01 01 04 09 19 88 80 80 80 80 09 03 00 38 00   ..............8.
         4380  +|   3232: 00 00 14 02 31 6e 02 06 01 01 03 01 01 72 02 06   ....1n.......r..
         4381  +|   3248: 01 01 05 04 08 17 88 80 80 80 80 08 03 00 34 00   ..............4.
         4382  +|   3264: 00 00 12 02 31 62 02 02 04 01 01 69 02 06 01 01   ....1b.....i....
         4383  +|   3280: 06 04 06 19 88 80 80 80 80 07 03 00 38 00 00 00   ............8...
         4384  +|   3296: 14 04 02 31 32 02 02 05 01 01 61 02 08 03 01 01   ...12.....a.....
         4385  +|   3312: 02 05 06 1b 88 80 80 80 80 06 03 00 3c 00 00 00   ............<...
         4386  +|   3328: 16 06 30 74 68 65 72 65 02 02 02 00 02 31 31 02   ..0there.....11.
         4387  +|   3344: 06 01 01 04 0a 15 88 80 80 80 80 05 03 00 30 00   ..............0.
         4388  +|   3360: 00 00 11 01 01 05 04 30 74 68 65 02 06 01 01 07   .......0the.....
         4389  +|   3376: 07 1c 88 80 80 80 80 04 03 00 3e 00 00 00 17 01   ..........>.....
         4390  +|   3392: 01 06 02 30 6e 02 06 01 01 03 01 04 72 6f 77 73   ...0n.......rows
         4391  +|   3408: 02 06 07 08 1b 88 80 80 80 80 03 03 00 3c 00 00   .............<..
         4392  +|   3424: 00 16 08 30 62 65 74 77 65 65 6e 02 02 04 01 02   ...0between.....
         4393  +|   3440: 69 6e 02 06 04 0c 1a 88 80 80 80 80 02 03 00 3a   in.............:
         4394  +|   3456: 00 00 00 15 04 30 61 6e 64 02 06 01 01 02 02 02   .....0and.......
         4395  +|   3472: 72 65 02 02 03 04 0a 17 88 80 80 80 80 01 03 00   re..............
         4396  +|   3488: 34 00 00 00 12 02 30 31 02 06 01 01 04 01 01 32   4.....01.......2
         4397  +|   3504: 02 02 05 04 08 08 84 80 80 80 80 12 03 00 16 00   ................
         4398  +|   3520: 00 00 05 04 1b 84 80 80 80 80 11 03 00 3c 00 00   .............<..
         4399  +|   3536: 00 16 05 34 74 61 62 6c 01 06 01 01 05 02 03 65   ...4tabl.......e
         4400  +|   3552: 72 6d 01 02 04 0b 1b 84 80 80 80 80 10 03 00 3c   rm.............<
         4401  +|   3568: 00 00 00 16 05 34 65 61 63 68 01 02 03 01 04 70   .....4each.....p
         4402  +|   3584: 72 65 73 01 02 05 04 09 1a 84 80 80 80 80 0f 03   res.............
         4403  +|   3600: 00 3a 00 00 00 15 04 33 74 65 72 01 02 04 02 02   .:.....3ter.....
         4404  +|   3616: 68 65 01 06 01 01 03 04 08 1b 84 80 80 80 80 0e   he..............
         4405  +|   3632: 03 00 3c 00 00 00 16 04 33 70 72 65 01 02 05 01   ..<.....3pre....
         4406  +|   3648: 03 74 61 62 01 06 01 01 05 04 08 1a 84 80 80 80   .tab............
         4407  +|   3664: 80 0d 03 00 3a 00 00 00 15 04 33 66 6f 72 01 02   ....:.....3for..
         4408  +|   3680: 02 02 02 74 73 01 06 01 01 04 04 08 1b 84 80 80   ...ts...........
         4409  +|   3696: 80 80 0c 03 00 3c 00 00 00 16 03 32 74 68 01 06   .....<.....2th..
         4410  +|   3712: 01 01 03 00 04 33 65 61 63 01 02 03 04 09 18 84   .....3eac.......
         4411  +|   3728: 80 80 80 80 0b 03 00 36 00 00 00 13 03 32 74 61   .......6.....2ta
         4412  +|   3744: 01 06 01 01 05 02 01 65 01 02 04 04 09 19 84 80   .......e........
         4413  +|   3760: 80 80 80 0a 03 00 38 00 00 00 14 03 32 69 6e 01   ......8.....2in.
         4414  +|   3776: 06 01 01 02 01 02 70 72 01 02 05 04 09 18 84 80   ......pr........
         4415  +|   3792: 80 80 80 09 03 00 36 00 00 00 13 03 32 66 6f 01   ......6.....2fo.
         4416  +|   3808: 02 02 02 01 74 01 06 01 01 04 04 07 1b 84 80 80   ....t...........
         4417  +|   3824: 80 80 08 03 00 3c 00 00 00 16 02 31 74 01 0a 04   .....<.....1t...
         4418  +|   3840: 01 01 03 04 00 03 32 65 61 01 02 03 04 0a 17 84   ......2ea.......
         4419  +|   3856: 80 80 80 80 07 03 00 34 00 00 00 12 02 31 69 01   .......4.....1i.
         4420  +|   3872: 06 01 01 02 01 01 70 01 02 05 04 08 18 84 80 80   ......p.........
         4421  +|   3888: 80 80 06 03 00 36 00 00 00 13 02 31 65 01 02 03   .....6.....1e...
         4422  +|   3904: 01 01 66 01 08 02 01 01 04 04 06 1b 84 80 80 80   ..f.............
         4423  +|   3920: 80 05 03 00 3c 00 00 00 16 05 30 74 65 72 6d 01   ....<.....0term.
         4424  +|   3936: 02 04 02 02 68 65 01 06 01 01 03 04 09 14 84 80   ....he..........
         4425  +|   3952: 80 80 80 04 03 00 2e 00 00 00 10 06 30 64 61 62   ............0dab
         4426  +|   3968: 6c 65 01 06 01 01 05 04 15 84 80 80 80 80 03 03   le..............
         4427  +|   3984: 00 30 00 00 00 11 02 08 30 70 72 65 73 65 6e 74   .0......0present
         4428  +|   4000: 01 02 05 05 1b 84 80 80 80 80 02 03 00 3c 00 00   .............<..
         4429  +|   4016: 00 16 04 30 66 74 73 01 06 01 01 04 01 02 69 6e   ...0fts.......in
         4430  +|   4032: 01 06 01 01 04 0a 1a 84 80 80 80 80 01 03 00 3a   ...............:
         4431  +|   4048: 00 00 00 15 05 30 65 61 63 68 01 02 03 01 03 66   .....0each.....f
         4432  +|   4064: 6f 72 01 02 02 04 09 06 01 03 00 12 03 0b 0f 00   or..............
         4433  +|   4080: 00 08 8c 80 80 80 80 11 03 00 16 00 00 00 05 04   ................
         4434  +| page 3 offset 8192
         4435  +|      0: 0a 00 00 00 32 0e 4f 00 0f fa 0f f1 0f e9 0f e1   ....2.O.........
         4436  +|     16: 0f d8 0f d1 0f c9 0f c1 0f b9 0f b1 0f a9 0f a0   ................
         4437  +|     32: 0f 98 0f 90 0f 87 0f 80 0f 78 0f 71 0f 68 0f 5f   .........x.q.h._
         4438  +|     48: 0f 56 0f 4d 0f 41 0f 38 0f 2f 0f 26 0f 1d 0f 13   .V.M.A.8./.&....
         4439  +|     64: 0f 0a 0f 01 0e f7 0e ee 0e e6 0e dd 0e d6 0e cd   ................
         4440  +|     80: 0e c3 0e ba 0e b0 0e a8 0e 9f 0e 96 0e 8e 0e 85   ................
         4441  +|     96: 0e 7c 0e 73 0e 6a 0e 60 0e 58 0e 4f 00 00 00 00   .|.s.j.`.X.O....
         4442  +|   3648: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08   ................
         4443  +|   3664: 04 01 10 01 03 34 74 20 07 04 01 0e 01 03 34 1e   .....4t ......4.
         4444  +|   3680: 09 04 01 12 01 03 33 74 68 1c 08 04 01 10 01 03   ......3th.......
         4445  +|   3696: 33 6e 1a 08 04 01 10 01 03 32 77 18 08 04 01 10   3n.......2w.....
         4446  +|   3712: 01 03 32 74 16 08 04 01 10 01 03 32 6e 14 07 04   ..2t.......2n...
         4447  +|   3728: 01 0e 01 03 32 12 08 04 01 10 01 03 31 74 10 08   ....2.......1t..
         4448  +|   3744: 04 01 10 01 03 31 6e 0e 07 04 01 0e 01 03 31 0c   .....1n.......1.
         4449  +|   3760: 09 04 01 12 01 03 30 74 68 0a 08 04 01 10 01 03   ......0th.......
         4450  +|   3776: 30 74 08 09 04 01 12 01 03 30 6e 75 06 08 04 01   0t.......0nu....
         4451  +|   3792: 10 01 03 30 6e 04 06 04 01 0c 01 03 02 08 04 01   ...0n...........
         4452  +|   3808: 10 01 02 34 72 22 07 04 01 0e 01 02 34 20 08 04   ...4r.......4 ..
         4453  +|   3824: 01 10 01 02 33 72 1e 09 04 01 12 01 02 33 61 72   ....3r.......3ar
         4454  +|   3840: 1c 08 04 01 10 01 02 32 74 1a 08 04 01 10 01 02   .......2t.......
         4455  +|   3856: 32 69 18 09 04 01 12 01 02 32 61 72 16 08 04 01   2i.......2ar....
         4456  +|   3872: 10 01 02 31 74 14 08 04 01 10 01 02 31 6e 12 08   ...1t.......1n..
         4457  +|   3888: 04 01 10 01 02 31 62 10 08 04 01 10 01 02 31 32   .....1b.......12
         4458  +|   3904: 0e 0b 04 01 16 01 02 30 74 68 65 72 0c 08 04 01   .......0ther....
         4459  +|   3920: 10 01 02 30 74 0a 08 04 01 10 01 02 30 6e 08 08   ...0t.......0n..
         4460  +|   3936: 14 01 10 01 02 30 62 06 08 04 01 10 01 02 30 61   .....0b.......0a
         4461  +|   3952: 04 06 04 01 0c 01 02 02 07 04 09 10 01 34 74 22   .............4t.
         4462  +|   3968: 06 04 09 0e 01 34 20 08 04 09 12 01 33 74 65 1e   .....4 .....3te.
         4463  +|   3984: 07 04 09 10 01 33 70 1c 07 04 09 10 01 33 66 1a   .....3p......3f.
         4464  +|   4000: 08 04 09 12 01 32 74 68 18 07 04 09 10 01 32 74   .....2th......2t
         4465  +|   4016: 16 07 04 09 10 01 32 69 14 07 04 09 10 01 32 66   ......2i......2f
         4466  +|   4032: 12 07 04 09 10 01 31 74 10 07 04 09 10 01 31 69   ......1t......1i
         4467  +|   4048: 0e 06 04 09 0e 01 31 0c 08 04 09 12 01 30 74 65   ......1......0te
         4468  +|   4064: 0a 07 04 09 10 01 30 74 08 07 04 09 10 01 30 70   ......0t......0p
         4469  +|   4080: 06 08 04 09 12 01 30 66 74 04 05 04 09 0c 01 02   ......0ft.......
         4470  +| page 4 offset 12288
         4471  +|      0: 0d 00 00 00 03 0f eb 00 0f f9 0f f2 0f eb 00 00   ................
         4472  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 05 03 03 00 10   ................
         4473  +|   4080: 03 05 05 02 03 00 10 04 06 05 01 03 00 10 04 04   ................
         4474  +| page 5 offset 16384
         4475  +|      0: 0a 00 00 00 02 0f eb 00 0f eb 0f f4 00 00 00 00   ................
         4476  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 08 03 15 01 70   ...............p
         4477  +|   4080: 67 73 7a 18 0b 03 1b 01 76 65 72 73 69 6f 6e 04   gsz.....version.
         4478  +| page 6 offset 20480
         4479  +|      0: 0d 00 00 00 03 0f f2 00 0f fc 0f f7 0f f2 00 00   ................
         4480  +|   4080: 00 00 03 03 02 01 03 03 02 02 01 02 02 01 0c e9   ................
         4481  +| end crash-a6651222df1bd1.db
         4482  +}]} {}
         4483  +
         4484  +do_catchsql_test 36.1 {
         4485  +  INSERT INTO t1(b) VALUES(
         4486  +      x'78de3fa24af3733ca8769291a0fee3669f9fddefc5cba913e4225d4b6ce2b04f26b87fad3ee6f9b7d90a1ea62a169bf41e5d32707a6ca5c3d05e4bde05c9d89eaaa8c50e74333d2e9fcd7dfe95528a3a016aac1102d825c5cd70cf99d8a88e0ea7f798d4334386518b7ad359beb168b93aba059a2a3bd93112d65b44c12b9904ea786b204d80531cdf0504bf9b203dbe927061974caf7b9f30cbc3397b61f802e732012a6663d41c3607d6f1c0dbcfd489adac05ca500c0b04439d894cd93a840159225ef73b627e178b9f84b3ffe66cf22a963a8368813ff7961fc47f573211ccec95e0220dcbb3bf429f4a50ba54d7a53784ac51bfef346e6a');
         4487  +} {1 {database disk image is malformed}}
         4488  +
         4489  +#-------------------------------------------------------------------------
         4490  +reset_db
         4491  +do_test 37.0 {
         4492  +  sqlite3 db {}
         4493  +  db deserialize [decode_hexdb {
         4494  +| size 40960 pagesize 4096 filename null-memcmp-param-1..db
         4495  +| page 1 offset 0
         4496  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         4497  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 0a   .....@  ........
         4498  +|     32: 00 00 00 00 00 00 00 00 00 00 00 0d 00 00 00 04   ................
         4499  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         4500  +|     96: 00 00 00 00 0d 00 00 00 0d 0b 6e 00 0f a3 0f 4c   ..........n....L
         4501  +|    112: 0e e1 0e 81 0e 24 0d cc 0d 72 0d 1b 0c b0 0c 50   .....$...r.....P
         4502  +|    128: 0b f8 0b b3 0b 6e 00 00 00 00 00 00 00 00 00 00   .....n..........
         4503  +|   2912: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 43 0d   ..............C.
         4504  +|   2928: 06 17 11 11 08 75 74 61 62 6c 66 74 34 74 34 43   .....utablft4t4C
         4505  +|   2944: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41   REATE VIRTUAL TA
         4506  +|   2960: 42 4c 45 20 74 34 20 55 53 49 4e 47 20 66 74 73   BLE t4 USING fts
         4507  +|   2976: 35 76 6f 63 61 62 28 27 74 32 27 2c 20 27 72 6f   5vocab('t2', 'ro
         4508  +|   2992: 77 27 29 43 0c 06 17 11 11 08 75 74 61 62 6c 65   w')C......utable
         4509  +|   3008: 74 33 74 33 43 52 45 41 54 45 20 56 49 52 54 55   t3t3CREATE VIRTU
         4510  +|   3024: 41 4c 20 54 41 42 4c 45 20 74 33 20 55 53 49 4e   AL TABLE t3 USIN
         4511  +|   3040: 47 20 66 74 73 35 76 6f 63 61 62 28 27 74 31 27   G fts5vocab('t1'
         4512  +|   3056: 2c 20 27 72 6f 77 27 29 56 0b 06 17 1f 1f 01 7d   , 'row')V.......
         4513  +|   3072: 74 61 62 6c 65 74 32 5f 63 6f 6e 66 69 67 74 32   tablet2_configt2
         4514  +|   3088: 5f 63 6f 6e 66 69 67 0a 43 52 45 41 54 45 20 54   _config.CREATE T
         4515  +|   3104: 41 42 4c 45 20 27 74 32 5f 63 6f 6e 66 69 67 27   ABLE 't2_config'
         4516  +|   3120: 28 6b 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   (k PRIMARY KEY, 
         4517  +|   3136: 76 29 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44   v) WITHOUT ROWID
         4518  +|   3152: 5e 0a 07 17 21 21 01 81 07 74 61 62 6c 65 74 32   ^...!!...tablet2
         4519  +|   3168: 5f 63 6f 6e 74 65 6e 74 74 32 5f 63 6f 6e 74 65   _contentt2_conte
         4520  +|   3184: 6e 74 09 43 52 45 41 54 45 20 54 41 42 4c 45 20   nt.CREATE TABLE 
         4521  +|   3200: 27 74 32 5f 63 6f 6e 74 65 6e 74 27 28 69 64 20   't2_content'(id 
         4522  +|   3216: 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20   INTEGER PRIMARY 
         4523  +|   3232: 4b 45 59 2c 20 63 30 2c 20 63 31 2c 20 63 32 29   KEY, c0, c1, c2)
         4524  +|   3248: 69 09 07 17 19 19 01 81 2d 74 61 62 6c 65 74 32   i.......-tablet2
         4525  +|   3264: 5f 69 64 78 74 32 5f 69 64 78 08 43 52 45 41 54   _idxt2_idx.CREAT
         4526  +|   3280: 45 20 54 41 42 4c 45 20 27 74 32 5f 69 64 78 27   E TABLE 't2_idx'
         4527  +|   3296: 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20 70 67   (segid, term, pg
         4528  +|   3312: 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45 59 28   no, PRIMARY KEY(
         4529  +|   3328: 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20 57 49   segid, term)) WI
         4530  +|   3344: 54 48 4f 55 54 20 52 4f 57 49 44 55 08 07 17 1b   THOUT ROWIDU....
         4531  +|   3360: 1b 01 81 01 74 61 62 6c 65 74 32 5f 64 61 74 61   ....tablet2_data
         4532  +|   3376: 74 32 5f 64 61 74 61 07 43 52 45 41 54 45 20 54   t2_data.CREATE T
         4533  +|   3392: 41 42 4c 45 20 27 74 32 5f 64 61 74 61 27 28 69   ABLE 't2_data'(i
         4534  +|   3408: 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52   d INTEGER PRIMAR
         4535  +|   3424: 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f   Y KEY, block BLO
         4536  +|   3440: 42 29 58 07 07 17 11 11 08 81 1d 74 61 62 6c 65   B)X........table
         4537  +|   3456: 74 32 74 32 43 52 45 41 54 45 20 56 49 52 54 55   t2t2CREATE VIRTU
         4538  +|   3472: 41 4c 20 54 41 42 4c 45 20 74 32 20 55 53 49 4e   AL TABLE t2 USIN
         4539  +|   3488: 47 20 64 44 73 35 28 27 61 27 2c 5b 62 5d 2c 22   G dDs5('a',[b],.
         4540  +|   3504: 63 22 2c 64 65 74 61 69 6c 3d 6e 6f 6e 65 2c 63   c.,detail=none,c
         4541  +|   3520: 6f 6c 75 6d 6e 73 69 7a 65 3d 30 29 56 06 06 17   olumnsize=0)V...
         4542  +|   3536: 1f 1f 01 7d 74 61 62 6c 65 74 31 5f 63 6f 6e 66   ....tablet1_conf
         4543  +|   3552: 69 67 74 31 5f 63 6f 6e 66 69 67 06 43 52 45 41   igt1_config.CREA
         4544  +|   3568: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f 6e   TE TABLE 't1_con
         4545  +|   3584: 66 69 67 27 28 6b 20 50 52 49 4d 41 52 59 20 4b   fig'(k PRIMARY K
         4546  +|   3600: 45 59 2c 20 76 29 20 57 49 54 48 4f 55 54 20 52   EY, v) WITHOUT R
         4547  +|   3616: 4f 57 49 44 5b 05 07 17 21 21 01 81 01 74 61 62   OWID[...!!...tab
         4548  +|   3632: 6c 65 74 31 5f 64 6f 63 73 69 7a 65 74 31 5f 64   let1_docsizet1_d
         4549  +|   3648: 6f 63 73 69 7a 65 05 43 52 45 41 54 45 20 54 41   ocsize.CREATE TA
         4550  +|   3664: 42 4c 45 20 27 74 31 5f 64 6f 63 73 69 7a 65 27   BLE 't1_docsize'
         4551  +|   3680: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         4552  +|   3696: 41 52 59 20 4b 45 59 2c 20 73 7a 20 42 4c 4f 42   ARY KEY, sz BLOB
         4553  +|   3712: 29 5e 04 07 17 21 21 01 81 07 74 61 62 6c 65 74   )^...!!...tablet
         4554  +|   3728: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74   1_contentt1_cont
         4555  +|   3744: 65 6e 74 04 43 52 45 41 54 45 20 54 41 42 4c 45   ent.CREATE TABLE
         4556  +|   3760: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 69 64    't1_content'(id
         4557  +|   3776: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59    INTEGER PRIMARY
         4558  +|   3792: 20 4b 45 59 2c 20 63 30 2c 20 63 31 2c 20 63 32    KEY, c0, c1, c2
         4559  +|   3808: 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65 74   )i.......-tablet
         4560  +|   3824: 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45 41   1_idxt1_idx.CREA
         4561  +|   3840: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64 78   TE TABLE 't1_idx
         4562  +|   3856: 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20 70   '(segid, term, p
         4563  +|   3872: 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45 59   gno, PRIMARY KEY
         4564  +|   3888: 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20 57   (segid, term)) W
         4565  +|   3904: 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07 17   ITHOUT ROWIDU...
         4566  +|   3920: 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61 74   .....tablet1_dat
         4567  +|   3936: 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45 20   at1_data.CREATE 
         4568  +|   3952: 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27 28   TABLE 't1_data'(
         4569  +|   3968: 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41   id INTEGER PRIMA
         4570  +|   3984: 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c   RY KEY, block BL
         4571  +|   4000: 4f 42 29 5b 01 07 17 11 11 08 81 23 74 61 62 6c   OB)[.......#tabl
         4572  +|   4016: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         4573  +|   4032: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         4574  +|   4048: 4e 47 20 66 74 73 35 28 61 2c 62 20 75 6e 69 6e   NG fts5(a,b unin
         4575  +|   4064: 64 65 78 65 64 2c 63 2c 74 6f 6b 65 6e 69 7a 65   dexed,c,tokenize
         4576  +|   4080: 3d 22 70 6f 72 74 65 72 20 61 73 63 69 69 22 29   =.porter ascii.)
         4577  +| page 2 offset 4096
         4578  +|      0: 0d 0f 68 00 05 0f 13 00 0f e6 0f 13 0f a8 0f 7c   ..h............|
         4579  +|     16: 0f 2a 00 00 00 00 00 00 00 00 00 00 00 00 00 00   .*..............
         4580  +|   3856: 00 00 00 15 0a 03 00 30 00 00 00 00 01 03 03 00   .......0........
         4581  +|   3872: 03 01 01 01 02 01 01 03 01 01 37 8c 80 80 80 80   ..........7.....
         4582  +|   3888: 01 03 00 74 00 00 00 2e 02 30 61 03 02 02 01 01   ...t.....0a.....
         4583  +|   3904: 62 03 02 03 01 01 63 03 02 04 01 01 67 03 06 01   b.....c.....g...
         4584  +|   3920: 02 02 01 01 68 03 06 01 02 03 01 01 69 03 06 01   ....h.......i...
         4585  +|   3936: 02 04 04 06 06 06 08 08 0f ef 00 14 2a 00 00 00   ............*...
         4586  +|   3952: 00 01 02 02 00 02 01 01 01 02 01 01 25 88 80 80   ............%...
         4587  +|   3968: 80 80 01 03 00 50 00 00 00 1f 01 30 67 02 08 02   .....P.....0g...
         4588  +|   3984: 01 02 02 01 01 68 02 08 03 01 02 03 01 01 69 02   .....h........i.
         4589  +|   4000: 08 04 01 02 04 04 09 09 37 84 80 80 80 80 01 03   ........7.......
         4590  +|   4016: 00 74 00 00 00 2e 02 30 61 01 5a 02 01 01 62 01   .t.....0a.Z...b.
         4591  +|   4032: 02 03 01 01 63 01 02 04 01 01 67 01 06 01 02 02   ....c.....g.....
         4592  +|   4048: 01 01 68 01 06 01 02 03 01 01 69 01 06 01 02 04   ..h.......i.....
         4593  +|   4064: 04 06 06 06 08 08 07 01 03 00 14 03 09 00 09 00   ................
         4594  +|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         4595  +| page 3 offset 8192
         4596  +|      0: 0a 00 00 00 03 0f ec 00 0f fa 0f f3 0f ec 00 00   ................
         4597  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 06 04 01 0c   ................
         4598  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         4599  +| page 4 offset 12288
         4600  +|      0: 0d 00 00 00 03 0f be 00 0f ea 0f d4 0f be 00 00   ................
         4601  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 03   ................
         4602  +|   4032: 05 00 17 17 17 61 20 62 20 63 67 20 68 20 69 67   .....a b cg h ig
         4603  +|   4048: 20 68 20 69 14 02 05 00 17 17 17 67 20 68 20 69    h i.......g h i
         4604  +|   4064: 61 20 62 20 63 67 20 68 20 69 14 01 05 00 17 17   a b cg h i......
         4605  +|   4080: 17 61 20 62 20 63 64 20 65 20 66 67 20 68 20 69   .a b cd e fg h i
         4606  +| page 5 offset 16384
         4607  +|      0: 0d 00 00 00 03 0f e8 00 0f f8 0f f0 0f e8 00 00   ................
         4608  +|   4064: 00 00 00 00 00 00 00 00 06 03 03 00 12 03 00 03   ................
         4609  +|   4080: 06 02 03 00 12 03 00 03 06 01 03 00 12 03 00 03   ................
         4610  +| page 6 offset 20480
         4611  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         4612  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         4613  +| page 7 offset 24576
         4614  +|      0: 0d 00 00 00 03 0f 9e 00 0f e6 0f ef 0f 9e 00 00   ................
         4615  +|   3984: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 84   ..............A.
         4616  +|   4000: 80 80 80 80 01 04 00 81 06 00 00 00 34 02 30 61   ............4.0a
         4617  +|   4016: 01 01 01 01 01 62 01 01 01 01 01 63 01 01 01 01   .....b.....c....
         4618  +|   4032: 01 64 01 01 01 65 01 01 01 66 01 01 01 67 01 01   .d...e...f...g..
         4619  +|   4048: 01 01 01 68 01 01 01 01 01 69 01 01 01 04 06 06   ...h.....i......
         4620  +|   4064: 06 04 04 04 06 06 07 01 03 00 14 03 09 09 09 0f   ................
         4621  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         4622  +| page 8 offset 28672
         4623  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
         4624  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         4625  +| page 9 offset 32768
         4626  +|      0: 0d 00 00 00 03 0f be 00 0f ea 0f d4 0f be 00 00   ................
         4627  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 03   ................
         4628  +|   4032: 05 00 17 17 17 61 20 62 20 63 67 20 68 20 69 67   .....a b cg h ig
         4629  +|   4048: 20 68 20 69 14 02 05 00 17 17 17 67 20 68 20 69    h i.......g h i
         4630  +|   4064: 61 20 62 20 63 67 20 68 20 69 14 01 05 00 17 17   a b cg h i......
         4631  +|   4080: 17 61 20 62 20 63 64 20 65 20 66 67 20 68 30 69   .a b cd e fg h0i
         4632  +| page 10 offset 36864
         4633  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         4634  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         4635  +| end null-memcmp-param-1..db
         4636  +}]} {}
         4637  +
         4638  +do_catchsql_test 37.1 {
         4639  +  SELECT * FROM t3;
         4640  +} {1 {database disk image is malformed}}
         4641  +
         4642  +#-------------------------------------------------------------------------
         4643  +reset_db 
         4644  +do_execsql_test 37.0 {
         4645  +  CREATE VIRTUAL TABLE t1 USING fts5(b, c);
         4646  +  INSERT INTO t1 VALUES('a', 'b');
         4647  +  SELECT quote(block) FROM t1_data WHERE rowid=10;
         4648  +} {X'000000000101010001010101'}
         4649  +
         4650  +do_execsql_test 37.1 {
         4651  +  UPDATE t1_data SET block = X'FFFFFFFF0101010001010101' WHERE rowid = 10;
         4652  +  SELECT rowid FROM t1('a');
         4653  +} {1}
         4654  +
         4655  +#-------------------------------------------------------------------------
         4656  +reset_db 
         4657  +do_execsql_test 38.0 {
         4658  +  CREATE VIRTUAL TABLE t1 USING fts5(b, c);
         4659  +  INSERT INTO t1 VALUES('a', 'b');
         4660  +  INSERT INTO t1 VALUES('a', 'b');
         4661  +  SELECT quote(block) FROM t1_data WHERE rowid=1;
         4662  +} {X'020202'}
         4663  +
         4664  +do_execsql_test 38.1 {
         4665  +  SELECT * FROM t1('a b') ORDER BY rank;
         4666  +} {a b a b}
         4667  +
         4668  +do_execsql_test 38.2 {
         4669  +  UPDATE t1_data SET block = X'000202' WHERE rowid=1;
         4670  +}
         4671  +breakpoint
         4672  +do_catchsql_test 38.3 {
         4673  +  SELECT * FROM t1('a b') ORDER BY rank;
         4674  +} {1 {database disk image is malformed}}
         4675  +
         4676  +db close
         4677  +sqlite3 db test.db
         4678  +do_catchsql_test 38.4 {
         4679  +  SELECT * FROM t1('a b') ORDER BY rank;
         4680  +} {1 {database disk image is malformed}}
         4681  +
         4682  +#-------------------------------------------------------------------------
         4683  +reset_db
         4684  +do_test 38.0 {
         4685  +  sqlite3 db {}
         4686  +  db deserialize [decode_hexdb {
         4687  +| size 32768 pagesize 4096 filename crash-fd2a1313e5b5e9.db
         4688  +| page 1 offset 0
         4689  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         4690  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 08   .....@  ........
         4691  +|     32: 00 00 00 02 00 00 00 01 00 00 00 09 00 00 00 04   ................
         4692  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         4693  +|     96: 00 00 00 00 0d 0f c7 00 07 0d 92 00 0f 8d 0f 36   ...............6
         4694  +|    112: 0e cb 0e 6b 0e 0e 0d b6 0d 92 0d 92 00 00 00 00   ...k............
         4695  +|   3472: 00 00 22 08 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         4696  +|   3488: 32 74 32 08 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         4697  +|   3504: 20 74 32 28 78 29 56 07 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         4698  +|   3520: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         4699  +|   3536: 6f 6e 66 69 67 07 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         4700  +|   3552: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         4701  +|   3568: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         4702  +|   3584: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 06    WITHOUT ROWID[.
         4703  +|   3600: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         4704  +|   3616: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         4705  +|   3632: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         4706  +|   3648: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         4707  +|   3664: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         4708  +|   3680: 59 2c 20 73 7a 20 42 4c 4f 42 29 5e 05 07 17 21   Y, sz BLOB)^...!
         4709  +|   3696: 21 01 81 07 74 61 62 6c 65 b8 31 5f 63 6f 6e 74   !...table.1_cont
         4710  +|   3712: 65 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 05 43 52   entt1_content.CR
         4711  +|   3728: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63   EATE TABLE 't1_c
         4712  +|   3744: 6f 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47   ontent'(id INTEG
         4713  +|   3760: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   ER PRIMARY KEY, 
         4714  +|   3776: 63 30 2c 20 63 31 2c 20 63 32 29 69 04 07 17 19   c0, c1, c2)i....
         4715  +|   3792: 19 01 81 2d 74 61 62 6c 65 74 31 5f 69 64 78 74   ...-tablet1_idxt
         4716  +|   3808: 31 5f 69 64 78 04 43 52 45 41 54 45 20 54 41 42   1_idx.CREATE TAB
         4717  +|   3824: 4c 45 20 27 74 31 5f 69 64 78 27 28 73 65 67 69   LE 't1_idx'(segi
         4718  +|   3840: 64 2c 20 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50   d, term, pgno, P
         4719  +|   3856: 52 49 4d 41 52 59 20 4b 45 59 28 73 65 67 69 64   RIMARY KEY(segid
         4720  +|   3872: 2c 20 74 65 72 6d 29 29 20 57 49 54 48 4f 55 54   , term)) WITHOUT
         4721  +|   3888: 20 52 4f 57 49 44 55 03 07 17 1b 1b 01 81 01 74    ROWIDU........t
         4722  +|   3904: 61 62 6c 65 74 31 5f 64 61 74 61 74 31 5f 64 61   ablet1_datat1_da
         4723  +|   3920: 74 61 03 43 52 45 41 54 45 20 54 41 42 4c 45 20   ta.CREATE TABLE 
         4724  +|   3936: 27 74 31 5f 64 61 74 61 27 28 69 64 20 49 4e 54   't1_data'(id INT
         4725  +|   3952: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59   EGER PRIMARY KEY
         4726  +|   3968: 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 38 02 06   , block BLOB)8..
         4727  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         4728  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         4729  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35   LE t1 USING fts5
         4730  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00   (a,b,c)...9.....
         4731  +| page 3 offset 8192
         4732  +|      0: 0d 00 00 00 03 0c 94 00 0f e6 0f ef 0c 94 00 00   ................
         4733  +|   3216: 00 00 00 00 86 4a 84 80 80 80 80 01 04 00 8d 18   .....J..........
         4734  +|   3232: 00 00 03 2b 02 30 30 01 02 06 01 02 06 01 02 06   ...+.00.........
         4735  +|   3248: 1f 02 03 01 02 03 01 02 03 01 08 32 30 31 36 30   ...........20160
         4736  +|   3264: 36 30 39 01 02 07 01 02 07 01 02 07 01 01 34 01   609...........4.
         4737  +|   3280: 02 05 01 02 05 01 02 05 01 01 35 01 02 04 01 02   ..........5.....
         4738  +|   3296: 04 01 02 04 02 07 30 30 30 30 30 30 30 1c 02 04   ......0000000...
         4739  +|   3312: 01 02 04 01 02 04 01 06 62 69 6e 61 72 79 03 06   ........binary..
         4740  +|   3328: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         4741  +|   3344: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         4742  +|   3360: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02   ................
         4743  +|   3376: 03 06 01 02 02 03 06 01 02 02 01 08 63 6f 6d 70   ............comp
         4744  +|   3392: 69 6c 65 72 01 02 02 01 02 02 01 02 02 01 06 64   iler...........d
         4745  +|   3408: 62 73 74 61 74 07 02 03 01 02 03 01 02 03 02 04   bstat...........
         4746  +|   3424: 65 62 75 67 04 02 02 01 02 02 01 02 02 01 06 65   ebug...........e
         4747  +|   3440: 6e 61 62 6c 65 07 02 02 01 02 02 01 02 02 01 02   nable...........
         4748  +|   3456: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02   ................
         4749  +|   3472: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01   ................
         4750  +|   3488: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02   ................
         4751  +|   3504: 02 01 02 02 02 08 78 74 65 6e 73 69 6f 6e 1f 02   ......xtension..
         4752  +|   3520: 04 01 02 04 01 02 04 01 04 66 74 73 34 0a 02 03   .........fts4...
         4753  +|   3536: 01 02 03 01 02 03 04 01 35 0d 02 03 01 02 03 01   ........5.......
         4754  +|   3552: 02 03 01 03 67 63 63 01 02 03 01 02 03 01 02 03   ....gcc.........
         4755  +|   3568: 02 06 65 6f 70 6f 6c 79 10 02 03 01 02 03 01 02   ..eopoly........
         4756  +|   3584: 03 01 05 6a 73 6f 6e 31 13 02 03 01 02 03 01 02   ...json1........
         4757  +|   3600: 03 01 04 6c 6f 61 64 1f 02 03 01 02 03 01 02 03   ...load.........
         4758  +|   3616: 01 03 6d 61 78 1c 02 02 01 02 02 01 02 02 02 05   ..max...........
         4759  +|   3632: 65 6d 6f 72 79 1c 02 03 01 02 03 01 02 03 04 04   emory...........
         4760  +|   3648: 73 79 73 35 16 02 03 01 02 03 01 02 03 01 06 6e   sys5...........n
         4761  +|   3664: 6f 63 61 73 65 02 06 01 02 02 03 06 01 02 02 03   ocase...........
         4762  +|   3680: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06   ................
         4763  +|   3696: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         4764  +|   3712: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         4765  +|   3728: 02 01 04 6f 6d 69 74 1f 02 02 01 02 02 01 02 02   ...omit.........
         4766  +|   3744: 01 05 72 74 72 65 65 19 02 03 01 02 03 01 02 03   ..rtree.........
         4767  +|   3760: 04 02 69 6d 01 06 01 02 02 03 06 01 02 02 03 06   ..im............
         4768  +|   3776: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         4769  +|   3792: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         4770  +|   3808: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02   ................
         4771  +|   3824: 01 0a 74 68 72 65 61 64 73 61 66 65 22 02 02 01   ..threadsafe....
         4772  +|   3840: 02 02 01 02 01 01 04 76 74 61 62 07 02 04 01 02   .......vtab.....
         4773  +|   3856: 04 01 02 04 01 01 78 01 06 01 01 02 01 06 01 01   ......x.........
         4774  +|   3872: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02   ................
         4775  +|   3888: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01   ................
         4776  +|   3904: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06   ................
         4777  +|   3920: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01   ................
         4778  +|   3936: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01   ................
         4779  +|   3952: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02   ................
         4780  +|   3968: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01   ................
         4781  +|   3984: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06   ................
         4782  +|   4000: 01 01 02 01 06 01 01 02 01 06 01 ec 02 01 06 01   ................
         4783  +|   4016: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01   ................
         4784  +|   4032: 02 01 06 01 01 02 01 06 01 01 01 04 15 13 0c 0c   ................
         4785  +|   4048: 12 44 13 11 0f 47 13 0f 0c 0e 11 10 0f 0e 10 0f   .D...G..........
         4786  +|   4064: 44 0f 10 40 15 0f 07 01 03 00 14 24 5a 24 24 0f   D..@.......$Z$$.
         4787  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         4788  +| page 4 offset 12288
         4789  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
         4790  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         4791  +| page 5 offset 16384
         4792  +|      0: 0d 00 00 00 24 0c 0a 00 0f d8 0f af 0f 86 0f 74   ....$..........t
         4793  +|     16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5   .a.N./..........
         4794  +|     32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5   ...t.[.@.$......
         4795  +|     48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb   .......h.O.5....
         4796  +|     64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a   .......x.W.>.$..
         4797  +|   3072: 00 00 00 00 00 00 00 00 00 00 18 24 05 00 25 0f   ...........$..%.
         4798  +|   3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49   .THREADSAFE=0XBI
         4799  +|   3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41   NARY.#..%..THREA
         4800  +|   3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22   DSAFE=0XNOCASE..
         4801  +|   3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d   ..%..THREADSAFE=
         4802  +|   3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d   0XRTRIM.!..3..OM
         4803  +|   3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f   IT LOAD EXTENSIO
         4804  +|   3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f   NXBINARY. ..3..O
         4805  +|   3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49   MIT LOAD EXTENSI
         4806  +|   3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17   ONXNOCASE....3..
         4807  +|   3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53   OMIT LOAD EXTENS
         4808  +|   3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19   IONXRTRIM....3..
         4809  +|   3264: 4d 41 58 20 4d 45 4d 4f 52 59 60 35 30 30 30 30   MAX MEMORY`50000
         4810  +|   3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f   000XBINARY....3.
         4811  +|   3296: 19 4d 41 58 20 4d 44 4d 4f 52 59 3d 35 30 30 30   .MAX MDMORY=5000
         4812  +|   3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33   0000XNOCASE....3
         4813  +|   3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30   ..MAX MEMORY=500
         4814  +|   3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25   00000XRTRIM....%
         4815  +|   3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42   ..ENABLE RTREEXB
         4816  +|   3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         4817  +|   3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17   LE RTREEXNOCASE.
         4818  +|   3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52   ...%..ENABLE RTR
         4819  +|   3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45   EEXRTRIM....)..E
         4820  +|   3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49   NABLE MEMSYS5XBI
         4821  +|   3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         4822  +|   3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45   E MEMSYS5XNOCASE
         4823  +|   3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45   ....)..ENABLE ME
         4824  +|   3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25   MSYS5XRTRIM....%
         4825  +|   3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42   ..ENABLE JSON1XB
         4826  +|   3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         4827  +|   3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17   LE JSON1XNOCASE.
         4828  +|   3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f   ...%..ENABLE JSO
         4829  +|   3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45   N1XRTRIM....)..E
         4830  +|   3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49   NABLE GEOPOLYXBI
         4831  +|   3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         4832  +|   3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45   E GEOPOLYXNOCASE
         4833  +|   3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45   ....)..ENABLE GE
         4834  +|   3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23   OPOLYXRTRIM....#
         4835  +|   3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49   ..ENABLE FTS5XBI
         4836  +|   3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c   NARY....#..ENABL
         4837  +|   3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05   E FTS5XNOCASE...
         4838  +|   3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58   .#..ENABLE FTS5X
         4839  +|   3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42   RTRIM....#..ENAB
         4840  +|   3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b   LE FTS4XBINARY..
         4841  +|   3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34   ..#..ENABLE FTS4
         4842  +|   3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e   XNOCASE....#..EN
         4843  +|   3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e   ABLE FTS4XRTRIM.
         4844  +|   3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         4845  +|   3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e   TAT VTABXBINARY.
         4846  +|   3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         4847  +|   3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d   TAT VTABXNOCASE.
         4848  +|   3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         4849  +|   3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06   TAT VTABXRTRIM..
         4850  +|   3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52   .....DEBUGXBINAR
         4851  +|   3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f   Y.......DEBUGXNO
         4852  +|   3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47   CASE.......DEBUG
         4853  +|   3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d   XRTRIM'...C..COM
         4854  +|   3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20   PILER=gcc-5.4.0 
         4855  +|   4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27   20160609XBINARY'
         4856  +|   4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67   ...C..COMPILER=g
         4857  +|   4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30   cc-5.4.0 2016060
         4858  +|   4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43   9XNOCASE&...C..C
         4859  +|   4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e   OMPILER=gcc-5.4.
         4860  +|   4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d   0 20160609XRTRIM
         4861  +| page 6 offset 20480
         4862  +|      0: 0d 00 00 00 24 0e e0 00 0f f8 0f f0 0f e8 0f e0   ....$...........
         4863  +|     16: 0f d8 0f d0 0f c8 0f c0 0f b8 0f b0 0f a8 0f a0   ................
         4864  +|     32: 0f 98 0f 90 0f 88 0f 80 0f 78 0f 70 0f 68 0f 60   .........x.p.h.`
         4865  +|     48: 0f 58 0f 50 0f 48 0f 40 0f 38 0f 30 0f 28 0f 20   .X.P.H.@.8.0.(. 
         4866  +|     64: 0f 18 0f 10 0f 08 0f 00 0e f8 0e f0 0e e8 0e e0   ................
         4867  +|   3808: 06 24 03 00 12 02 01 01 06 23 03 00 12 02 01 01   .$.......#......
         4868  +|   3824: 06 22 03 00 12 02 01 01 06 21 03 00 12 03 01 01   .........!......
         4869  +|   3840: 06 20 03 00 12 03 01 01 06 1f 03 00 12 03 01 01   . ..............
         4870  +|   3856: 06 1e 03 00 12 03 01 01 06 1d 03 00 12 03 01 01   ................
         4871  +|   3872: 06 1c 03 00 12 03 01 01 16 1b 03 00 12 02 01 01   ................
         4872  +|   3888: 06 1a 03 00 12 02 01 01 06 19 03 00 12 02 01 01   ................
         4873  +|   3904: 06 18 03 00 12 02 01 01 06 17 03 00 12 02 01 01   ................
         4874  +|   3920: 06 16 03 00 12 02 01 01 06 15 03 00 12 02 01 01   ................
         4875  +|   3936: 06 14 03 00 12 02 01 01 06 13 03 00 12 02 01 01   ................
         4876  +|   3952: 06 12 03 00 12 02 01 01 06 11 03 00 12 02 01 01   ................
         4877  +|   3968: 06 10 03 00 12 02 01 01 06 0f 03 00 12 02 01 01   ................
         4878  +|   3984: 06 0e 03 00 12 02 01 01 06 0d 03 00 12 02 01 01   ................
         4879  +|   4000: 06 0c 03 00 12 02 01 01 06 0b 03 00 12 02 01 01   ................
         4880  +|   4016: 06 0a 03 00 12 02 01 01 05 09 03 00 12 03 01 01   ................
         4881  +|   4032: 06 08 03 00 12 03 01 01 06 07 03 10 12 03 01 01   ................
         4882  +|   4048: 06 06 03 00 12 01 01 01 06 05 03 00 12 01 01 01   ................
         4883  +|   4064: 06 04 03 00 12 01 01 01 06 03 03 00 12 05 f1 01   ................
         4884  +|   4080: 06 02 03 00 12 06 01 01 06 01 03 00 12 06 01 01   ................
         4885  +| page 7 offset 24576
         4886  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         4887  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         4888  +| page 8 offset 28672
         4889  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e9 0f d6 00 00   ................
         4890  +|   4048: 00 00 00 00 00 00 11 03 02 2b 69 6e 74 65 67 72   .........+integr
         4891  +|   4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity-check....reb
         4892  +|   4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   uild....optimize
         4893  +| end crash-fd2a1313e5b5e9.db
         4894  +}]} {}
         4895  +
         4896  +do_catchsql_test 38.1 {
         4897  +  UPDATE t1 SET b=quote(zeroblob(200)) WHERE t1 MATCH 'thread*';
         4898  +} {0 {}}
         4899  +
         4900  +#-------------------------------------------------------------------------
         4901  +reset_db
         4902  +do_test 39.0 {
         4903  +  sqlite3 db {}
         4904  +  db deserialize [decode_hexdb {
         4905  +.open --hexdb
         4906  +| size 24576 pagesize 4096 filename crash-e650fe95502908.db
         4907  +| page 1 offset 0
         4908  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         4909  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 06   .....@  ........
         4910  +|     32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04   ................
         4911  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         4912  +|     96: 00 00 00 00 0d 00 00 00 06 0e 0f 00 0f aa 0f 53   ...............S
         4913  +|    112: 0e e8 0e 8b 0e 33 0e 0f 00 00 00 00 00 00 00 00   .....3..........
         4914  +|   3584: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22   ................
         4915  +|   3600: 06 06 17 11 11 01 31 74 61 62 6c 65 62 62 62 62   ......1tablebbbb
         4916  +|   3616: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 62 62   .CREATE TABLE bb
         4917  +|   3632: 28 61 29 56 05 06 17 1f 1f 01 7d 74 61 62 6c 65   (a)V.......table
         4918  +|   3648: 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63 6f 6e 66   t1_configt1_conf
         4919  +|   3664: 69 67 05 43 52 45 41 54 45 20 54 41 42 4c 45 20   ig.CREATE TABLE 
         4920  +|   3680: 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b 20 50 52   't1_config'(k PR
         4921  +|   3696: 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 20 57 49   IMARY KEY, v) WI
         4922  +|   3712: 54 48 4f 55 54 20 52 4f 57 49 44 5b 04 07 17 21   THOUT ROWID[...!
         4923  +|   3728: 21 01 81 01 74 61 62 6c 65 74 31 5f 64 6f 63 73   !...tablet1_docs
         4924  +|   3744: 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65 04 43 52   izet1_docsize.CR
         4925  +|   3760: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 64   EATE TABLE 't1_d
         4926  +|   3776: 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 54 45 47   ocsize'(id INTEG
         4927  +|   3792: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   ER PRIMARY KEY, 
         4928  +|   3808: 73 7a 20 42 4c 4f 42 29 69 03 07 17 19 19 01 81   sz BLOB)i.......
         4929  +|   3824: 2d 74 61 62 6c 65 74 31 5f 69 64 78 74 31 5f 69   -tablet1_idxt1_i
         4930  +|   3840: 64 78 03 43 52 45 41 54 45 20 54 41 42 4c 45 20   dx.CREATE TABLE 
         4931  +|   3856: 27 74 31 5f 69 64 78 27 28 73 65 67 69 64 2c 20   't1_idx'(segid, 
         4932  +|   3872: 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50 52 49 4d   term, pgno, PRIM
         4933  +|   3888: 41 52 59 20 4b 45 59 28 73 65 67 69 64 2c 20 74   ARY KEY(segid, t
         4934  +|   3904: 65 72 6d 29 29 20 57 49 54 48 4f 55 54 20 52 4f   erm)) WITHOUT RO
         4935  +|   3920: 57 49 44 55 02 07 17 1b 1b 01 81 01 74 61 62 6c   WIDU........tabl
         4936  +|   3936: 65 74 31 5f 64 61 74 61 74 31 5f 64 61 74 61 02   et1_datat1_data.
         4937  +|   3952: 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 31   CREATE TABLE 't1
         4938  +|   3968: 5f 64 61 74 61 27 28 69 64 20 49 4e 54 45 47 45   _data'(id INTEGE
         4939  +|   3984: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62   R PRIMARY KEY, b
         4940  +|   4000: 6c 6f 63 6b 20 42 4c 4f 42 29 54 01 07 17 11 11   lock BLOB)T.....
         4941  +|   4016: 08 81 15 74 61 62 6c 65 74 31 74 31 43 52 45 41   ...tablet1t1CREA
         4942  +|   4032: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45   TE VIRTUAL TABLE
         4943  +|   4048: 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28 61    t1 USING fts5(a
         4944  +|   4064: 2c 62 2c 70 72 65 66 69 78 3d 22 32 2c 32 2c 33   ,b,prefix=.2,2,3
         4945  +|   4080: 2c 34 22 2c 20 63 6f 6e 74 65 6e 74 3d 22 22 29   ,4., content=..)
         4946  +| page 2 offset 4096
         4947  +|      0: 0d 0b 6a 00 37 09 4c 02 0f e7 09 4c 0f c6 0f a4   ..j.7.L....L....
         4948  +|     16: 0f 88 0f 6d 0f 4b 0f 2c 0f 0e 0e ec 0e cd 0e ad   ...m.K.,........
         4949  +|     32: 0e 8e 0e 6c 0e 4b 0e 29 0e 08 0d e6 0d c4 0d b5   ...l.K.)........
         4950  +|     48: 0d 97 0d 76 0d 54 0d 31 0d 15 0c f3 0c d3 0c b5   ...v.T.1........
         4951  +|     64: 0c 95 0c 73 0c 54 0c 32 0c 10 0b ee 0b cc 0b b0   ...s.T.2........
         4952  +|     80: 0b 8d 0b 7e 0b 48 0b 2e 0b 0b 0a ef 0a cc 0a ad   ...~.H..........
         4953  +|     96: 0a 8c 0a 6d 0a 4d 0a 2b 0a 0c 09 ec 09 ca 09 a8   ...m.M.+........
         4954  +|    112: 09 86 09 63 0f f1 00 00 00 00 00 00 00 00 00 00   ...c............
         4955  +|   2368: 00 00 00 00 00 00 00 00 00 00 00 00 15 0a 03 00   ................
         4956  +|   2384: 30 00 00 00 01 01 03 35 00 03 01 01 12 02 01 12   0......5........
         4957  +|   2400: 03 01 11 1c 8c 80 80 80 80 10 03 00 3e 00 00 00   ............>...
         4958  +|   2416: 17 01 05 05 34 74 61 62 6c 03 02 03 01 04 77 68   ....4tabl.....wh
         4959  +|   2432: 65 72 03 02 06 09 1b 8c 80 80 80 80 0f 03 00 3c   er.............<
         4960  +|   2448: 00 00 00 16 05 34 66 74 73 34 03 02 02 01 04 6e   .....4fts4.....n
         4961  +|   2464: 75 6d 62 03 06 01 04 09 1b 8c 80 80 80 80 0e 03   umb.............
         4962  +|   2480: 00 3c 00 00 00 16 04 33 74 68 65 03 06 01 01 04   .<.....3the.....
         4963  +|   2496: 01 03 77 68 65 03 02 04 04 0a 1b 8c 80 80 80 80   ..whe...........
         4964  +|   2512: 0d 03 00 3c 00 00 00 16 04 33 6e 75 6d 03 06 01   ...<.....3num...
         4965  +|   2528: 01 05 01 03 74 61 62 03 02 03 04 0a 19 8c 80 80   ....tab.........
         4966  +|   2544: 80 80 0c 03 00 38 00 00 00 14 03 32 77 68 03 02   .....8.....2wh..
         4967  +|   2560: 04 00 04 33 66 74 73 03 02 02 04 07 18 8c 80 80   ...3fts.........
         4968  +|   2576: 80 80 0b 03 00 36 00 00 00 13 03 32 74 61 03 02   .....6.....2ta..
         4969  +|   2592: 03 02 01 68 03 06 01 01 04 04 07 1b 8c 80 80 80   ...h............
         4970  +|   2608: 80 0a 03 00 3c 00 00 00 16 03 32 6e 75 03 06 01   ....<.....2nu...
         4971  +|   2624: 01 05 01 02 6f 66 03 06 01 01 06 04 09 19 8c 80   ....of..........
         4972  +|   2640: 80 80 80 09 03 00 38 00 00 00 14 03 32 66 74 03   ......8.....2ft.
         4973  +|   2656: 02 02 01 02 69 73 03 06 01 01 03 04 07 18 8c 80   ....is..........
         4974  +|   2672: 80 80 80 08 03 00 36 00 00 00 13 02 31 74 03 08   ......6.....1t..
         4975  +|   2688: 03 01 01 04 01 01 77 03 02 04 04 09 1a 8c 80 80   ......w.........
         4976  +|   2704: 80 80 07 03 00 3a ff 00 00 15 02 31 6e 03 08 01   .....:.....1n...
         4977  +|   2720: 01 02 05 01 01 6f 03 06 01 01 06 04 09 18 8c 80   .....o..........
         4978  +|   2736: 80 80 80 06 03 00 36 00 00 00 13 04 02 31 66 03   ......6......1f.
         4979  +|   2752: 02 02 01 01 69 03 06 01 01 03 05 06 1c 8c 80 80   ....i...........
         4980  +|   2768: 80 80 05 03 00 3e 00 00 00 17 04 30 74 68 65 03   .....>.....0the.
         4981  +|   2784: 06 00 f1 04 01 05 77 68 65 72 65 03 02 04 0a 15   ......where.....
         4982  +|   2800: 8c 80 80 80 80 04 03 00 30 00 00 00 11 01 01 06   ........0.......
         4983  +|   2816: 06 30 74 61 62 6c 65 03 02 03 07 1c 8c 80 80 80   .0table.........
         4984  +|   2832: 80 03 03 00 3e 00 00 00 17 07 30 6e 75 6d 62 65   ....>.....0numbe
         4985  +|   2848: 72 03 06 01 01 05 01 02 6f 66 03 06 04 0d 13 8c   r.......of......
         4986  +|   2864: 80 80 80 80 02 03 00 2c 00 00 00 0f 01 01 03 02   .......,........
         4987  +|   2880: 30 6e 03 06 01 01 02 07 1b 8c 80 80 80 80 01 03   0n..............
         4988  +|   2896: 00 3c 00 00 00 16 08 30 66 74 73 34 61 75 78 03   .<.....0fts4aux.
         4989  +|   2912: 02 02 01 02 69 73 03 06 04 0c 00 00 00 14 2a 00   ....is........*.
         4990  +|   2928: 00 00 01 01 02 24 00 02 01 01 12 02 01 12 08 88   .....$..........
         4991  +|   2944: 80 80 80 80 12 03 00 16 00 00 00 05 02 1c 88 80   ................
         4992  +|   2960: 80 80 80 11 03 00 3e 00 00 00 17 05 34 72 6f 77   ......>.....4row
         4993  +|   2976: 73 02 06 01 01 05 01 04 74 68 65 72 02 02 04 0b   s.......ther....
         4994  +|   2992: 15 88 80 80 80 80 10 03 00 30 00 00 00 11 02 01   .........0......
         4995  +|   3008: 01 07 05 34 62 65 74 77 02 02 04 08 1b 88 80 80   ...4betw........
         4996  +|   3024: 80 80 0f 03 00 3c 00 00 00 16 04 04 33 72 6f 77   .....<......3row
         4997  +|   3040: 02 06 01 01 05 01 03 74 68 65 02 08 05 0a 1b 88   .......the......
         4998  +|   3056: 80 80 80 80 0e 03 00 3c 00 00 00 16 01 01 02 04   .......<........
         4999  +|   3072: 33 61 72 65 02 02 03 01 03 62 65 74 02 02 07 08   3are.....bet....
         5000  +|   3088: 1b 88 80 80 80 80 0d 03 00 3c 00 00 00 16 03 32   .........<.....2
         5001  +|   3104: 74 68 02 08 02 01 01 07 00 04 33 61 6e 64 02 06   th........3and..
         5002  +|   3120: 04 0a 1b 88 80 80 80 80 0c 03 00 3c 00 00 00 16   ...........<....
         5003  +|   3136: 03 32 69 6e 02 06 01 01 06 01 02 72 6f 02 06 01   .2in.......ro...
         5004  +|   3152: 01 05 04 09 18 88 80 80 80 80 0b 03 00 36 00 00   .............6..
         5005  +|   3168: 00 13 02 03 32 61 72 02 02 03 01 02 62 65 02 02   ....2ar.....be..
         5006  +|   3184: 04 05 07 1b 88 80 80 80 80 0a 03 00 3c 00 00 00   ............<...
         5007  +|   3200: 16 02 31 74 02 08 02 01 01 07 00 03 32 61 6e 02   ..1t........2an.
         5008  +|   3216: 06 01 01 04 09 19 88 80 80 80 80 09 03 00 38 00   ..............8.
         5009  +|   3232: 00 00 14 02 31 6e 02 06 01 01 03 01 01 72 02 06   ....1n.......r..
         5010  +|   3248: 01 01 05 04 08 17 88 80 80 80 80 08 03 00 34 00   ..............4.
         5011  +|   3264: 00 00 12 02 31 62 02 02 04 01 01 69 02 06 01 01   ....1b.....i....
         5012  +|   3280: 06 04 06 19 88 80 80 80 80 07 03 00 38 00 00 00   ............8...
         5013  +|   3296: 14 04 02 31 32 02 02 05 01 01 61 02 08 03 01 01   ...12.....a.....
         5014  +|   3312: 02 05 06 1b 88 80 80 80 80 06 03 00 3c 00 00 00   ............<...
         5015  +|   3328: 16 06 30 74 68 65 72 65 02 02 02 00 02 31 31 02   ..0there.....11.
         5016  +|   3344: 06 01 01 04 0a 15 88 80 80 80 80 05 03 00 30 00   ..............0.
         5017  +|   3360: 00 00 11 01 01 05 04 30 74 68 65 02 06 01 01 07   .......0the.....
         5018  +|   3376: 07 1c 88 80 80 80 80 04 03 00 3e 00 00 00 17 01   ..........>.....
         5019  +|   3392: 01 06 02 30 6e 02 06 01 01 03 01 04 72 6f 77 73   ...0n.......rows
         5020  +|   3408: 02 06 07 08 1b 88 80 80 80 80 03 03 00 3c 00 00   .............<..
         5021  +|   3424: 00 16 08 30 62 65 74 77 65 65 6e 02 02 04 01 02   ...0between.....
         5022  +|   3440: 69 6e 02 06 04 0c 1a 88 80 80 80 80 02 03 00 3a   in.............:
         5023  +|   3456: 00 00 00 15 04 30 61 6e 64 02 06 01 01 02 02 02   .....0and.......
         5024  +|   3472: 72 65 02 02 03 04 0a 17 88 80 80 80 80 01 03 00   re..............
         5025  +|   3488: 34 00 00 00 12 02 30 31 02 06 01 01 04 01 01 32   4.....01.......2
         5026  +|   3504: 02 02 05 04 08 08 84 80 80 80 81 12 03 00 16 00   ................
         5027  +|   3520: 00 00 05 04 1b 84 61 80 80 80 11 03 00 3c 00 00   ......a......<..
         5028  +|   3536: 00 16 05 34 74 61 62 6c 01 06 01 01 05 02 03 65   ...4tabl.......e
         5029  +|   3552: 72 6d 01 02 04 0b 1b 84 80 80 80 80 10 03 00 3c   rm.............<
         5030  +|   3568: 00 00 00 16 05 34 65 61 63 68 01 02 03 01 04 70   .....4each.....p
         5031  +|   3584: 72 65 73 01 02 05 04 09 1a 84 80 80 80 80 0f 03   res.............
         5032  +|   3600: 00 3a 00 00 00 15 04 33 74 65 72 01 02 04 02 02   .:.....3ter.....
         5033  +|   3616: 68 65 01 06 01 01 03 04 08 1b 84 80 80 80 80 0e   he..............
         5034  +|   3632: 03 00 3c 00 00 00 16 04 33 70 72 65 01 02 05 01   ..<.....3pre....
         5035  +|   3648: 03 74 61 62 01 06 01 01 05 04 08 1a 84 80 80 80   .tab............
         5036  +|   3664: 80 0d 03 00 3a 00 00 00 15 04 33 66 6f 72 01 02   ....:.....3for..
         5037  +|   3680: 02 02 02 74 73 01 06 01 01 04 04 08 1b 84 80 80   ...ts...........
         5038  +|   3696: 80 80 0c 03 00 3c 00 00 00 16 03 32 74 68 01 06   .....<.....2th..
         5039  +|   3712: 01 01 03 00 04 33 65 61 63 01 02 03 04 09 18 84   .....3eac.......
         5040  +|   3728: 80 80 80 80 0b 03 00 36 00 00 00 13 03 32 74 71   .......6.....2tq
         5041  +|   3744: 01 06 01 01 05 02 01 65 01 02 04 04 09 19 84 80   .......e........
         5042  +|   3760: 80 80 80 0a 03 00 38 00 00 00 14 03 32 69 6e 01   ......8.....2in.
         5043  +|   3776: 06 01 01 02 01 02 70 72 01 02 05 0b 89 18 84 80   ......pr........
         5044  +|   3792: 80 80 80 09 03 00 36 00 00 00 13 03 32 66 6f 01   ......6.....2fo.
         5045  +|   3808: 02 02 02 01 74 01 06 01 01 04 04 07 1b 84 80 80   ....t...........
         5046  +|   3824: 80 80 08 03 00 3c 00 00 00 16 02 31 74 01 0a 04   .....<.....1t...
         5047  +|   3840: 01 01 03 04 00 03 32 65 61 01 02 03 04 0a 17 84   ......2ea.......
         5048  +|   3856: 80 80 80 80 07 03 00 34 00 00 00 12 02 31 69 01   .......4.....1i.
         5049  +|   3872: 06 01 01 02 01 01 70 01 02 05 04 08 18 84 80 80   ......p.........
         5050  +|   3888: 80 80 06 03 00 36 00 00 00 13 02 31 65 01 02 03   .....6.....1e...
         5051  +|   3904: 01 01 66 01 08 02 01 01 04 04 06 1b 84 80 80 80   ..f.............
         5052  +|   3920: 80 05 03 00 3c 00 00 00 16 05 30 74 65 72 6d 01   ....<.....0term.
         5053  +|   3936: 02 04 02 02 68 65 01 06 01 01 03 04 09 14 84 80   ....he..........
         5054  +|   3952: 80 80 80 04 03 00 2e 00 00 00 10 06 30 74 61 62   ............0tab
         5055  +|   3968: 6c 65 01 06 01 01 05 04 15 84 80 80 80 80 03 03   le..............
         5056  +|   3984: 00 30 00 00 00 11 02 08 30 70 72 65 73 65 6e 74   .0......0present
         5057  +|   4000: 01 02 05 05 1b 84 80 80 80 80 02 03 00 3c 00 00   .............<..
         5058  +|   4016: 00 16 04 30 66 74 73 01 06 01 01 04 01 02 69 6e   ...0fts.......in
         5059  +|   4032: 01 06 01 01 04 0a 1a 84 80 80 80 80 01 03 00 3a   ...............:
         5060  +|   4048: 00 00 00 15 05 30 65 61 63 f4 01 02 03 01 03 66   .....0eac......f
         5061  +|   4064: 6f 72 01 02 02 04 09 06 01 03 00 12 03 0b 0f 00   or..............
         5062  +|   4080: 00 08 8c 80 80 80 80 11 03 00 16 00 00 00 05 04   ................
         5063  +| page 3 offset 8192
         5064  +|      0: 0a 00 00 00 32 0e 4f 00 0f fa 0f f1 0f e9 0f e1   ....2.O.........
         5065  +|     16: 0f d8 0f d1 0f c9 0f c1 0f b9 0f b1 0f a9 0f a0   ................
         5066  +|     32: 0f 98 0f 90 0f 87 0f 80 0f 78 0f 71 0f 68 0f 5f   .........x.q.h._
         5067  +|     48: 0f 56 0f 4d 0f 41 0f 38 0f 2f 0f 26 0f 1d 0f 13   .V.M.A.8./.&....
         5068  +|     64: 0f 0a 0f 01 0e f7 0e ee 0e e6 0e dd 0e d6 0e cd   ................
         5069  +|     80: 0e c3 0e ba 0e b0 0e a8 0e 9f 0e 96 0e 8e 0e 85   ................
         5070  +|     96: 0e 7c 0e 73 0e 6a 0e 60 0e 58 0e 4f 00 00 00 00   .|.s.j.`.X.O....
         5071  +|   3648: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08   ................
         5072  +|   3664: 04 01 10 01 03 34 74 20 07 04 01 0e 01 03 34 1e   .....4t ......4.
         5073  +|   3680: 09 04 01 12 01 03 33 74 68 1c 08 04 01 10 01 03   ......3th.......
         5074  +|   3696: 33 6e 1a 08 04 01 10 01 03 32 77 18 08 04 01 10   3n.......2w.....
         5075  +|   3712: 01 03 32 74 16 08 04 01 10 01 03 32 6e 14 07 04   ..2t.......2n...
         5076  +|   3728: 01 0e 01 03 32 12 08 04 01 10 01 03 31 74 10 08   ....2.......1t..
         5077  +|   3744: 04 01 10 01 03 31 6e 0e 07 04 01 0e 01 03 31 0c   .....1n.......1.
         5078  +|   3760: 09 04 01 12 01 03 30 74 68 0a 08 04 01 10 01 03   ......0th.......
         5079  +|   3776: 30 74 08 09 04 01 12 01 03 30 6e 75 06 08 04 01   0t.......0nu....
         5080  +|   3792: 10 01 03 30 6e 04 06 04 01 0c 01 03 02 08 04 01   ...0n...........
         5081  +|   3808: 10 01 02 34 72 22 07 04 01 0e 01 02 34 20 08 04   ...4r.......4 ..
         5082  +|   3824: 01 10 01 02 33 72 1e 09 04 01 12 01 02 33 61 72   ....3r.......3ar
         5083  +|   3840: 1c 08 04 01 10 01 02 32 74 1a 08 04 01 10 b3 02   .......2t.......
         5084  +|   3856: 32 69 18 09 04 01 12 01 02 32 61 72 16 08 04 01   2i.......2ar....
         5085  +|   3872: 10 01 02 31 74 14 08 04 01 10 01 02 31 6e 12 08   ...1t.......1n..
         5086  +|   3888: 04 01 10 01 02 31 62 10 08 04 01 10 01 02 31 32   .....1b.......12
         5087  +|   3904: 0e 0b 04 01 16 01 02 30 74 68 65 72 0c 08 04 01   .......0ther....
         5088  +|   3920: 10 01 02 30 74 0a 08 04 01 10 01 02 30 6e 08 08   ...0t.......0n..
         5089  +|   3936: 04 01 10 01 02 30 62 06 08 04 01 10 01 02 30 61   .....0b.......0a
         5090  +|   3952: 05 06 04 01 0c 01 02 02 07 04 09 10 01 34 74 22   .............4t.
         5091  +|   3968: 06 04 09 0e 01 34 20 08 04 09 12 01 33 74 65 1e   .....4 .....3te.
         5092  +|   3984: 07 04 09 10 01 33 70 1c 07 04 09 10 01 33 66 1a   .....3p......3f.
         5093  +|   4000: 08 04 09 12 01 32 74 68 18 07 04 09 10 01 32 2d   .....2th......2-
         5094  +|   4016: 16 07 04 09 10 01 32 69 14 07 04 09 10 01 32 66   ......2i......2f
         5095  +|   4032: 12 07 04 09 10 01 31 74 10 07 04 09 10 01 31 69   ......1t......1i
         5096  +|   4048: 0e 06 04 09 0e 01 31 0c 08 04 09 12 01 30 74 65   ......1......0te
         5097  +|   4064: 0a 07 04 09 10 01 30 74 08 07 04 09 10 01 30 70   ......0t......0p
         5098  +|   4080: 06 08 04 09 12 01 30 66 74 04 05 04 09 0c 01 02   ......0ft.......
         5099  +| page 4 offset 12288
         5100  +|      0: 0d 00 00 00 03 0f eb 00 0f f9 0f f2 0f eb 00 00   ................
         5101  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 05 03 03 00 10   ................
         5102  +|   4080: 03 05 05 02 03 00 10 04 06 05 01 03 00 10 04 03   ................
         5103  +| page 5 offset 16384
         5104  +|      0: 0a 00 00 00 02 0f eb 00 0f eb 0f f4 00 00 00 00   ................
         5105  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 08 03 15 01 70   ...............p
         5106  +|   4080: 67 73 7a 18 0b 03 1b 01 76 65 72 73 69 6f 6e 04   gsz.....version.
         5107  +| page 6 offset 20480
         5108  +|      0: 0d 00 00 00 03 0f f2 00 0f fc 0f f7 0f f2 00 00   ................
         5109  +|   4080: 00 00 03 03 02 01 03 03 02 02 01 02 02 01 02 09   ................
         5110  +| end crash-e650fe95502908.db
         5111  +}]} {}
         5112  +
         5113  +do_execsql_test 39.1 {
         5114  +  SELECT rowid FROM t1('t*');
         5115  +} {1 2 3}
         5116  +
         5117  +#-------------------------------------------------------------------------
         5118  +reset_db
         5119  +do_test 40.0 {
         5120  +  sqlite3 db {}
         5121  +  db deserialize [decode_hexdb {
         5122  +.open --hexdb
         5123  +| size 24576 pagesize 4096 filename crash2.txt.db
         5124  +| page 1 offset 0
         5125  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         5126  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 06   .....@  ........
         5127  +|     32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04   ................
         5128  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         5129  +|     96: 00 00 00 00 0d 00 00 00 06 0e 0f 00 0f aa 0f 53   ...............S
         5130  +|    112: 0e e8 0e 8b 0e 33 0e 0f 00 00 00 00 00 00 00 00   .....3..........
         5131  +|   3584: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22   ................
         5132  +|   3600: 06 06 17 11 11 01 31 74 61 62 6c 65 62 62 62 62   ......1tablebbbb
         5133  +|   3616: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 62 62   .CREATE TABLE bb
         5134  +|   3632: 28 61 29 56 05 06 17 1f 1f 01 7d 74 61 52 6c 65   (a)V.......taRle
         5135  +|   3648: 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63 6f 6e 66   t1_configt1_conf
         5136  +|   3664: 69 67 05 43 52 45 41 54 45 20 54 41 42 4c 45 20   ig.CREATE TABLE 
         5137  +|   3680: 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b 20 50 52   't1_config'(k PR
         5138  +|   3696: 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 20 57 49   IMARY KEY, v) WI
         5139  +|   3712: 54 48 4f 55 54 20 52 4f 57 49 44 5b 04 07 17 21   THOUT ROWID[...!
         5140  +|   3728: 21 01 81 01 74 61 62 6c 65 74 31 5f 64 6f 73 73   !...tablet1_doss
         5141  +|   3744: 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65 04 43 52   izet1_docsize.CR
         5142  +|   3760: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 64   EATE TABLE 't1_d
         5143  +|   3776: 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 54 45 47   ocsize'(id INTEG
         5144  +|   3792: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   ER PRIMARY KEY, 
         5145  +|   3808: 73 7a 20 42 4c 4f 42 29 69 03 07 17 19 19 01 81   sz BLOB)i.......
         5146  +|   3824: 2d 74 61 62 6c 65 74 31 5f 69 64 78 74 31 5f 69   -tablet1_idxt1_i
         5147  +|   3840: 64 78 03 43 52 45 41 54 45 20 54 41 42 4c 45 20   dx.CREATE TABLE 
         5148  +|   3856: 27 74 31 5f 69 64 78 27 28 73 65 67 69 64 2c 20   't1_idx'(segid, 
         5149  +|   3872: 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50 52 49 4d   term, pgno, PRIM
         5150  +|   3888: 41 52 59 20 4b 45 59 28 73 65 67 69 64 2c 20 74   ARY KEY(segid, t
         5151  +|   3904: 65 72 6d 29 29 20 57 49 54 48 4f 55 54 20 52 4f   erm)) WITHOUT RO
         5152  +|   3920: 57 49 44 55 02 07 17 1b 1b 01 81 01 74 61 62 6c   WIDU........tabl
         5153  +|   3936: 65 74 31 5f 64 61 74 61 74 31 5f 64 61 74 61 02   et1_datat1_data.
         5154  +|   3952: 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 31   CREATE TABLE 't1
         5155  +|   3968: 5f 64 61 74 61 27 28 69 64 20 49 4e 54 45 47 45   _data'(id INTEGE
         5156  +|   3984: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62   R PRIMARY KEY, b
         5157  +|   4000: 6c 6f 63 6b 20 42 4c 4f 42 29 54 01 07 17 11 11   lock BLOB)T.....
         5158  +|   4016: 08 81 15 74 61 62 6c 65 74 31 74 31 43 52 45 41   ...tablet1t1CREA
         5159  +|   4032: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45   TE VIRTUAL TABLE
         5160  +|   4048: 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28 61    t1 USING fts5(a
         5161  +|   4064: 2c 62 2c 70 72 65 66 69 78 3d 22 31 2c 32 2c 33   ,b,prefix=.1,2,3
         5162  +|   4080: 2c 34 22 2c 20 63 6f 6e 74 65 6e 74 3d 22 22 29   ,4., content=..)
         5163  +| page 2 offset 4096
         5164  +|      0: 0d 0b 6a 00 37 09 4c 02 0f e7 09 4c 0f c6 0f a4   ..j.7.L....L....
         5165  +|     16: 0f 88 0f 6d 0f 4b 0f 2c 0f 0e 0e ec 0e cd 0e ad   ...m.K.,........
         5166  +|     32: 0e 8e 0e 6c 0e 4b 0e 29 0e 08 0d e6 0d c4 0d b5   ...l.K.)........
         5167  +|     48: 0d 97 0d 76 0d 54 0d 31 0d 15 0c f3 0c d3 0c b5   ...v.T.1........
         5168  +|     64: 0c 95 0c 73 0c 54 0c 32 0c 10 0b ee 0b cc 0b b0   ...s.T.2........
         5169  +|     80: 0b 8d 0b 7e 0b 48 0b 2e 0b 0b 0a ef 0a cc 0a ad   ...~.H..........
         5170  +|     96: 0a 8c 0a 6d 0a 4d 0a 2b 0a 0c 09 ec 09 ca 09 a8   ...m.M.+........
         5171  +|    112: 09 86 09 63 0f f1 00 00 00 00 00 00 00 00 00 00   ...c............
         5172  +|   2368: 00 00 00 00 00 00 00 00 00 00 00 00 15 0a 03 00   ................
         5173  +|   2384: 30 00 00 00 01 01 03 35 00 03 01 01 12 02 01 12   0......5........
         5174  +|   2400: 03 01 11 1c 8c 80 80 80 80 10 03 00 3e 00 00 00   ............>...
         5175  +|   2416: 17 01 05 05 34 74 61 62 6c 03 02 03 01 04 77 68   ....4tabl.....wh
         5176  +|   2432: 65 72 03 02 06 09 1b 8c 80 80 80 80 0f 03 00 3c   er.............<
         5177  +|   2448: 00 00 00 16 05 34 66 75 73 34 03 02 02 01 04 6e   .....4fus4.....n
         5178  +|   2464: 75 6d 62 03 06 01 04 09 1b 8c 80 80 80 80 0e 03   umb.............
         5179  +|   2480: 00 3c 00 00 00 16 04 33 74 68 65 03 06 01 01 04   .<.....3the.....
         5180  +|   2496: 01 03 77 68 65 03 02 04 04 0a 1b 8c 80 80 80 80   ..whe...........
         5181  +|   2512: 0d 03 00 3c 00 00 00 16 04 33 6e 75 6d 03 06 01   ...<.....3num...
         5182  +|   2528: 01 05 01 03 74 61 62 05 62 03 04 0a 19 8c 80 80   ....tab.b.......
         5183  +|   2544: 80 80 0c 03 00 38 00 00 00 14 03 32 77 68 03 02   .....8.....2wh..
         5184  +|   2560: 04 00 04 33 66 74 73 03 02 02 04 07 18 8c 80 80   ...3fts.........
         5185  +|   2576: 80 80 0b 03 00 36 00 00 00 13 03 32 74 61 03 02   .....6.....2ta..
         5186  +|   2592: 03 02 01 68 03 06 01 01 04 04 07 1b 8c 80 80 80   ...h............
         5187  +|   2608: 80 0a 03 00 3c 00 00 00 16 03 32 6e 75 03 06 01   ....<.....2nu...
         5188  +|   2624: 01 05 01 02 6f 66 03 06 01 01 06 04 09 19 8c 80   ....of..........
         5189  +|   2640: 80 80 80 09 03 00 38 00 00 00 14 03 32 66 74 03   ......8.....2ft.
         5190  +|   2656: 02 02 01 02 69 73 03 06 01 01 03 04 07 18 8c 80   ....is..........
         5191  +|   2672: 80 80 80 08 03 00 36 00 00 00 13 02 31 74 03 08   ......6.....1t..
         5192  +|   2688: 03 01 01 04 01 01 77 03 02 04 04 09 1a 8c 80 80   ......w.........
         5193  +|   2704: 80 80 07 03 00 3a ff 00 00 15 02 31 6e 03 08 01   .....:.....1n...
         5194  +|   2720: 01 02 05 01 01 6f 03 06 01 01 06 04 09 18 8c 80   .....o..........
         5195  +|   2736: 80 80 80 06 03 00 36 00 00 00 13 04 02 31 66 03   ......6......1f.
         5196  +|   2752: 02 02 01 01 69 03 06 01 01 03 05 06 1c 8c 80 80   ....i...........
         5197  +|   2768: 80 80 05 03 00 3e 00 00 00 17 04 30 74 68 65 03   .....>.....0the.
         5198  +|   2784: 06 01 01 04 01 05 77 68 65 72 65 03 02 04 0a 15   ......where.....
         5199  +|   2800: 8c 80 80 80 80 04 03 00 30 00 00 00 11 01 01 06   ........0.......
         5200  +|   2816: 06 30 74 61 62 6c 65 03 02 03 07 1c 8c 80 80 80   .0table.........
         5201  +|   2832: 80 03 03 00 3e 00 00 00 17 07 30 6e 75 6d 62 65   ....>.....0numbe
         5202  +|   2848: 72 03 06 01 01 05 01 02 6f 66 03 06 04 0d 13 8c   r.......of......
         5203  +|   2864: 80 80 80 80 02 03 00 2c 00 00 00 0f 01 01 03 02   .......,........
         5204  +|   2880: 30 6e 03 06 01 01 02 07 1b 8c 80 80 80 80 01 03   0n..............
         5205  +|   2896: 00 3c 00 00 00 16 08 30 66 74 73 34 61 75 78 03   .<.....0fts4aux.
         5206  +|   2912: 02 02 01 02 69 73 03 06 04 0c 00 00 00 14 2a 00   ....is........*.
         5207  +|   2928: 00 00 01 01 02 24 00 02 01 01 12 02 01 12 08 88   .....$..........
         5208  +|   2944: 80 80 80 80 11 03 00 16 00 00 00 05 02 1c 88 80   ................
         5209  +|   2960: 80 80 80 11 03 00 3e 00 00 00 17 05 34 72 6f 77   ......>.....4row
         5210  +|   2976: 73 02 06 01 01 05 01 04 74 68 65 72 02 02 04 0b   s.......ther....
         5211  +|   2992: 15 88 80 80 80 80 10 03 00 30 00 00 00 11 02 01   .........0......
         5212  +|   3008: 01 07 05 34 62 65 74 77 02 02 04 08 1b 88 80 80   ...4betw........
         5213  +|   3024: 80 80 0f 03 00 3c 00 00 00 16 04 04 33 72 6f 77   .....<......3row
         5214  +|   3040: 02 06 01 01 05 01 03 74 68 65 02 08 05 0a 1b 88   .......the......
         5215  +|   3056: 80 80 80 80 0e 03 00 3c 00 00 00 16 02 01 02 04   .......<........
         5216  +|   3072: 33 61 72 65 02 02 03 01 03 62 65 74 02 02 07 08   3are.....bet....
         5217  +|   3088: 1b 88 80 80 80 80 0d 03 00 3c 00 00 00 16 03 32   .........<.....2
         5218  +|   3104: 74 68 02 08 02 01 01 07 00 04 33 61 6e 64 02 06   th........3and..
         5219  +|   3120: 04 0a 1b 88 80 80 80 80 0c 03 00 3c 00 00 00 16   ...........<....
         5220  +|   3136: 03 32 69 6e 02 06 01 01 06 01 02 72 6f 02 06 01   .2in.......ro...
         5221  +|   3152: 01 05 04 09 18 88 80 80 80 80 0b 03 00 36 00 00   .............6..
         5222  +|   3168: 00 13 02 03 32 61 72 02 02 03 01 02 62 65 02 02   ....2ar.....be..
         5223  +|   3184: 04 05 07 1b 88 80 80 80 80 0a 03 00 3c 00 00 00   ............<...
         5224  +|   3200: 16 02 31 74 02 08 02 01 01 07 00 03 32 61 6e 02   ..1t........2an.
         5225  +|   3216: 06 01 01 04 09 19 88 80 80 80 80 09 03 00 38 00   ..............8.
         5226  +|   3232: 00 00 14 02 31 6e 02 06 01 01 03 01 01 72 02 06   ....1n.......r..
         5227  +|   3248: 01 01 05 04 08 17 88 80 80 80 80 08 03 00 34 00   ..............4.
         5228  +|   3264: 00 00 12 02 31 62 02 02 04 01 01 69 02 06 01 01   ....1b.....i....
         5229  +|   3280: 06 04 06 19 88 80 80 80 80 07 03 00 38 00 00 00   ............8...
         5230  +|   3296: 14 04 02 31 32 02 02 05 01 01 61 02 08 03 01 01   ...12.....a.....
         5231  +|   3312: 02 05 06 1b 88 80 80 80 80 06 03 00 3c 00 00 00   ............<...
         5232  +|   3328: 16 06 30 74 68 65 72 65 02 02 02 00 02 31 31 02   ..0there.....11.
         5233  +|   3344: 06 01 01 04 0a 15 88 80 80 80 80 05 03 00 30 00   ..............0.
         5234  +|   3360: 00 00 11 01 01 05 04 30 74 68 65 02 06 01 01 07   .......0the.....
         5235  +|   3376: 07 1c 88 80 80 80 80 04 03 00 3e 00 00 00 17 01   ..........>.....
         5236  +|   3392: 01 06 02 30 6e 02 06 01 01 03 01 04 72 6f 77 73   ...0n.......rows
         5237  +|   3408: 02 06 07 08 1b 88 80 80 80 80 03 03 00 3c 00 00   .............<..
         5238  +|   3424: 00 16 08 30 62 65 74 77 65 65 6e 02 02 04 01 02   ...0between.....
         5239  +|   3440: 69 6e 02 06 04 0c 1a 88 80 80 80 80 02 03 00 3a   in.............:
         5240  +|   3456: 00 00 00 15 04 30 61 6e 64 02 06 01 01 02 02 02   .....0and.......
         5241  +|   3472: 72 65 02 02 03 04 0a 17 88 80 80 80 80 01 03 00   re..............
         5242  +|   3488: 34 00 00 00 12 02 30 31 02 06 01 01 04 01 01 32   4.....01.......2
         5243  +|   3504: 02 02 06 04 08 08 84 80 80 80 80 12 03 00 16 00   ................
         5244  +|   3520: 00 00 05 04 1b 84 80 80 80 80 11 03 00 3c 00 00   .............<..
         5245  +|   3536: 00 16 05 34 74 61 62 6c 01 06 01 01 05 02 03 65   ...4tabl.......e
         5246  +|   3552: 72 6d 01 02 04 0b 1b 84 80 80 80 80 10 03 00 3c   rm.............<
         5247  +|   3568: 00 00 00 16 05 34 65 61 63 68 01 02 03 01 04 70   .....4each.....p
         5248  +|   3584: 72 65 73 01 02 05 04 09 1a 84 80 80 80 80 0f 03   res.............
         5249  +|   3600: 00 3a 00 00 00 15 04 33 74 65 72 01 02 04 02 02   .:.....3ter.....
         5250  +|   3616: 68 65 01 06 01 01 03 04 08 1b 84 80 80 80 80 0e   he..............
         5251  +|   3632: 03 00 3c 00 00 00 16 04 33 70 72 65 01 02 05 01   ..<.....3pre....
         5252  +|   3648: 03 74 61 62 01 06 01 01 05 04 08 1a 84 80 80 80   .tab............
         5253  +|   3664: 80 0d 03 00 3a 00 00 00 15 04 33 66 6f 72 01 02   ....:.....3for..
         5254  +|   3680: 02 02 02 74 73 01 06 01 01 04 04 08 1b 84 80 80   ...ts...........
         5255  +|   3696: 80 80 0c 03 00 3c 00 00 00 16 03 32 74 68 01 06   .....<.....2th..
         5256  +|   3712: 01 01 03 00 04 33 65 61 63 01 02 03 04 09 18 84   .....3eac.......
         5257  +|   3728: 80 80 80 80 0b 03 00 36 00 00 00 13 03 32 74 61   .......6.....2ta
         5258  +|   3744: 01 06 01 01 05 02 01 65 01 02 04 04 09 19 84 80   .......e........
         5259  +|   3760: 80 80 80 0a 03 00 38 00 00 00 14 03 32 69 6e 01   ......8.....2in.
         5260  +|   3776: 06 01 01 02 01 02 70 72 01 02 05 04 09 18 84 80   ......pr........
         5261  +|   3792: 80 80 80 09 03 00 36 00 00 00 13 03 32 66 6f 01   ......6.....2fo.
         5262  +|   3808: 02 02 02 01 74 01 06 01 01 04 04 07 1b 84 80 80   ....t...........
         5263  +|   3824: 80 80 08 03 00 3c 00 00 00 16 02 31 74 01 0a 04   .....<.....1t...
         5264  +|   3840: 01 01 03 04 00 03 32 65 61 01 02 03 04 0a 17 84   ......2ea.......
         5265  +|   3856: 80 80 80 80 07 03 00 34 00 00 00 12 02 31 69 01   .......4.....1i.
         5266  +|   3872: 06 01 01 02 01 01 70 01 02 05 04 08 18 84 80 80   ......p.........
         5267  +|   3888: 80 80 06 03 00 36 00 00 00 13 02 31 65 01 02 03   .....6.....1e...
         5268  +|   3904: 01 01 66 01 08 02 01 01 04 04 06 1b 84 80 80 80   ..f.............
         5269  +|   3920: 80 05 03 00 3c 00 00 00 16 05 30 74 65 72 6d 01   ....<.....0term.
         5270  +|   3936: 02 04 02 02 68 65 01 06 01 01 03 04 09 14 84 80   ....he..........
         5271  +|   3952: 80 80 80 04 03 00 2e 00 00 00 10 06 30 74 61 62   ............0tab
         5272  +|   3968: 6c 65 01 06 00 01 05 04 15 84 80 80 80 80 03 03   le..............
         5273  +|   3984: 00 30 00 00 00 11 02 08 30 70 72 65 73 65 6e 74   .0......0present
         5274  +|   4000: 01 02 05 05 1b 84 80 80 80 80 02 03 00 3c 00 00   .............<..
         5275  +|   4016: 00 16 04 30 66 74 73 01 06 01 01 04 01 02 69 6e   ...0fts.......in
         5276  +|   4032: 01 06 01 01 04 0a 1a 84 80 80 80 80 01 03 00 3a   ...............:
         5277  +|   4048: 00 00 00 15 05 30 65 61 63 68 01 02 03 01 03 66   .....0each.....f
         5278  +|   4064: 6f 72 01 02 02 04 09 06 01 03 00 12 03 0b 0f 00   or..............
         5279  +|   4080: 00 08 8c 80 80 80 80 11 03 00 16 00 00 00 05 04   ................
         5280  +| page 3 offset 8192
         5281  +|      0: 0a 00 00 00 32 0e 4f 00 0f fa 10 f1 0f e9 0f e1   ....2.O.........
         5282  +|     16: 0f d8 0f d1 0f c9 0f c1 0f b9 0f b1 0f a9 0f a0   ................
         5283  +|     32: 0f 98 0f 90 0f 87 0f 80 0f 78 0f 71 0f 68 0f 5f   .........x.q.h._
         5284  +|     48: bd 56 0f 4d 0f 41 0f 38 0f 2f 0f 26 0f 1d 0f 13   .V.M.A.8./.&....
         5285  +|     64: 0f 0a 0f 01 0e f7 0e ee 0e e6 0e dd 0e d6 0e cd   ................
         5286  +|     80: 0e c3 0e ba 0e b0 0e a8 0e 9f 0e 96 0e 8e 0e 85   ................
         5287  +|     96: 0e 7c 0e 73 0e 6a 0e 60 0e 58 0e 4f 00 00 00 00   .|.s.j.`.X.O....
         5288  +|   3648: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08   ................
         5289  +|   3664: 04 01 10 01 03 34 74 20 07 04 01 0e 01 03 34 1e   .....4t ......4.
         5290  +|   3680: 09 04 01 12 01 03 33 74 68 1c 08 04 01 10 01 03   ......3th.......
         5291  +|   3696: 33 6e 1a 08 04 01 10 01 03 32 77 18 08 04 01 10   3n.......2w.....
         5292  +|   3712: 01 03 32 74 16 08 04 01 10 01 03 32 6e 14 07 04   ..2t.......2n...
         5293  +|   3728: 01 0e 01 03 32 12 08 04 01 10 01 03 31 74 10 08   ....2.......1t..
         5294  +|   3744: 04 01 10 01 03 31 6e 0e 07 04 01 0e 01 03 31 0c   .....1n.......1.
         5295  +|   3760: 09 04 01 12 01 03 30 74 68 0a 08 04 01 10 01 03   ......0th.......
         5296  +|   3776: 30 74 08 09 04 01 12 01 03 30 6e 75 06 08 04 01   0t.......0nu....
         5297  +|   3792: 10 01 03 30 6e 04 06 04 01 0c 01 05 52 08 04 01   ...0n.......R...
         5298  +|   3808: 10 01 02 34 72 22 07 04 01 0e 01 02 34 20 08 04   ...4r.......4 ..
         5299  +|   3824: 01 10 01 02 33 72 1e 09 04 01 12 01 02 33 61 72   ....3r.......3ar
         5300  +|   3840: 1c 08 04 01 10 01 02 32 74 1a 08 04 01 10 b3 02   .......2t.......
         5301  +|   3856: 32 69 18 09 04 01 12 01 02 32 61 72 16 08 04 01   2i.......2ar....
         5302  +|   3872: 10 01 02 31 74 14 08 04 01 10 01 02 31 6e 12 08   ...1t.......1n..
         5303  +|   3888: 04 01 10 01 02 31 62 10 08 04 01 10 01 02 31 32   .....1b.......12
         5304  +|   3904: 0e 0b 04 01 16 01 02 30 74 68 65 72 0c 08 04 01   .......0ther....
         5305  +|   3920: 10 01 02 30 74 0a 08 04 01 10 01 02 30 6e 08 08   ...0t.......0n..
         5306  +|   3936: 04 01 10 01 02 30 62 06 08 04 01 10 01 02 30 61   .....0b.......0a
         5307  +|   3952: 04 06 04 01 0c 01 02 02 07 04 09 10 01 34 74 22   .............4t.
         5308  +|   3968: 06 04 09 0e 01 34 20 08 04 09 12 01 33 74 65 1e   .....4 .....3te.
         5309  +|   3984: 07 04 09 10 01 33 70 1c 07 04 09 10 01 33 66 1a   .....3p......3f.
         5310  +|   4000: 08 04 09 12 01 32 74 68 18 07 04 09 10 01 32 74   .....2th......2t
         5311  +|   4016: 16 07 04 09 10 01 32 69 14 07 04 09 10 01 32 66   ......2i......2f
         5312  +|   4032: 12 07 04 09 10 01 31 74 10 07 04 09 10 01 31 69   ......1t......1i
         5313  +|   4048: 0e 06 04 09 0e 01 31 0c 08 04 09 12 01 30 74 65   ......1......0te
         5314  +|   4064: 0a 07 04 09 10 01 30 74 08 07 04 09 10 01 30 70   ......0t......0p
         5315  +|   4080: 06 08 04 09 12 01 30 66 74 04 05 04 09 0c 01 02   ......0ft.......
         5316  +| page 4 offset 12288
         5317  +|      0: 0d 00 00 00 03 0f eb 00 0f f9 0f f2 0f eb 00 00   ................
         5318  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 05 03 03 00 10   ................
         5319  +|   4080: 03 05 05 02 03 00 10 04 06 05 01 03 00 10 04 04   ................
         5320  +| page 5 offset 16384
         5321  +|      0: 0a 00 00 00 02 0f eb 00 0f eb 0f f4 00 00 00 00   ................
         5322  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 08 03 15 01 70   ...............p
         5323  +|   4080: 67 73 7a 18 0b 03 1b 01 76 65 72 73 69 6f 6e 04   gsz.....version.
         5324  +| page 6 offset 20480
         5325  +|      0: 0d 00 00 00 03 0f f2 00 0f fc 0f f7 0f f2 00 00   ................
         5326  +|   4080: 00 00 03 03 02 01 03 03 02 02 01 02 02 01 02 09   ................
         5327  +| end crash2.txt.db
         5328  +}]} {}
         5329  +
         5330  +do_execsql_test 40.1 {
         5331  +  BEGIN;
         5332  +  INSERT INTO t1(b) VALUES(X'819192e578de3fa24af3733ca8769291a0fee3669f9fddefc5cba913e4225d4b6ce2b04f26b87fad3ee6f9b7d90a1ea62a169bf41e5d32707a6ca5c3d05e4bde05c9d89eaaa8c50e74333d2e9fcd7dfe95528a3a016aac1102d825c5cd70cf99d8a88e0ea7f798d4334386518b7ad359beb168b93aba059a2a3bd93112d65b44c12b9904ea786b204d80531cdf0504bf9b203dbe927061974caf7b9f30cbc3397b61f802e732012a6663d41c3607d6f1c0dbcfd489adac05ca500c0b04439d894cd93a840159225ef73b627e178b9f84b3ffe66cf22a963a8368813ff7961fc47f573211ccec95e0220dcbb3bf429f4a50ba54d7a53784ac51bf');
         5333  +  INSERT INTO t1(b) VALUES(X'c8ae0d0e7c3175946e62ba2b449511d4eb504079984a20f77969f62206c9f3d7ea25358ab705e6978627290b6d48db9032f815a06a79a4f4b809841a0942eed12954ed166f666111812a508abc3bec87958846edaec0a6fe14564bc0a4b78f1c35ebcacca6bae29cc37ae9b59d8a2d7593af1e47dda0ece2268a98d20febafad037964f139851f9a57f48b3706b01721769071991412044cd6006f1d72eb6eb4aa5ad77e378176db8c15575fbeee47165e38a7c6c5a557ac2dfe11813976eaf6741cf593a9e457053a3c34cddfbe605a6e25419f993de8374fafcd3636509d8416a51dc7bcc14cfca322ae343078f47e23522431c17d0da0c033');
         5334  +  INSERT INTO t1(b) VALUES(X'dc29a94e873a45a4243fce9b912aaefbadf1d0423e0345793874b356eeb500b92fb05284c1601fe9bad3143f72162f10242cec27c44ebf764c8fc9fb0824e32c4161472a4f914f579e0e8274f08ca1a02e59b9d8eec1f31061f9ccb9ed97a6f06534e991f7992c761489e6a7724f6e9c2b581e77487ded3a986d53c4419bbd3e9747cee300e670dd7294874c77e2ed48da68eaa6c3ec954a09ac410493d98e34d6686e54fbbe80696705f10e040c66093efb40746b33600685c94c664c7942835a9e954866121d5dcfb2cb12e92521ea3df175ee17072502dad9b9c1565f801b2179799011eb7418bfa00323e3157589e648ff7378be233c79b7');
         5335  +}
         5336  +
         5337  +do_catchsql_test 40.2 {
         5338  +  INSERT INTO t1(a,b) VALUES(1,11),(2,22),(3, true ),(4,44);
         5339  +} {1 {database disk image is malformed}}
         5340  +
         5341  +#-------------------------------------------------------------------------
         5342  +reset_db
         5343  +do_execsql_test 41.0 {
         5344  +  CREATE VIRTUAL TABLE t1 USING fts5(a,b,c);
         5345  +  REPLACE INTO t1_data VALUES(1,X'255a5824');
         5346  +  REPLACE INTO t1_data VALUES(10,X'0a1000000102020002010101020101');
         5347  +  INSERT INTO t1_data VALUES(137438953473,X'0000032b0030300102060102060102061f0203010203010203010832303136303630390102070102070102070101340102050102050102050101350102040102040102040207303030303030301c0204010204010204010662696e6272790306010202030601020203060102020306010202030601020203060102020306010202030601020203060102020306010202030601020203060102020108636f6d70696c657201020201020201020201066462737461740702030102030102030424656275670402020102020102020106656e61626c6507020201020201020201020201020201020201020201020201020201020201020201020201020201020201020201020201020201020201020201020201020202087874656e73696f6e1f02040102040102040104667473340a02030102030102030401350d020301020301020301036763630102030102030102030206656f706f6c7910020301020301020301056a736f6e3113020301020301020301046c6f61641f020301020301020301036d61781c02020102020102020205656d6f72791c020301020301020304047379733516020301020301020301066e6f6361736502060102020306010202030601020203060102020306010202030601020203060102020306010202030601020203060102020301b10202030601020201046f6d69741f0202010202010202010572747265651902030102030102030402696d010601020203060102020306010202030601020203060102020306010202030601020203060102020306010202030601020203060102020306010202010a746872656164736166652202020102020102020104767461620702040102040102040101780106010102010601010201060101020106010102010601010201060101020106010102010601010201060101020106010102010601010201060101020106010102010601010201060101020106010102010601010201060101020106010102010601010201060101020106010102010601010201060101020106010102010601010201060101020106010102010601010201060101020106010102010601010201060101020106010102010601010201060101020415130c0c124413110f47130f0c0e11100f0e100f440f1040150f');
         5348  +  INSERT INTO t1_data VALUES(274877906945,X'00000183023030250601011d010331c2ba250601010d0101342506010121010135250601011e02036ec2ba250601012b0101382506010112010161250a0101021a1d02016f2506010111010162250601013201026377250601012f010166250801011f0c010167250601012701026863250601010f02026473250601013002016b2506010133020175250601010e010169250601012c0204386ec2be250601012001016a250601010401056bc2b2cebc250601010901016c25060101150203cebc71250601011301036dd18a250601010c01016f25060101260102706425060101240101712506010122010173250a010116040d02016f2506010134010175250801011b14020161250601010b010376c2aa25060101100202d7ac250601010601017725060101030201752506010114010179250a0101190e050202357a250601010701017a250601012e0102c2aa250801011c100201b3250601010a0202ba6225060101310203be656625060101080103c5a77425060101050102de8e250601011704080a08080a080a080809090809090808080b080c080a0a0809080a0809080a0908080a09080a08090a0a');
         5349  +  INSERT INTO t1_idx VALUES(1,X'',2);
         5350  +  INSERT INTO t1_idx VALUES(2,X'',2);
         5351  +}
         5352  +
         5353  +do_catchsql_test 41.1 {
         5354  +  INSERT INTO t1(t1) VALUES('optimize');
         5355  +} {1 {database disk image is malformed}}
         5356  +
         5357  +do_catchsql_test 41.2 {
         5358  +  INSERT INTO t1(t1) VALUES('integrity-check');
         5359  +} {1 {database disk image is malformed}}
         5360  +
         5361  +#-------------------------------------------------------------------------
         5362  +reset_db
         5363  +do_test 42.0 {
         5364  +  sqlite3 db {}
         5365  +  db deserialize [decode_hexdb {
         5366  +| size 32768 pagesize 4096 filename 8cfba7fbb67e48de92c6.db
         5367  +| page 1 offset 0
         5368  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         5369  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 08   .....@  ........
         5370  +|     32: 00 00 00 02 00 00 00 01 00 00 00 09 00 00 00 04   ................
         5371  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         5372  +|     96: 00 00 00 00 0d 0f c7 00 07 0d 92 00 0f 8d 0f 36   ...............6
         5373  +|    112: 0e cb 0e 6b 0e 0e 0d b6 0d 92 0d 92 00 00 00 00   ...k............
         5374  +|   3472: 00 00 22 08 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         5375  +|   3488: 32 74 32 08 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         5376  +|   3504: 20 74 32 28 78 29 56 07 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
         5377  +|   3520: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         5378  +|   3536: 6f 6e 66 69 67 07 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         5379  +|   3552: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         5380  +|   3568: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         5381  +|   3584: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 06    WITHOUT ROWID[.
         5382  +|   3600: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         5383  +|   3616: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         5384  +|   3632: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         5385  +|   3648: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         5386  +|   3664: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         5387  +|   3680: 59 2c 20 73 7a 20 42 4c 4f 42 29 5e 05 07 17 21   Y, sz BLOB)^...!
         5388  +|   3696: 21 01 81 07 74 61 62 6c 65 74 31 5f 63 6f 6e 74   !...tablet1_cont
         5389  +|   3712: 65 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 05 43 52   entt1_content.CR
         5390  +|   3728: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63   EATE TABLE 't1_c
         5391  +|   3744: 6f 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47   ontent'(id INTEG
         5392  +|   3760: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   ER PRIMARY KEY, 
         5393  +|   3776: 63 30 2c 20 63 31 2c 20 63 32 29 69 04 07 17 19   c0, c1, c2)i....
         5394  +|   3792: 19 01 81 2d 74 61 62 6c 65 74 31 5f 69 64 78 74   ...-tablet1_idxt
         5395  +|   3808: 31 5f 69 64 78 04 43 52 45 41 54 45 20 54 41 42   1_idx.CREATE TAB
         5396  +|   3824: 4c 45 20 27 74 31 5f 69 64 78 27 28 73 65 67 69   LE 't1_idx'(segi
         5397  +|   3840: 64 2c 20 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50   d, term, pgno, P
         5398  +|   3856: 52 49 4d 41 52 59 20 4b 45 59 28 73 65 67 69 64   RIMARY KEY(segid
         5399  +|   3872: 2c 20 74 65 72 6d 29 29 20 57 49 54 48 4f 55 54   , term)) WITHOUT
         5400  +|   3888: 20 52 4f 57 49 44 55 03 07 17 1b 1b 01 81 01 74    ROWIDU........t
         5401  +|   3904: 61 62 6c 65 74 31 5f 64 61 74 61 74 31 5f 64 61   ablet1_datat1_da
         5402  +|   3920: 74 61 03 43 52 45 41 54 45 20 54 41 42 4c 45 20   ta.CREATE TABLE 
         5403  +|   3936: 27 74 31 5f 64 61 74 61 27 28 69 64 20 49 4e 54   't1_data'(id INT
         5404  +|   3952: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59   EGER PRIMARY KEY
         5405  +|   3968: 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 38 02 06   , block BLOB)8..
         5406  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         5407  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         5408  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35   LE t1 USING fts5
         5409  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00   (a,b,c)...9.....
         5410  +| page 3 offset 8192
         5411  +|      0: 0d 00 00 00 03 0c 94 00 0f e6 0f ef 0c 94 00 00   ................
         5412  +|   3216: 00 00 00 00 86 4a 84 80 80 80 80 01 04 00 8d 18   .....J..........
         5413  +|   3232: 00 00 03 2b 02 30 30 01 02 06 01 02 06 01 02 06   ...+.00.........
         5414  +|   3248: 1f 02 03 01 02 03 01 02 03 01 08 32 30 31 36 30   ...........20160
         5415  +|   3264: 36 30 39 01 02 07 01 02 07 01 02 07 01 01 34 01   609...........4.
         5416  +|   3280: 02 05 01 02 05 01 02 05 01 01 35 01 02 04 01 02   ..........5.....
         5417  +|   3296: 04 01 02 04 02 07 30 30 30 30 30 30 30 1c 02 04   ......0000000...
         5418  +|   3312: 01 02 04 01 02 04 01 06 62 69 6e 62 72 79 03 06   ........binbry..
         5419  +|   3328: 01 02 02 03 06 01 02 02 03 06 01 02 01 03 06 01   ................
         5420  +|   3344: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         5421  +|   3360: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02   ................
         5422  +|   3376: 03 06 01 02 02 03 06 01 02 02 01 08 63 6f 6d 70   ............comp
         5423  +|   3392: 69 6c 65 72 01 02 02 01 02 02 01 02 02 01 06 64   iler...........d
         5424  +|   3408: 62 73 74 61 74 07 02 03 01 02 03 01 02 03 02 04   bstat...........
         5425  +|   3424: 65 62 75 67 04 02 02 01 02 02 01 02 02 01 06 65   ebug...........e
         5426  +|   3440: 6e 61 62 6c 65 07 02 02 01 02 02 01 02 02 01 02   nable...........
         5427  +|   3456: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02   ................
         5428  +|   3472: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01   ................
         5429  +|   3488: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02   ................
         5430  +|   3504: 02 01 02 02 02 08 78 74 65 6e 73 69 6f 6e 1f 02   ......xtension..
         5431  +|   3520: 04 01 02 04 01 02 04 01 04 66 74 73 34 0a 02 03   .........fts4...
         5432  +|   3536: 01 02 03 01 02 03 04 01 35 0d 02 03 01 02 03 01   ........5.......
         5433  +|   3552: 02 03 01 03 67 63 63 01 02 03 01 02 03 01 02 03   ....gcc.........
         5434  +|   3568: 02 06 65 6f 70 6f 6c 79 10 02 03 01 02 03 01 02   ..eopoly........
         5435  +|   3584: 03 01 05 6a 73 6f 6e 31 13 02 03 01 02 03 01 02   ...json1........
         5436  +|   3600: 03 01 04 6c 6f 61 64 1f 02 03 01 02 03 01 02 03   ...load.........
         5437  +|   3616: 01 03 6d 61 78 1c 02 02 01 02 02 01 02 02 02 05   ..max...........
         5438  +|   3632: 65 6d 6f 72 79 1c 02 03 01 02 03 01 02 03 04 04   emory...........
         5439  +|   3648: 73 79 73 35 16 02 03 01 02 03 01 02 03 01 06 6e   sys5...........n
         5440  +|   3664: 6f 63 61 73 65 02 06 01 02 02 03 06 01 02 02 03   ocase...........
         5441  +|   3680: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06   ................
         5442  +|   3696: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         5443  +|   3712: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         5444  +|   3728: 02 01 04 6f 6d 69 74 1f 02 02 01 02 02 01 02 02   ...omit.........
         5445  +|   3744: 01 05 72 74 72 65 65 19 02 03 01 02 03 01 02 03   ..rtree.........
         5446  +|   3760: 04 02 69 6d 01 06 01 02 02 03 06 01 02 02 03 06   ..im............
         5447  +|   3776: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         5448  +|   3792: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         5449  +|   3808: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02   ................
         5450  +|   3824: 01 0a 74 68 72 65 61 64 73 61 66 65 22 02 02 01   ..threadsafe....
         5451  +|   3840: 02 02 01 02 02 01 04 76 74 61 62 07 02 04 01 02   .......vtab.....
         5452  +|   3856: 04 01 02 04 01 01 78 01 06 01 01 02 01 06 01 01   ......x.........
         5453  +|   3872: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02   ................
         5454  +|   3888: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01   ................
         5455  +|   3904: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06   ................
         5456  +|   3920: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01   ................
         5457  +|   3936: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01   ................
         5458  +|   3952: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02   ................
         5459  +|   3968: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01   ................
         5460  +|   3984: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06   ................
         5461  +|   4000: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01   ................
         5462  +|   4016: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01   ................
         5463  +|   4032: 02 01 06 01 01 02 01 06 01 01 02 04 15 13 0c 0c   ................
         5464  +|   4048: 12 44 13 11 0f 47 13 0f 0c 0e 11 10 0f 0e 10 0f   .D...G..........
         5465  +|   4064: 44 0f 10 40 15 0f 07 01 03 00 14 24 5a 24 24 0f   D..@.......$Z$$.
         5466  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         5467  +| page 4 offset 12288
         5468  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
         5469  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0b 01 02   ................
         5470  +| page 5 offset 16384
         5471  +|      0: 0d 00 00 00 24 0c 0a 00 0f d8 0f af 0f 86 0f 74   ....$..........t
         5472  +|     16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5   .a.N./..........
         5473  +|     32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5   ...t.[.@.$......
         5474  +|     48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb   .......h.O.5....
         5475  +|     64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a   .......x.W.>.$..
         5476  +|   3072: 00 00 00 00 00 00 00 00 00 00 18 24 05 00 25 0f   ...........$..%.
         5477  +|   3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49   .THREADSAFE=0XBI
         5478  +|   3104: 4f 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41   OARY.#..%..THREA
         5479  +|   3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22   DSAFE=0XNOCASE..
         5480  +|   3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d   ..%..THREADSAFE=
         5481  +|   3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d   0XRTRIM.!..3..OM
         5482  +|   3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f   IT LOAD EXTENSIO
         5483  +|   3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f   NXBINARY. ..3..O
         5484  +|   3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49   MIT LOAD EXTENSI
         5485  +|   3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17   ONXNOCASE....3..
         5486  +|   3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53   OMIT LOAD EXTENS
         5487  +|   3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19   IONXRTRIM....3..
         5488  +|   3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30   MAX MEMORY=50000
         5489  +|   3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f   000XBINARY....3.
         5490  +|   3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30   .MAX MEMORY=5000
         5491  +|   3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33   0000XNOCASE....3
         5492  +|   3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30   ..MAX MEMORY=500
         5493  +|   3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25   00000XRTRIM....%
         5494  +|   3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42   ..ENABLE RTREEXB
         5495  +|   3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         5496  +|   3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17   LE RTREEXNOCASE.
         5497  +|   3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52   ...%..ENABLE RTR
         5498  +|   3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45   EEXRTRIM....)..E
         5499  +|   3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49   NABLE MEMSYS5XBI
         5500  +|   3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         5501  +|   3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45   E MEMSYS5XNOCASE
         5502  +|   3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45   ....)..ENABLE ME
         5503  +|   3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25   MSYS5XRTRIM....%
         5504  +|   3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42   ..ENABLE JSON1XB
         5505  +|   3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         5506  +|   3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17   LE JSON1XNOCASE.
         5507  +|   3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f   ...%..ENABLE JSO
         5508  +|   3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45   N1XRTRIM....)..E
         5509  +|   3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 57 42 49   NABLE GEOPOLYWBI
         5510  +|   3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         5511  +|   3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 42 41 53 45   E GEOPOLYXNOBASE
         5512  +|   3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45   ....)..ENABLE GE
         5513  +|   3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23   OPOLYXRTRIM....#
         5514  +|   3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49   ..ENABLE FTS5XBI
         5515  +|   3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c   NARY....#..ENABL
         5516  +|   3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05   E FTS5XNOCASE...
         5517  +|   3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58   .#..ENABLE FTS5X
         5518  +|   3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42   RTRIM....#..ENAB
         5519  +|   3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b   LE FTS4XBINARY..
         5520  +|   3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34   ..#..ENABLE FTS4
         5521  +|   3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e   XNOCASE....#..EN
         5522  +|   3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e   ABLE FTS4XRTRIM.
         5523  +|   3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         5524  +|   3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e   TAT VTABXBINARY.
         5525  +|   3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         5526  +|   3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d   TAT VTABXNOCASE.
         5527  +|   3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         5528  +|   3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06   TAT VTABXRTRIM..
         5529  +|   3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52   .....DEBUGXBINAR
         5530  +|   3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f   Y.......DEBUGXNO
         5531  +|   3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47   CASE.......DEBUG
         5532  +|   3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d   XRTRIM'...C..COM
         5533  +|   3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20   PILER=gcc-5.4.0 
         5534  +|   4000: 32 30 31 36 30 36 30 39 52 02 49 4e 41 52 59 27   20160609R.INARY'
         5535  +|   4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67   ...C..COMPILER=g
         5536  +|   4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30   cc-5.4.0 2016060
         5537  +|   4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43   9XNOCASE&...C..C
         5538  +|   4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e   OMPILER=gcc-5.4.
         5539  +|   4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d   0 20160609XRTRIM
         5540  +| page 6 offset 20480
         5541  +|      0: 0d 00 00 00 24 0e e0 00 0f f8 0f f0 0f e8 0f e0   ....$...........
         5542  +|     16: 0f d8 0f d0 0f c8 0f c0 0f b8 0f b0 0f a8 0f a0   ................
         5543  +|     32: 0f 98 0f 90 0f 88 0f 80 0f 78 0f 70 0f 68 0f 60   .........x.p.h.`
         5544  +|     48: 0f 58 0f 50 0f 48 0f 40 0f 38 0f 30 0f 28 0f 20   .X.P.H.@.8.0.(. 
         5545  +|     64: 0f 18 0f 10 0f 08 0f 00 0e f8 0e f0 0e e8 0e e0   ................
         5546  +|   3808: 06 24 03 00 12 02 01 01 06 23 03 00 12 02 01 01   .$.......#......
         5547  +|   3824: 06 22 03 00 12 02 01 01 06 21 03 00 12 03 01 01   .........!......
         5548  +|   3840: 06 20 03 00 12 03 01 01 06 1f 03 00 12 03 01 01   . ..............
         5549  +|   3856: 06 1e 03 00 12 03 01 01 06 1d 03 00 12 03 01 01   ................
         5550  +|   3872: 06 1c 03 00 12 03 01 01 06 1b 03 00 12 02 01 01   ................
         5551  +|   3888: 06 1a 03 00 12 02 01 01 06 19 03 00 12 02 01 01   ................
         5552  +|   3904: 06 18 03 00 12 02 01 01 06 17 03 00 12 02 01 01   ................
         5553  +|   3920: 06 16 03 00 12 02 01 01 06 15 03 00 12 02 01 01   ................
         5554  +|   3936: 06 14 03 00 12 02 01 01 06 13 03 00 12 02 01 01   ................
         5555  +|   3952: 06 12 03 00 12 02 01 01 06 11 03 00 12 02 01 01   ................
         5556  +|   3968: 06 10 03 00 12 02 01 01 06 0f 03 00 12 02 01 01   ................
         5557  +|   3984: 06 0e 03 00 12 02 01 01 06 0d 03 00 12 02 01 01   ................
         5558  +|   4000: 06 0c 03 00 12 02 01 01 06 0b 03 00 12 02 01 01   ................
         5559  +|   4016: 06 0a 03 00 12 02 01 01 06 09 03 00 12 03 01 01   ................
         5560  +|   4032: 06 08 03 00 12 03 01 01 06 07 03 00 12 03 01 01   ................
         5561  +|   4048: 06 06 03 00 12 01 01 01 06 05 03 00 12 01 01 01   ................
         5562  +|   4064: 06 04 03 00 12 01 01 01 06 03 03 00 12 06 01 01   ................
         5563  +|   4080: 06 02 03 00 12 06 01 01 06 01 03 00 12 06 01 01   ................
         5564  +| page 7 offset 24576
         5565  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         5566  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         5567  +| page 8 offset 28672
         5568  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e9 0f d6 00 00   ................
         5569  +|   4048: 00 00 00 00 00 00 11 03 02 2b 69 6e 74 65 67 72   .........+integr
         5570  +|   4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity-check....reb
         5571  +|   4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 5d 69 7a 65   uild....opti]ize
         5572  +| end 8cfba7fbb67e48de92c6.db
         5573  +}]} {}
         5574  +
         5575  +do_catchsql_test 42.1 {
         5576  +  INSERT INTO t1(t1) VALUES('integrity-check');
         5577  +} {1 {database disk image is malformed}}
         5578  +
         5579  +#-------------------------------------------------------------------------
         5580  +reset_db
         5581  +do_test 43.0 {
         5582  +  sqlite3 db {}
         5583  +  db deserialize [decode_hexdb {
         5584  +| size 24576 pagesize 4096 filename 89028ffd2c29b679e250.db
         5585  +| page 1 offset 0
         5586  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         5587  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 06   .....@  ........
         5588  +|     32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04   ................
         5589  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         5590  +|     96: 00 00 00 00 0d 00 00 00 06 0e 0f 00 0f aa 0f 53   ...............S
         5591  +|    112: 0e e8 0e 8b 0e 33 0e 0f 00 00 00 00 00 00 00 00   .....3..........
         5592  +|   3584: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22   ................
         5593  +|   3600: 06 06 17 11 11 01 31 74 61 62 6c 65 62 62 62 62   ......1tablebbbb
         5594  +|   3616: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 62 62   .CREATE TABLE bb
         5595  +|   3632: 28 61 29 56 05 06 17 1f 1f 01 7d 74 61 62 6c 65   (a)V.......table
         5596  +|   3648: 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63 6f 6e 66   t1_configt1_conf
         5597  +|   3664: 69 67 05 43 52 45 41 54 45 20 54 41 42 4c 45 20   ig.CREATE TABLE 
         5598  +|   3680: 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b 20 50 52   't1_config'(k PR
         5599  +|   3696: 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 20 57 49   IMARY KEY, v) WI
         5600  +|   3712: 54 48 4f 55 54 20 52 4f 57 49 44 5b 04 07 17 21   THOUT ROWID[...!
         5601  +|   3728: 21 01 81 01 74 61 62 6c 65 74 31 5f 64 6f 63 73   !...tablet1_docs
         5602  +|   3744: 69 7a 65 74 31 5f 12 6f 63 73 69 7a 65 04 43 52   izet1_.ocsize.CR
         5603  +|   3760: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 64   EATE TABLE 't1_d
         5604  +|   3776: 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 54 45 47   ocsize'(id INTEG
         5605  +|   3792: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   ER PRIMARY KEY, 
         5606  +|   3808: 73 7a 20 42 4c 4f 42 29 69 03 07 17 19 19 01 81   sz BLOB)i.......
         5607  +|   3824: 2d 74 61 62 6c 65 74 31 5f 69 64 78 74 31 5f 69   -tablet1_idxt1_i
         5608  +|   3840: 64 78 03 43 52 45 41 54 45 20 54 41 42 4c 45 20   dx.CREATE TABLE 
         5609  +|   3856: 27 74 31 5f 69 64 78 27 28 73 65 67 69 64 2c 20   't1_idx'(segid, 
         5610  +|   3872: 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50 52 49 4d   term, pgno, PRIM
         5611  +|   3888: 41 52 59 20 4b 45 59 28 73 65 67 69 64 2c 20 74   ARY KEY(segid, t
         5612  +|   3904: 65 72 6d 29 29 20 57 49 54 48 4f 55 54 20 52 4f   erm)) WITHOUT RO
         5613  +|   3920: 57 49 44 55 02 07 17 1b 1b 01 81 01 74 61 62 6c   WIDU........tabl
         5614  +|   3936: 65 74 31 5f 64 61 74 61 74 31 5e 64 61 74 61 02   et1_datat1^data.
         5615  +|   3952: 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 31   CREATE TABLE 't1
         5616  +|   3968: 5f 64 61 74 61 27 28 69 64 20 49 4e 54 45 47 45   _data'(id INTEGE
         5617  +|   3984: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62   R PRIMARY KEY, b
         5618  +|   4000: 6c 6f 63 6b 20 42 4c 4f 42 29 54 01 07 17 11 11   lock BLOB)T.....
         5619  +|   4016: 08 81 15 74 61 62 6c 65 74 31 74 31 43 52 45 41   ...tablet1t1CREA
         5620  +|   4032: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45   TE VIRTUAL TABLE
         5621  +|   4048: 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28 61    t1 USING fts5(a
         5622  +|   4064: 2c 62 2c 70 72 65 66 69 78 3d 22 31 2c 32 2c 33   ,b,prefix=.1,2,3
         5623  +|   4080: 2c 34 22 2c 20 63 6f 6e 74 65 6e 74 3d 22 22 29   ,4., content=..)
         5624  +| page 2 offset 4096
         5625  +|      0: 0d 0b 6a 00 37 09 4c 02 0f e8 09 4c 0f c6 0f a4   ..j.7.L....L....
         5626  +|     16: 0f 88 0f 6d 0f 4b 0f 2c 0f 0e 0e ec 0e cd 0e ad   ...m.K.,........
         5627  +|     32: 0e 8e 0e 6c 0e 4b 0e 29 0e 08 0d e6 0d c4 0d b5   ...l.K.)........
         5628  +|     48: 0d 97 0d 76 0d 54 0d 31 0d 15 0c f3 0c d3 0c b5   ...v.T.1........
         5629  +|     64: 0c 95 0c 73 0c 54 0c 32 0c 10 0b ee 0b cc 0b b0   ...s.T.2........
         5630  +|     80: 0b 8d 0b 7e 0b 48 0b 2e 0b 0b 0a ef 0a cc 0a ad   ...~.H..........
         5631  +|     96: 0a 8c 0a 6d 0a 4d 0a 2b 0a 0c 09 ec 09 ca 09 a8   ...m.M.+........
         5632  +|    112: 09 86 09 63 0f f1 00 00 00 00 00 00 00 00 00 00   ...c............
         5633  +|   2368: 00 00 00 00 00 00 00 00 00 00 00 00 15 0a 03 00   ................
         5634  +|   2384: 30 00 00 00 01 01 03 35 00 03 00 01 12 02 01 12   0......5........
         5635  +|   2400: 03 01 11 1c 8c 80 80 80 80 10 03 00 3e 00 00 00   ............>...
         5636  +|   2416: 17 01 05 05 34 74 61 62 6c 03 02 03 01 04 77 68   ....4tabl.....wh
         5637  +|   2432: 65 72 03 02 06 09 1b 8c 80 80 80 80 0f 03 00 3c   er.............<
         5638  +|   2448: 00 00 00 16 05 34 66 74 73 34 03 02 02 01 04 6e   .....4fts4.....n
         5639  +|   2464: 75 6d 62 03 06 01 04 09 1b 8c 80 80 80 80 0e 03   umb.............
         5640  +|   2480: 00 3c 00 00 00 16 04 33 74 68 65 03 06 01 01 04   .<.....3the.....
         5641  +|   2496: 01 03 77 68 65 03 02 04 04 0a 1b 8c 80 80 80 80   ..whe...........
         5642  +|   2512: 0d 03 00 3c 00 00 00 16 04 33 6e 75 6d 03 06 01   ...<.....3num...
         5643  +|   2528: 01 05 01 03 74 61 62 03 02 03 04 0a 19 8c 80 80   ....tab.........
         5644  +|   2544: 80 80 0c 03 00 38 00 00 00 14 03 32 77 68 03 02   .....8.....2wh..
         5645  +|   2560: 04 00 04 33 66 74 73 03 02 02 04 07 18 8c 80 80   ...3fts.........
         5646  +|   2576: 80 80 0b 03 00 36 00 00 00 13 03 32 74 61 03 02   .....6.....2ta..
         5647  +|   2592: 03 02 01 68 03 06 01 01 04 04 07 1b 8c 80 80 80   ...h............
         5648  +|   2608: 80 0a 03 00 3c 00 00 00 16 03 32 6e 75 03 06 01   ....<.....2nu...
         5649  +|   2624: 01 05 01 02 6f 66 03 06 01 01 06 04 09 19 8c 80   ....of..........
         5650  +|   2640: 80 80 80 09 03 00 38 00 00 00 14 03 32 66 74 03   ......8.....2ft.
         5651  +|   2656: 02 02 01 02 69 73 03 06 01 01 03 04 07 18 8c 80   ....is..........
         5652  +|   2672: 80 80 80 08 03 00 36 94 00 00 13 02 31 74 03 08   ......6.....1t..
         5653  +|   2688: 03 01 01 04 01 01 77 03 02 04 04 09 1a 8c 80 80   ......w.........
         5654  +|   2704: 80 80 07 03 00 3a 00 00 00 15 02 31 6e 03 08 01   .....:.....1n...
         5655  +|   2720: 01 02 05 01 01 6f 03 06 01 01 06 04 09 18 8c 80   .....o..........
         5656  +|   2736: 80 80 80 06 03 00 36 00 00 00 13 04 02 31 66 03   ......6......1f.
         5657  +|   2752: 02 02 01 01 69 03 06 01 01 03 05 06 1c 8c 80 80   ....i...........
         5658  +|   2768: 80 80 05 03 00 3e 00 00 00 17 04 30 74 68 65 03   .....>.....0the.
         5659  +|   2784: 06 01 01 04 01 05 77 68 65 72 65 03 02 04 0a 15   ......where.....
         5660  +|   2800: 8c 80 80 80 80 04 03 00 30 00 00 00 11 01 01 06   ........0.......
         5661  +|   2816: 06 30 74 61 62 6c 65 03 02 03 07 1c 8c 80 80 80   .0table.........
         5662  +|   2832: 80 03 03 00 3e 00 00 00 17 07 30 6e 75 6d 62 65   ....>.....0numbe
         5663  +|   2848: 72 03 06 01 01 05 01 02 6f 66 03 06 04 0d 13 8c   r.......of......
         5664  +|   2864: 80 80 80 80 02 03 00 2c 00 00 00 0f 01 01 03 02   .......,........
         5665  +|   2880: 30 6e 03 06 01 01 02 07 1b 8c 80 80 80 80 01 03   0n..............
         5666  +|   2896: 00 3c 00 00 00 16 08 30 66 74 73 34 61 75 78 03   .<.....0fts4aux.
         5667  +|   2912: 02 02 01 02 69 73 04 06 04 0c 00 00 00 14 2a 00   ....is........*.
         5668  +|   2928: 00 00 01 01 02 24 00 02 01 01 12 02 01 12 08 88   .....$..........
         5669  +|   2944: 80 80 80 80 12 03 00 16 00 00 00 05 02 1c 88 80   ................
         5670  +|   2960: 80 80 80 11 03 00 3e 00 00 00 17 05 34 72 6f 77   ......>.....4row
         5671  +|   2976: 73 02 06 01 01 05 01 04 74 68 65 72 02 02 04 0b   s.......ther....
         5672  +|   2992: 15 88 80 80 80 80 10 03 00 30 00 00 00 11 02 01   .........0......
         5673  +|   3008: 01 07 05 34 62 65 74 77 02 02 04 08 1b 88 80 80   ...4betw........
         5674  +|   3024: 80 80 0f 03 00 3c 00 00 00 16 04 04 33 72 6f 77   .....<......3row
         5675  +|   3040: 02 06 01 01 05 01 03 74 68 65 02 08 05 0a 1b 88   .......the......
         5676  +|   3056: 80 80 80 80 0e 03 00 3c 00 00 00 16 01 01 02 04   .......<........
         5677  +|   3072: 33 61 72 65 02 02 03 01 03 62 65 74 02 02 07 08   3are.....bet....
         5678  +|   3088: 1b 88 80 80 80 80 0d 03 00 3c 00 00 00 16 03 32   .........<.....2
         5679  +|   3104: 74 68 02 08 02 01 01 07 00 04 33 61 6e 64 02 06   th........3and..
         5680  +|   3120: 04 0a 1b 88 80 80 80 80 0c 03 00 3c 00 00 00 16   ...........<....
         5681  +|   3136: 03 32 69 6e 02 06 01 01 06 01 02 72 6f 02 06 01   .2in.......ro...
         5682  +|   3152: 01 05 04 09 18 88 80 80 80 80 0b 03 00 36 00 00   .............6..
         5683  +|   3168: 00 13 02 03 32 61 72 02 02 03 01 02 62 65 02 02   ....2ar.....be..
         5684  +|   3184: 04 05 07 1b 88 80 80 80 80 0a 03 00 3c 00 00 00   ............<...
         5685  +|   3200: 16 02 31 74 02 08 02 01 01 07 00 03 32 61 6e 02   ..1t........2an.
         5686  +|   3216: 06 01 01 04 09 19 88 80 80 80 80 09 03 00 38 00   ..............8.
         5687  +|   3232: 00 00 14 02 31 6e 02 06 01 01 03 01 01 72 02 06   ....1n.......r..
         5688  +|   3248: 01 01 05 04 08 17 88 80 80 80 80 08 03 00 34 00   ..............4.
         5689  +|   3264: 00 00 12 02 31 62 02 02 04 01 01 69 02 06 01 01   ....1b.....i....
         5690  +|   3280: 06 04 06 19 88 80 80 80 80 07 03 00 38 00 00 00   ............8...
         5691  +|   3296: 14 04 02 31 32 02 02 05 01 01 61 02 08 03 01 01   ...12.....a.....
         5692  +|   3312: 02 05 06 1b 88 80 80 80 80 06 03 00 3c 00 00 00   ............<...
         5693  +|   3328: 16 06 30 74 68 65 72 65 02 02 02 00 02 31 31 02   ..0there.....11.
         5694  +|   3344: 06 01 01 04 0a 15 88 80 80 80 80 05 00 90 30 00   ..............0.
         5695  +|   3360: 00 00 11 01 01 05 04 30 74 68 65 02 06 01 01 07   .......0the.....
         5696  +|   3376: 07 1c 88 80 80 80 80 04 03 00 3e 00 00 00 17 01   ..........>.....
         5697  +|   3392: 01 06 02 30 6e 02 06 01 01 03 01 04 72 6f 77 73   ...0n.......rows
         5698  +|   3408: 02 06 07 08 1b 88 80 80 80 80 03 03 00 3c 00 00   .............<..
         5699  +|   3424: 00 16 07 30 62 65 74 77 65 65 6e 02 02 04 01 02   ...0between.....
         5700  +|   3440: 69 6e 02 06 04 0c 1a 88 80 80 80 80 02 03 00 3a   in.............:
         5701  +|   3456: 00 00 00 15 04 30 61 6e 64 02 06 01 01 02 02 02   .....0and.......
         5702  +|   3472: 72 65 02 02 03 04 0a 17 88 80 80 80 80 01 03 00   re..............
         5703  +|   3488: 34 00 00 00 12 02 30 31 02 06 01 01 04 01 01 32   4.....01.......2
         5704  +|   3504: 02 02 05 04 08 08 84 80 80 80 80 12 03 00 16 00   ................
         5705  +|   3520: 00 00 05 04 1b 84 80 80 80 80 11 03 00 3c 00 00   .............<..
         5706  +|   3536: 00 16 05 34 74 61 62 6c 01 06 01 01 05 02 03 65   ...4tabl.......e
         5707  +|   3552: 72 6d 01 02 04 0b 1b 84 80 80 80 80 10 03 00 3c   rm.............<
         5708  +|   3568: 00 00 00 16 05 34 65 61 63 68 01 02 03 01 04 70   .....4each.....p
         5709  +|   3584: 72 65 73 01 02 05 04 09 1a 84 80 80 80 80 0f 03   res.............
         5710  +|   3600: 00 3a 00 00 00 15 04 33 74 65 72 01 02 04 02 02   .:.....3ter.....
         5711  +|   3616: 68 65 01 06 01 01 03 04 08 1b 84 80 80 80 80 0e   he..............
         5712  +|   3632: 03 00 3c 00 00 00 16 04 33 70 72 65 01 02 05 01   ..<.....3pre....
         5713  +|   3648: 03 74 61 62 01 06 01 01 05 04 08 1a 84 80 80 80   .tab............
         5714  +|   3664: 80 0d 03 00 3a 00 00 00 15 04 33 66 6f 72 01 02   ....:.....3for..
         5715  +|   3680: 02 02 02 74 73 01 06 01 01 04 04 08 1b 84 80 80   ...ts...........
         5716  +|   3696: 80 80 0c 03 00 3c 00 00 00 16 03 32 74 68 01 06   .....<.....2th..
         5717  +|   3712: 01 01 03 00 04 33 65 61 63 01 02 03 04 09 18 84   .....3eac.......
         5718  +|   3728: 80 80 80 80 0b 03 00 36 00 00 00 13 03 32 74 61   .......6.....2ta
         5719  +|   3744: 01 06 01 01 05 02 01 65 01 02 04 04 09 19 84 80   .......e........
         5720  +|   3760: 80 80 80 0a 03 00 38 00 00 00 14 03 32 69 6e 01   ......8.....2in.
         5721  +|   3776: 06 01 01 02 01 02 70 72 01 02 05 04 09 18 84 80   ......pr........
         5722  +|   3792: 80 80 80 09 03 00 36 00 00 00 13 03 32 66 6f 01   ......6.....2fo.
         5723  +|   3808: 02 02 02 01 74 01 06 01 01 04 04 07 1b 84 80 80   ....t...........
         5724  +|   3824: 80 80 08 03 00 3c 00 00 00 16 02 31 74 01 0a 04   .....<.....1t...
         5725  +|   3840: 01 01 03 04 00 03 32 65 61 01 02 03 04 0a 17 84   ......2ea.......
         5726  +|   3856: 80 80 80 80 07 03 00 34 00 00 00 12 02 31 69 01   .......4.....1i.
         5727  +|   3872: 06 01 01 02 01 01 71 01 02 05 04 08 18 84 80 80   ......q.........
         5728  +|   3888: 80 80 06 03 00 36 00 00 00 13 02 31 65 01 02 03   .....6.....1e...
         5729  +|   3904: 01 01 66 01 08 02 01 01 04 04 06 1b 84 80 80 80   ..f.............
         5730  +|   3920: 80 05 03 00 3c 00 00 00 16 05 30 74 65 72 6d 01   ....<.....0term.
         5731  +|   3936: 02 04 02 02 68 65 01 06 01 01 03 04 09 14 84 80   ....he..........
         5732  +|   3952: 80 80 80 04 03 00 2e 00 00 00 10 06 30 74 61 62   ............0tab
         5733  +|   3968: 6c 65 01 06 01 01 05 04 15 84 80 80 80 80 03 03   le..............
         5734  +|   3984: 00 30 00 00 00 11 02 08 30 70 72 65 73 65 6e 74   .0......0present
         5735  +|   4000: 01 02 05 05 1b 84 80 80 80 80 02 03 00 3c 00 00   .............<..
         5736  +|   4016: 00 16 04 30 66 74 73 01 06 01 01 04 01 02 69 6e   ...0fts.......in
         5737  +|   4032: 01 06 01 01 04 0a 1a 84 80 80 80 80 01 03 00 3a   ...............:
         5738  +|   4048: 00 00 00 15 05 30 65 61 63 68 01 02 03 01 03 66   .....0each.....f
         5739  +|   4064: 6f 72 01 02 02 04 09 06 01 03 00 12 03 0b 0f 00   or..............
         5740  +|   4080: 00 08 8c 80 80 80 80 11 03 00 16 00 00 00 05 04   ................
         5741  +| page 3 offset 8192
         5742  +|      0: 0a 00 00 00 32 0e 4f 00 0f fa 0f f1 0f e9 0f e1   ....2.O.........
         5743  +|     16: 0f d8 0f d1 0f c9 0f c1 0f b9 0f b1 0f a9 0f a0   ................
         5744  +|     32: 0f 98 0f 91 0f 87 0f 80 0f 78 0f 71 0f 68 0f 5f   .........x.q.h._
         5745  +|     48: 0f 56 0f 4d 0f 41 0f 38 0f 2f 0f 26 0f 1d 0f 13   .V.M.A.8./.&....
         5746  +|     64: 0f 0a 0f 01 0e f7 0e ee 0e e6 0e dd 0e d6 0e cd   ................
         5747  +|     80: 0e c3 0e ba 0e b0 0e a8 0e 9f 0e 96 0e 8e 0e 85   ................
         5748  +|     96: 0e 7c 0e 73 0e 6a 0e 60 0e 58 0e 4f 00 00 00 00   .|.s.j.`.X.O....
         5749  +|   3648: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08   ................
         5750  +|   3664: 04 01 10 01 03 34 74 20 07 04 01 0e 01 03 34 1e   .....4t ......4.
         5751  +|   3680: 09 05 01 12 01 03 33 74 68 1c 08 04 01 10 01 03   ......3th.......
         5752  +|   3696: 33 6e 1a 08 04 01 10 01 03 32 77 18 08 04 01 10   3n.......2w.....
         5753  +|   3712: 01 03 32 74 16 08 04 01 10 01 03 32 6e 14 07 04   ..2t.......2n...
         5754  +|   3728: 01 0e 01 03 32 12 08 04 01 10 01 03 31 74 10 08   ....2.......1t..
         5755  +|   3744: 04 01 10 01 03 31 6e 0e 07 04 01 0e 01 03 31 0c   .....1n.......1.
         5756  +|   3760: 09 04 01 12 01 03 30 74 68 0a 08 04 01 10 01 03   ......0th.......
         5757  +|   3776: 30 74 08 09 04 01 12 01 03 30 6e 75 06 08 04 01   0t.......0nu....
         5758  +|   3792: 10 01 03 30 6e 04 06 04 01 0c 01 03 02 08 04 01   ...0n...........
         5759  +|   3808: 10 01 02 34 72 22 07 04 01 0e 01 02 34 20 08 04   ...4r.......4 ..
         5760  +|   3824: 01 10 01 02 33 72 1e 09 04 01 12 01 02 33 61 72   ....3r.......3ar
         5761  +|   3840: 1c 08 04 01 10 01 02 32 74 1a 08 04 01 10 02 02   .......2t.......
         5762  +|   3856: 32 69 18 09 04 01 12 01 02 32 61 72 16 08 04 01   2i.......2ar....
         5763  +|   3872: 10 01 02 31 74 14 08 04 01 10 01 02 31 6e 12 08   ...1t.......1n..
         5764  +|   3888: 04 01 10 01 02 31 62 10 08 04 01 10 01 02 31 32   .....1b.......12
         5765  +|   3904: 0e 0b 04 01 16 01 02 30 74 68 65 72 0c 08 04 01   .......0ther....
         5766  +|   3920: 10 01 02 30 74 0a 08 04 01 10 01 02 30 6e 08 08   ...0t.......0n..
         5767  +|   3936: 04 01 10 01 02 30 62 06 08 04 01 10 01 02 30 61   .....0b.......0a
         5768  +|   3952: 04 06 04 01 0c 01 02 02 07 04 09 10 01 34 74 22   .............4t.
         5769  +|   3968: 06 04 09 0e 01 34 20 08 04 09 12 01 33 74 65 1e   .....4 .....3te.
         5770  +|   3984: 07 04 09 10 01 33 70 1c 07 04 09 10 01 33 66 1a   .....3p......3f.
         5771  +|   4000: 08 04 09 12 01 32 74 68 18 07 04 09 10 01 32 74   .....2th......2t
         5772  +|   4016: 16 07 04 09 10 01 32 69 14 07 04 09 10 01 32 66   ......2i......2f
         5773  +|   4032: 12 07 04 09 10 01 31 74 10 07 04 09 10 01 31 69   ......1t......1i
         5774  +|   4048: 0e 06 04 09 0e 01 31 0c 08 04 09 12 01 30 74 65   ......1......0te
         5775  +|   4064: 0a 07 04 09 10 01 30 74 08 07 04 09 10 01 30 70   ......0t......0p
         5776  +|   4080: 06 08 04 09 12 01 30 66 74 04 05 04 09 0c 01 02   ......0ft.......
         5777  +| page 4 offset 12288
         5778  +|      0: 0d 00 00 00 03 0f eb 00 0f f9 0f f2 0f eb 00 00   ................
         5779  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 05 03 03 00 10   ................
         5780  +|   4080: 03 05 05 02 03 00 10 04 06 05 01 03 00 10 04 04   ................
         5781  +| page 5 offset 16384
         5782  +|      0: 0a 00 00 00 02 0f eb 00 0f eb 0f f4 00 00 00 00   ................
         5783  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 08 03 15 01 70   ...............p
         5784  +|   4080: 67 73 7a 18 0b 03 1b 01 76 65 72 73 69 6f 6e 04   gsz.....version.
         5785  +| page 6 offset 20480
         5786  +|      0: 0d 00 00 00 03 0f f2 00 0f fc 0f f7 0f f2 00 00   ................
         5787  +|   4080: 00 00 03 03 02 01 03 03 02 02 01 02 02 01 02 09   ................
         5788  +| end 89028ffd2c29b679e250.db
         5789  +}]} {}
         5790  +
         5791  +do_catchsql_test 43.1 {
         5792  +  INSERT INTO t1(t1) VALUES('optimize');
         5793  +} {1 {database disk image is malformed}}
         5794  +
         5795  +#-------------------------------------------------------------------------
         5796  +reset_db
         5797  +do_execsql_test 44.1 {
         5798  +  CREATE VIRTUAL TABLE t1 USING fts5(a,b unindexed,c,tokenize="porter ascii");
         5799  +  REPLACE INTO t1_data VALUES(1,X'03090009');
         5800  +  REPLACE INTO t1_data VALUES(10,X'000000000103030003010101020101030101');
         5801  +  INSERT INTO t1_data VALUES(137438953473,X'0000002e023061011202010162010203010163010204010167010601020201016801050102030101690106010204040606060808');
         5802  +  INSERT INTO t1_data VALUES(274877906945,X'0000001f02306702080201020201016802080301020301016a420804010204040909');
         5803  +  INSERT INTO t1_data VALUES(412316860417,X'0000002e023061030202010162030203010163030204010167030601020201016803060102030101690306010204040606060808');
         5804  +  INSERT INTO t1_idx VALUES(1,X'',2);
         5805  +  INSERT INTO t1_idx VALUES(2,X'',2);
         5806  +  INSERT INTO t1_idx VALUES(3,X'',2);
         5807  +  INSERT INTO t1_content VALUES(1,'a b c','d e f','g h i');
         5808  +  INSERT INTO t1_content VALUES(2,'g h i','a b c','g h i');
         5809  +  INSERT INTO t1_content VALUES(3,'a b c','g h i','g h i');
         5810  +  INSERT INTO t1_docsize VALUES(1,X'030003');
         5811  +  INSERT INTO t1_docsize VALUES(2,X'030003');
         5812  +  INSERT INTO t1_docsize VALUES(3,X'030003');
         5813  +} {}
         5814  +
         5815  +do_catchsql_test 44.2 {
         5816  +INSERT INTO t1(t1) VALUES('integrity-check');
         5817  +} {1 {database disk image is malformed}}
         5818  +
         5819  +do_catchsql_test 44.2 {
         5820  +  SELECT snippet(t1, -1, '.', '..', '', 2 ) FROM t1('g h') ORDER BY rank; 
         5821  +} {1 {database disk image is malformed}}
         5822  +
         5823  +#--------------------------------------------------------------------------
         5824  +reset_db
         5825  +do_test 45.0 {
         5826  +  sqlite3 db {}
         5827  +  db deserialize [decode_hexdb {
         5828  +| size 24576 pagesize 4096 filename crash-0b162c9e69b999.db
         5829  +| page 1 offset 0
         5830  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         5831  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 06   .....@  ........
         5832  +|     32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04   ................
         5833  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         5834  +|     96: 00 00 00 00 0d 00 00 00 06 0e 0f 00 0f aa 0f 53   ...............S
         5835  +|    112: 0e e8 0e 8b 0e 33 0e 0f 00 00 00 00 00 00 00 00   .....3..........
         5836  +|   3584: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 22   ................
         5837  +|   3600: 06 06 17 11 11 01 31 74 61 62 6c 65 62 62 62 62   ......1tablebbbb
         5838  +|   3616: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 62 62   .CREATE TABLE bb
         5839  +|   3632: 28 61 29 56 05 06 17 1f 1f 01 7d 74 61 52 6c 65   (a)V.......taRle
         5840  +|   3648: 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63 6f 6e 66   t1_configt1_conf
         5841  +|   3664: 69 67 05 43 52 45 41 54 45 20 54 41 42 4c 45 20   ig.CREATE TABLE 
         5842  +|   3680: 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b 20 50 52   't1_config'(k PR
         5843  +|   3696: 49 4d 41 52 59 20 4b 45 59 2c 20 76 29 20 57 49   IMARY KEY, v) WI
         5844  +|   3712: 54 48 4f 55 54 20 52 4f 57 49 44 5b 04 07 17 21   THOUT ROWID[...!
         5845  +|   3728: 21 01 81 01 74 61 62 6c 65 74 31 5f 64 6f 73 73   !...tablet1_doss
         5846  +|   3744: 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65 04 43 52   izet1_docsize.CR
         5847  +|   3760: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 64   EATE TABLE 't1_d
         5848  +|   3776: 6f 63 73 69 7a 65 27 28 69 64 20 49 4e 54 45 47   ocsize'(id INTEG
         5849  +|   3792: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   ER PRIMARY KEY, 
         5850  +|   3808: 73 7a 20 42 4c 4f 42 29 69 03 07 17 19 19 01 81   sz BLOB)i.......
         5851  +|   3824: 2d 74 61 62 6c 65 74 31 5f 69 64 78 74 31 5f 69   -tablet1_idxt1_i
         5852  +|   3840: 64 78 03 43 52 45 41 54 45 20 54 41 42 4c 45 20   dx.CREATE TABLE 
         5853  +|   3856: 27 74 31 5f 69 64 78 27 28 73 65 67 69 64 2c 20   't1_idx'(segid, 
         5854  +|   3872: 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50 52 49 4d   term, pgno, PRIM
         5855  +|   3888: 41 52 59 20 4b 45 59 28 73 65 67 69 64 2c 20 74   ARY KEY(segid, t
         5856  +|   3904: 65 72 6d 29 29 20 57 49 54 48 4f 55 54 20 52 4f   erm)) WITHOUT RO
         5857  +|   3920: 57 49 44 55 02 07 17 1b 1b 01 81 01 74 61 62 6c   WIDU........tabl
         5858  +|   3936: 65 74 31 5f 64 61 74 61 74 31 5f 64 61 74 61 02   et1_datat1_data.
         5859  +|   3952: 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74 31   CREATE TABLE 't1
         5860  +|   3968: 5f 64 61 74 61 27 28 69 64 20 49 4e 54 45 47 45   _data'(id INTEGE
         5861  +|   3984: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62   R PRIMARY KEY, b
         5862  +|   4000: 6c 6f 63 6b 20 42 4c 4f 42 29 54 01 07 17 11 11   lock BLOB)T.....
         5863  +|   4016: 08 81 15 74 61 62 6c 65 74 31 74 31 43 52 45 41   ...tablet1t1CREA
         5864  +|   4032: 54 45 20 56 49 52 54 55 41 4c 20 54 41 42 4c 45   TE VIRTUAL TABLE
         5865  +|   4048: 20 74 31 20 55 53 49 4e 47 20 66 74 73 35 28 61    t1 USING fts5(a
         5866  +|   4064: 2c 62 2c 70 72 65 66 69 78 3d 22 31 2c 32 2c 33   ,b,prefix=.1,2,3
         5867  +|   4080: 2c 34 22 2c 20 63 6f 6e 74 65 6e 74 3d 22 22 29   ,4., content=..)
         5868  +| page 2 offset 4096
         5869  +|      0: 0d 0b 6a 00 37 09 4c 02 0f e7 09 4c 0f c6 0f a4   ..j.7.L....L....
         5870  +|     16: 0f 88 0f 6d 0f 4b 0f 2c 0f 0e 0e ec 0e cd 0e ad   ...m.K.,........
         5871  +|     32: 0e 8e 0e 6c 0e 4b 0e 29 0e 08 0d e6 0d c4 0d b5   ...l.K.)........
         5872  +|     48: 0d 97 0d 76 0d 54 0d 31 0d 15 0c f3 0c d3 0c b5   ...v.T.1........
         5873  +|     64: 0c 95 0c 73 0c 54 0c 32 0c 10 0b ee 0b cc 0b b0   ...s.T.2........
         5874  +|     80: 0b 8d 0b 7e 0b 48 0b 2e 0b 0b 0a ef 0a cc 0a ad   ...~.H..........
         5875  +|     96: 0a 8c 0a 6d 0a 4d 0a 2b 0a 0c 09 ec 09 ca 09 a8   ...m.M.+........
         5876  +|    112: 09 86 09 63 0f f1 00 00 00 00 00 00 00 00 00 00   ...c............
         5877  +|   2368: 00 00 00 00 00 00 00 00 00 00 00 00 15 0a 03 00   ................
         5878  +|   2384: 30 00 00 00 01 01 03 35 00 03 01 01 12 02 01 12   0......5........
         5879  +|   2400: 03 01 11 1c 8c 80 80 80 80 10 03 00 3e 00 00 00   ............>...
         5880  +|   2416: 17 01 05 05 34 74 61 62 6c 03 02 03 01 04 77 68   ....4tabl.....wh
         5881  +|   2432: 65 72 03 02 06 09 1b 8c 80 80 80 80 0f 03 00 3c   er.............<
         5882  +|   2448: 00 00 00 16 05 34 66 75 73 34 03 02 02 01 04 6e   .....4fus4.....n
         5883  +|   2464: 75 6d 62 03 06 01 04 09 1b 8c 80 80 80 80 0e 03   umb.............
         5884  +|   2480: 00 3c 00 00 00 16 04 33 74 68 65 03 06 01 01 04   .<.....3the.....
         5885  +|   2496: 01 03 77 68 65 03 02 04 04 0a 1b 8c 80 80 80 80   ..whe...........
         5886  +|   2512: 0d 03 00 3c 00 00 00 16 04 33 6e 74 6d 03 06 01   ...<.....3ntm...
         5887  +|   2528: 01 05 01 03 74 61 62 05 62 03 04 0a 19 8c 80 80   ....tab.b.......
         5888  +|   2544: 80 80 0c 03 00 38 00 00 00 14 03 32 77 68 03 02   .....8.....2wh..
         5889  +|   2560: 04 00 04 33 66 74 73 03 02 02 04 07 18 8c 80 80   ...3fts.........
         5890  +|   2576: 80 80 0b 03 00 36 00 00 00 13 03 32 74 61 03 02   .....6.....2ta..
         5891  +|   2592: 03 02 01 68 03 06 01 01 04 04 07 1b 8c 80 80 80   ...h............
         5892  +|   2608: 80 0a 03 00 3c 00 00 00 16 03 32 6e 75 03 06 01   ....<.....2nu...
         5893  +|   2624: 01 05 01 02 6f 66 03 06 01 01 06 04 09 19 8c 80   ....of..........
         5894  +|   2640: 80 80 80 09 03 00 38 00 00 00 14 03 32 66 74 03   ......8.....2ft.
         5895  +|   2656: 02 02 01 02 69 73 03 06 01 01 03 04 07 18 8c 80   ....is..........
         5896  +|   2672: 80 80 80 08 03 00 36 00 00 00 13 02 31 74 03 08   ......6.....1t..
         5897  +|   2688: 03 01 01 04 01 01 77 03 02 04 04 09 1a 8c 80 80   ......w.........
         5898  +|   2704: 80 80 07 03 00 3a ff 00 00 15 02 31 6e 03 08 01   .....:.....1n...
         5899  +|   2720: 01 02 05 01 01 6f 03 06 01 01 06 04 09 18 8c 80   .....o..........
         5900  +|   2736: 80 80 80 06 03 00 36 00 00 00 13 04 02 31 66 03   ......6......1f.
         5901  +|   2752: 02 02 01 01 69 03 06 01 01 03 05 06 1c 8c 80 80   ....i...........
         5902  +|   2768: 80 80 05 03 00 3e 00 00 00 17 04 30 74 68 65 03   .....>.....0the.
         5903  +|   2784: 06 01 01 04 01 05 77 68 65 72 65 03 02 04 0a 15   ......where.....
         5904  +|   2800: 8c 80 80 80 80 04 03 00 30 00 00 00 11 01 01 06   ........0.......
         5905  +|   2816: 06 30 74 61 62 6c 65 03 02 03 07 1c 8c 80 80 80   .0table.........
         5906  +|   2832: 80 03 03 00 3e 00 00 00 17 07 30 6e 75 6d 62 65   ....>.....0numbe
         5907  +|   2848: 72 03 06 01 01 05 01 02 6f 66 03 06 04 0d 13 8c   r.......of......
         5908  +|   2864: 80 80 80 80 02 03 00 2c 00 00 00 0f 01 01 03 02   .......,........
         5909  +|   2880: 30 6e 03 06 01 01 02 07 1b 8c 80 80 80 80 01 03   0n..............
         5910  +|   2896: 00 3c 00 00 00 16 08 30 66 74 73 34 61 75 78 03   .<.....0fts4aux.
         5911  +|   2912: 02 02 01 02 69 73 03 06 04 0c 00 00 00 14 2a 00   ....is........*.
         5912  +|   2928: 00 00 01 01 02 24 00 02 01 01 12 02 01 12 08 88   .....$..........
         5913  +|   2944: 80 80 80 80 11 03 00 16 00 00 01 05 02 1c 88 80   ................
         5914  +|   2960: 80 80 80 11 03 00 3e 00 00 00 17 05 34 72 6f 77   ......>.....4row
         5915  +|   2976: 73 02 06 01 01 05 01 04 74 68 65 72 02 02 04 0b   s.......ther....
         5916  +|   2992: 15 88 80 80 80 80 10 03 00 30 00 00 00 11 02 01   .........0......
         5917  +|   3008: 01 07 05 34 62 65 74 77 02 02 04 08 1b 88 80 80   ...4betw........
         5918  +|   3024: 80 80 0f 03 00 3c 00 00 00 16 04 04 33 72 6f 77   .....<......3row
         5919  +|   3040: 02 06 01 01 05 01 03 74 68 65 02 08 05 0a 1b 88   .......the......
         5920  +|   3056: 80 80 80 80 0e 03 00 3c 00 00 00 16 02 01 02 04   .......<........
         5921  +|   3072: 33 61 72 65 02 02 03 01 03 62 65 74 02 02 07 08   3are.....bet....
         5922  +|   3088: 1b 88 80 80 80 80 0d 03 00 3c 00 00 00 16 03 32   .........<.....2
         5923  +|   3104: 74 68 02 08 02 01 01 07 00 04 33 61 6e 64 02 06   th........3and..
         5924  +|   3120: 04 0a 1b 88 80 80 80 80 0c 03 00 3c 00 00 00 16   ...........<....
         5925  +|   3136: 03 32 69 6e 02 06 01 01 06 01 02 72 6f 02 06 01   .2in.......ro...
         5926  +|   3152: 01 05 04 09 18 88 80 80 80 80 0b 03 00 36 00 00   .............6..
         5927  +|   3168: 00 13 02 03 32 61 72 02 02 03 01 02 62 65 02 02   ....2ar.....be..
         5928  +|   3184: 04 05 07 1b 88 80 80 80 80 0a 03 00 3c 00 00 00   ............<...
         5929  +|   3200: 16 02 31 74 02 08 02 01 01 07 00 03 32 61 6e 02   ..1t........2an.
         5930  +|   3216: 06 01 01 04 09 19 88 80 80 80 80 09 03 00 38 00   ..............8.
         5931  +|   3232: 00 00 14 02 31 6e 02 06 01 01 03 01 01 72 02 06   ....1n.......r..
         5932  +|   3248: 01 01 05 04 08 17 88 80 80 80 80 08 03 00 34 00   ..............4.
         5933  +|   3264: 00 00 12 02 31 62 02 02 04 01 01 69 02 06 01 01   ....1b.....i....
         5934  +|   3280: 06 04 06 19 88 80 80 80 80 07 03 00 38 00 00 00   ............8...
         5935  +|   3296: 14 04 02 31 32 02 02 05 01 01 61 02 08 03 01 01   ...12.....a.....
         5936  +|   3312: 02 05 06 1b 88 80 80 80 80 06 03 00 3c 00 00 00   ............<...
         5937  +|   3328: 16 06 30 74 68 65 72 65 02 02 02 00 02 31 31 02   ..0there.....11.
         5938  +|   3344: 06 01 01 04 0a 15 88 80 80 80 80 05 03 00 30 00   ..............0.
         5939  +|   3360: 00 00 11 01 01 05 04 30 74 68 65 02 06 01 01 07   .......0the.....
         5940  +|   3376: 07 1c 88 80 80 80 80 04 03 00 3e 00 00 00 17 01   ..........>.....
         5941  +|   3392: 01 06 02 30 6e 02 06 01 01 03 01 04 72 6f 77 73   ...0n.......rows
         5942  +|   3408: 02 06 07 08 1b 88 80 80 80 80 03 03 00 3c 00 00   .............<..
         5943  +|   3424: 00 16 08 30 62 65 74 77 65 65 6e 02 02 04 01 02   ...0between.....
         5944  +|   3440: 69 6e 02 06 04 0c 1a 88 80 80 80 80 02 03 00 3a   in.............:
         5945  +|   3456: 00 00 00 15 04 30 61 6e 64 02 06 01 01 02 02 02   .....0and.......
         5946  +|   3472: 72 65 02 02 03 04 0a 17 88 80 80 80 80 01 03 00   re..............
         5947  +|   3488: 34 00 00 00 12 02 30 31 02 06 01 01 04 01 01 32   4.....01.......2
         5948  +|   3504: 02 02 06 04 08 08 84 80 80 80 80 12 03 00 16 00   ................
         5949  +|   3520: 00 00 05 04 1b 84 80 80 80 80 11 03 00 3c 00 00   .............<..
         5950  +|   3536: 00 16 05 34 74 61 62 6c 01 06 01 01 05 02 03 65   ...4tabl.......e
         5951  +|   3552: 72 6d 01 02 04 0b 1b 84 80 80 80 80 10 03 00 3c   rm.............<
         5952  +|   3568: 00 00 00 16 05 34 65 61 63 68 01 02 03 01 04 70   .....4each.....p
         5953  +|   3584: 72 65 73 01 02 05 04 09 1a 84 80 80 80 80 0f 03   res.............
         5954  +|   3600: 00 3a 00 00 00 15 04 33 74 65 72 01 02 04 02 02   .:.....3ter.....
         5955  +|   3616: 68 65 01 06 01 01 03 04 08 1b 84 80 80 80 80 0e   he..............
         5956  +|   3632: 03 00 3c 00 00 00 16 04 33 70 72 65 01 02 05 01   ..<.....3pre....
         5957  +|   3648: 03 74 61 62 01 06 01 01 05 04 08 1a 84 80 80 80   .tab............
         5958  +|   3664: 80 0d 03 00 3a 00 00 00 15 04 33 66 6f 72 01 02   ....:.....3for..
         5959  +|   3680: 02 02 02 74 73 01 06 01 01 04 04 08 1b 84 80 80   ...ts...........
         5960  +|   3696: 80 80 0c 03 00 3c 00 00 00 16 03 32 74 68 01 06   .....<.....2th..
         5961  +|   3712: 01 01 03 00 04 33 65 61 63 01 02 03 04 09 18 84   .....3eac.......
         5962  +|   3728: 80 80 80 80 0b 03 00 36 00 00 00 13 03 32 74 61   .......6.....2ta
         5963  +|   3744: 01 06 01 01 05 02 01 65 01 02 04 04 09 19 84 80   .......e........
         5964  +|   3760: 80 80 80 0a 03 00 38 00 00 00 14 03 32 69 6e 01   ......8.....2in.
         5965  +|   3776: 06 01 01 02 01 02 70 72 01 02 05 04 09 18 84 80   ......pr........
         5966  +|   3792: 80 80 80 09 03 00 36 00 00 00 13 03 32 66 6f 01   ......6.....2fo.
         5967  +|   3808: 02 02 02 01 74 01 06 01 01 04 04 07 1b 84 80 80   ....t...........
         5968  +|   3824: 80 80 08 03 00 3c 00 00 00 16 02 31 74 01 0a 04   .....<.....1t...
         5969  +|   3840: 01 01 03 04 00 03 32 65 61 01 02 03 04 0a 17 84   ......2ea.......
         5970  +|   3856: 80 80 80 80 07 03 00 34 00 00 00 12 02 31 69 01   .......4.....1i.
         5971  +|   3872: 06 01 01 02 01 01 70 01 02 05 04 08 18 84 80 80   ......p.........
         5972  +|   3888: 80 80 06 03 00 36 00 00 00 13 02 31 65 01 02 03   .....6.....1e...
         5973  +|   3904: 01 01 66 01 08 02 01 01 04 04 06 1b 84 80 80 80   ..f.............
         5974  +|   3920: 80 05 03 00 3c 00 00 00 16 05 30 74 65 72 6d 01   ....<.....0term.
         5975  +|   3936: 02 04 02 02 68 65 01 06 01 01 03 04 09 14 84 80   ....he..........
         5976  +|   3952: 80 80 80 04 03 00 2e 00 00 00 10 06 30 74 61 62   ............0tab
         5977  +|   3968: 6c 65 01 06 00 01 05 04 15 84 80 80 80 80 03 03   le..............
         5978  +|   3984: 00 30 00 00 00 11 02 08 30 70 72 65 73 65 6e 74   .0......0present
         5979  +|   4000: 01 02 05 05 1b 84 80 80 80 80 02 03 00 3c 00 00   .............<..
         5980  +|   4016: 00 16 04 30 66 74 73 01 06 01 01 04 01 02 69 6e   ...0fts.......in
         5981  +|   4032: 01 06 01 01 04 0a 1a 84 80 80 80 80 01 03 00 3a   ...............:
         5982  +|   4048: 00 00 00 15 05 30 65 61 63 68 01 02 03 01 03 66   .....0each.....f
         5983  +|   4064: 6f 72 01 02 02 04 09 06 01 03 00 12 03 0b 0f 00   or..............
         5984  +|   4080: 00 08 8c 80 80 80 80 11 03 00 16 00 00 00 05 04   ................
         5985  +| page 3 offset 8192
         5986  +|      0: 0a 00 00 00 32 0e 4f 00 0f fa 10 f1 0f e9 0f e1   ....2.O.........
         5987  +|     16: 0f d8 0f d1 0f c9 0f c1 0f b9 0f b1 0f a9 0f a0   ................
         5988  +|     32: 0f 98 0f 90 0f 87 0f 80 0f 78 0f 71 0f 68 0f 5f   .........x.q.h._
         5989  +|     48: bd 56 0f 4d 0f 41 0f 38 0f 2f 0f 26 0f 1d 0f 13   .V.M.A.8./.&....
         5990  +|     64: 0f 0a 0f 01 0e f7 0e ee 0e e6 0e dd 0e d6 0e cd   ................
         5991  +|     80: 0e c3 0e ba 0e b0 0e a8 0e 9f 0e 96 0e 8e 0e 85   ................
         5992  +|     96: 0e 7c 0e 73 0e 6a 0e 60 0e 58 0e 4f 00 00 00 00   .|.s.j.`.X.O....
         5993  +|   3648: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08   ................
         5994  +|   3664: 04 01 10 2f 03 34 74 20 07 04 01 0e 01 03 34 1e   .../.4t ......4.
         5995  +|   3680: 09 04 01 12 01 03 33 74 68 1c 08 04 01 10 01 03   ......3th.......
         5996  +|   3696: 33 6e 1a 08 04 01 10 01 03 32 77 18 08 04 01 10   3n.......2w.....
         5997  +|   3712: 01 03 32 74 16 08 04 01 10 01 03 32 6e 14 07 04   ..2t.......2n...
         5998  +|   3728: 01 0e 01 03 32 12 08 04 01 10 01 03 31 74 10 08   ....2.......1t..
         5999  +|   3744: 04 01 10 01 03 31 6e 0e 07 04 01 0e 02 03 31 0c   .....1n.......1.
         6000  +|   3760: 09 04 01 12 01 03 30 74 68 0a 08 04 01 10 01 03   ......0th.......
         6001  +|   3776: 30 74 08 09 04 01 12 01 03 30 6e 75 06 08 04 01   0t.......0nu....
         6002  +|   3792: 10 01 03 30 6e 04 06 04 01 0c 01 05 52 08 04 01   ...0n.......R...
         6003  +|   3808: 10 01 02 34 72 22 07 04 01 0e 01 02 34 20 08 04   ...4r.......4 ..
         6004  +|   3824: 01 10 01 02 33 72 1e 09 04 01 12 01 02 33 61 72   ....3r.......3ar
         6005  +|   3840: 1c 08 04 01 10 01 02 32 74 1a 08 04 01 10 b3 02   .......2t.......
         6006  +|   3856: 32 69 18 09 04 01 12 01 02 32 61 72 16 08 04 01   2i.......2ar....
         6007  +|   3872: 10 01 02 31 74 14 08 04 01 10 01 02 31 6e 12 08   ...1t.......1n..
         6008  +|   3888: 04 01 10 01 02 31 62 10 08 04 01 10 01 02 31 32   .....1b.......12
         6009  +|   3904: 0e 0b 04 01 16 01 02 30 74 68 65 72 0c 08 04 01   .......0ther....
         6010  +|   3920: 10 01 02 30 74 0a 08 04 01 10 01 02 30 6e 08 08   ...0t.......0n..
         6011  +|   3936: 04 01 10 01 02 30 62 06 08 04 01 10 01 02 30 61   .....0b.......0a
         6012  +|   3952: 04 06 04 01 0c 01 02 02 07 04 09 10 01 34 74 22   .............4t.
         6013  +|   3968: 06 04 09 0e 01 34 20 08 04 09 12 01 33 74 65 1e   .....4 .....3te.
         6014  +|   3984: 07 04 09 10 01 33 70 1c 07 04 09 10 01 33 66 1a   .....3p......3f.
         6015  +|   4000: 08 04 09 12 01 32 74 68 18 07 04 09 10 01 32 74   .....2th......2t
         6016  +|   4016: 16 07 04 09 10 01 32 69 14 07 04 09 10 01 32 66   ......2i......2f
         6017  +|   4032: 12 07 04 09 10 01 31 74 10 07 04 09 10 01 31 69   ......1t......1i
         6018  +|   4048: 0e 06 04 09 0e 01 31 0c 08 04 09 12 01 30 74 65   ......1......0te
         6019  +|   4064: 0a 07 04 09 10 01 30 74 08 07 04 09 10 01 30 70   ......0t......0p
         6020  +|   4080: 06 08 04 09 12 01 30 66 74 04 05 04 09 0c 01 02   ......0ft.......
         6021  +| page 4 offset 12288
         6022  +|      0: 0d 00 00 00 03 0f eb 00 0f f9 0f f2 0f eb 00 00   ................
         6023  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 05 03 03 00 10   ................
         6024  +|   4080: 03 05 05 02 03 00 10 04 06 05 01 03 00 10 04 04   ................
         6025  +| page 5 offset 16384
         6026  +|      0: 0a 00 00 00 02 0f eb 00 0f eb 0f f4 00 00 00 00   ................
         6027  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 08 03 15 01 70   ...............p
         6028  +|   4080: 67 73 7a 18 0b 03 1b 01 76 65 72 73 69 6f 6e 04   gsz.....version.
         6029  +| page 6 offset 20480
         6030  +|      0: 0d 00 00 00 03 0f f2 00 0f fc 0f f7 0f f2 00 00   ................
         6031  +|   4080: 00 00 03 03 02 01 03 03 02 02 01 02 02 01 02 09   ................
         6032  +}]} {}
         6033  +
         6034  +do_catchsql_test 45.2 {
         6035  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6036  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6037  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6038  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6039  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6040  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6041  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6042  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6043  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6044  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6045  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6046  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6047  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6048  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6049  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6050  +  INSERT INTO t1(t1, rank) VALUES('merge', 5);
         6051  +} {0 {}}
         6052  +
         6053  +#--------------------------------------------------------------------------
         6054  +reset_db
         6055  +do_test 46.0 {
         6056  +  sqlite3 db {}
         6057  +  db deserialize [decode_hexdb {
         6058  +| size 32768 pagesize 4096 filename crash-1ee8bd451dd1ad.db
         6059  +| page 1 offset 0
         6060  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         6061  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 08   .....@  ........
         6062  +|     32: 00 00 00 02 00 00 00 01 00 00 00 09 00 00 00 04   ................
         6063  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         6064  +|     96: 00 00 00 00 0d 0f c7 00 07 0d 92 00 0f 8d 0f 36   ...............6
         6065  +|    112: 0e cb 0e 6b 0e 0e 0d b6 0d 92 0d 92 00 00 00 00   ...k............
         6066  +|   3472: 00 00 22 08 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
         6067  +|   3488: 32 74 32 08 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
         6068  +|   3504: 20 74 32 28 78 29 56 07 06 17 1f 1f 01 7d 74 60    t2(x)V.......t`
         6069  +|   3520: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
         6070  +|   3536: 6f 6e 66 69 67 07 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
         6071  +|   3552: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
         6072  +|   3568: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
         6073  +|   3584: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 06    WITHOUT ROWID[.
         6074  +|   3600: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
         6075  +|   3616: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
         6076  +|   3632: 06 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
         6077  +|   3648: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
         6078  +|   3664: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
         6079  +|   3680: 59 2c 20 73 7a 20 42 4c 4f 42 29 5e 05 07 17 21   Y, sz BLOB)^...!
         6080  +|   3696: 21 01 81 07 74 61 62 6c 65 74 31 5f 63 6f 6e 74   !...tablet1_cont
         6081  +|   3712: 65 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 05 43 52   entt1_content.CR
         6082  +|   3728: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63   EATE TABLE 't1_c
         6083  +|   3744: 6f 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47   ontent'(id INTEG
         6084  +|   3760: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   ER PRIMARY KEY, 
         6085  +|   3776: 63 30 2c 20 63 31 2c 20 63 32 29 69 04 07 17 19   c0, c1, c2)i....
         6086  +|   3792: 19 01 81 2d 74 61 62 6c 65 74 31 5f 69 64 78 74   ...-tablet1_idxt
         6087  +|   3808: 31 5f 69 64 78 04 43 52 45 41 54 45 20 54 41 42   1_idx.CREATE TAB
         6088  +|   3824: 4c 45 20 27 74 31 5f 69 64 78 27 28 73 65 67 69   LE 't1_idx'(segi
         6089  +|   3840: 64 2c 20 74 65 72 6d 2c 20 70 67 6e 6f 2c 20 50   d, term, pgno, P
         6090  +|   3856: 52 49 4d 41 52 59 20 4b 45 59 28 73 65 67 69 64   RIMARY KEY(segid
         6091  +|   3872: 2c 20 74 65 72 6d 29 29 20 57 49 54 48 4f 55 54   , term)) WITHOUT
         6092  +|   3888: 20 52 4f 57 49 44 55 03 07 17 1b 1b 01 81 01 74    ROWIDU........t
         6093  +|   3904: 61 62 6c 65 74 31 5f 64 61 74 61 74 31 5f 64 61   ablet1_datat1_da
         6094  +|   3920: 74 61 03 43 52 45 41 54 45 20 54 41 42 4c 45 20   ta.CREATE TABLE 
         6095  +|   3936: 27 74 31 5f 64 61 74 61 27 28 69 64 20 49 4e 54   't1_data'(id INT
         6096  +|   3952: 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59   EGER PRIMARY KEY
         6097  +|   3968: 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 38 02 06   , block BLOB)8..
         6098  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         6099  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         6100  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 35   LE t1 USING fts5
         6101  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00   (a,b,c)...9.....
         6102  +| page 3 offset 8192
         6103  +|      0: 0d 00 00 00 03 0c 94 00 0f e6 0f ef 0c 94 00 00   ................
         6104  +|   3216: 00 00 00 00 86 4a 84 80 80 80 80 01 04 00 8d 18   .....J..........
         6105  +|   3232: 00 00 03 2b 02 30 30 01 02 06 01 02 06 01 02 06   ...+.00.........
         6106  +|   3248: 1f 02 03 01 02 03 01 02 03 01 08 32 30 31 36 30   ...........20160
         6107  +|   3264: 36 30 39 01 02 07 01 02 07 01 02 07 01 01 34 01   609...........4.
         6108  +|   3280: 02 05 01 02 05 01 02 05 01 01 35 01 02 04 01 02   ..........5.....
         6109  +|   3296: 04 01 02 04 02 07 30 30 30 30 30 30 30 1c 02 3d   ......0000000..=
         6110  +|   3312: 01 02 04 01 02 04 01 06 62 69 6e 61 72 79 03 06   ........binary..
         6111  +|   3328: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         6112  +|   3344: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         6113  +|   3360: 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02 02   ................
         6114  +|   3376: 03 06 01 02 02 03 06 01 02 02 01 08 63 6f 6d 70   ............comp
         6115  +|   3392: 69 6c 65 72 01 02 02 01 02 02 01 02 02 01 06 64   iler...........d
         6116  +|   3408: 62 73 74 61 74 07 02 03 01 02 03 01 02 03 02 04   bstat...........
         6117  +|   3424: 65 62 75 67 04 02 02 01 02 02 01 02 02 01 06 65   ebug...........e
         6118  +|   3440: 6e 61 62 6c 65 07 02 02 01 02 02 01 02 02 01 02   nable...........
         6119  +|   3456: 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02   ................
         6120  +|   3472: 01 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01   ................
         6121  +|   3488: 02 02 01 02 02 01 02 02 01 02 02 01 02 02 01 02   ................
         6122  +|   3504: 02 01 02 02 02 08 78 74 65 6e 73 69 6f 6e 1f 02   ......xtension..
         6123  +|   3520: 04 01 02 04 01 02 04 01 04 66 74 73 34 0a 02 03   .........fts4...
         6124  +|   3536: 01 02 03 01 02 03 04 01 35 0d 02 03 01 02 03 01   ........5.......
         6125  +|   3552: 02 03 01 03 67 63 63 01 02 03 01 02 03 01 02 03   ....gcc.........
         6126  +|   3568: 02 06 65 6f 70 6f 6c 79 10 02 03 01 02 03 01 02   ..eopoly........
         6127  +|   3584: 03 01 05 6a 73 6f 6e 31 13 02 03 01 02 03 01 02   ...json1........
         6128  +|   3600: 03 01 04 6c 6f 61 64 1f 02 03 01 02 03 01 02 03   ...load.........
         6129  +|   3616: 01 03 6d 61 78 1c 02 02 01 02 02 01 02 02 02 05   ..max...........
         6130  +|   3632: 65 6d 6f 72 79 1c 02 03 01 02 03 01 02 03 04 04   emory...........
         6131  +|   3648: 73 79 73 35 16 02 03 01 02 03 01 02 03 01 06 6e   sys5...........n
         6132  +|   3664: 6f 63 61 73 65 02 06 01 02 02 03 06 01 02 02 03   ocase...........
         6133  +|   3680: 06 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06   ................
         6134  +|   3696: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         6135  +|   3712: 02 02 03 07 01 02 02 03 06 01 02 02 03 06 01 02   ................
         6136  +|   3728: 02 01 04 6f 6d 69 74 1f 02 02 01 02 02 01 02 02   ...omit.........
         6137  +|   3744: 01 05 72 74 72 65 65 19 02 03 01 02 03 01 02 03   ..rtree.........
         6138  +|   3760: 04 02 69 6d 01 06 01 02 02 03 06 01 02 02 03 06   ..im............
         6139  +|   3776: 01 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01   ................
         6140  +|   3792: 02 02 03 06 01 02 02 03 06 01 02 02 03 06 01 02   ................
         6141  +|   3808: 02 03 06 01 02 02 03 06 06 e2 02 03 06 01 02 02   ................
         6142  +|   3824: 01 0a 74 68 72 65 61 64 73 61 66 65 22 02 02 01   ..threadsafe....
         6143  +|   3840: 02 02 01 02 02 01 04 76 74 61 62 07 02 04 01 02   .......vtab.....
         6144  +|   3856: 04 01 02 04 01 01 78 01 06 01 01 02 01 06 01 01   ......x.........
         6145  +|   3872: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02   ................
         6146  +|   3888: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01   ................
         6147  +|   3904: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06   ................
         6148  +|   3920: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01   ................
         6149  +|   3936: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01   ................
         6150  +|   3952: 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02   ................
         6151  +|   3968: 01 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01   ................
         6152  +|   3984: 06 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06   ................
         6153  +|   4000: 01 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01   ................
         6154  +|   4016: 01 02 01 06 01 01 02 01 06 01 01 02 01 06 01 01   ................
         6155  +|   4032: 02 01 06 01 01 02 01 06 01 01 02 04 15 13 0c 0c   ................
         6156  +|   4048: 12 44 13 11 0f 47 13 0f 0c 0e 11 10 0f 0e 10 0f   .D...G..........
         6157  +|   4064: 44 0f 10 40 15 0f 07 01 03 00 14 24 5a 24 24 0f   D..@.......$Z$$.
         6158  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         6159  +| page 4 offset 12288
         6160  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
         6161  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         6162  +| page 5 offset 16384
         6163  +|      0: 0d 00 00 00 24 0c 0a 00 0f d8 0f af 0f 86 0f 74   ....$..........t
         6164  +|     16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5   .a.N./..........
         6165  +|     32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5   ...t.[.@.$......
         6166  +|     48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb   .......h.O.5....
         6167  +|     64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a   .......x.W.>.$..
         6168  +|   3072: 00 00 00 00 00 00 00 00 00 00 18 24 05 00 25 0f   ...........$..%.
         6169  +|   3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49   .THREADSAFE=0XBI
         6170  +|   3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41   NARY.#..%..THREA
         6171  +|   3120: 44 53 31 46 45 3d 30 58 4e 4f 43 41 53 45 17 22   DS1FE=0XNOCASE..
         6172  +|   3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d   ..%..THREADSAFE=
         6173  +|   3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d   0XRTRIM.!..3..OM
         6174  +|   3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f   IT LOAD EXTENSIO
         6175  +|   3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f   NXBINARY. ..3..O
         6176  +|   3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49   MIT LOAD EXTENSI
         6177  +|   3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17   ONXNOCASE....3..
         6178  +|   3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53   OMIT LOAD EXTENS
         6179  +|   3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19   IONXRTRIM....3..
         6180  +|   3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30   MAX MEMORY=50000
         6181  +|   3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f   000XBINARY....3.
         6182  +|   3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30   .MAX MEMORY=5000
         6183  +|   3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33   0000XNOCASE....3
         6184  +|   3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30   ..MAX MEMORY=500
         6185  +|   3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25   00000XRTRIM....%
         6186  +|   3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42   ..ENABLE RTREEXB
         6187  +|   3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         6188  +|   3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17   LE RTREEXNOCASE.
         6189  +|   3408: 19 05 00 25 0f 17 45 4e 40 42 4c 45 20 52 54 52   ...%..EN@BLE RTR
         6190  +|   3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45   EEXRTRIM....)..E
         6191  +|   3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49   NABLE MEMSYS5XBI
         6192  +|   3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         6193  +|   3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45   E MEMSYS5XNOCASE
         6194  +|   3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45   ....)..ENABLE ME
         6195  +|   3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25   MSYS5XRTRIM....%
         6196  +|   3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 59 42   ..ENABLE JSON1YB
         6197  +|   3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         6198  +|   3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17   LE JSON1XNOCASE.
         6199  +|   3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f   ...%..ENABLE JSO
         6200  +|   3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45   N1XRTRIM....)..E
         6201  +|   3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49   NABLE GEOPOLYXBI
         6202  +|   3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         6203  +|   3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45   E GEOPOLYXNOCASE
         6204  +|   3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45   ....)..ENABLE GE
         6205  +|   3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 15 00 23   OPOLYXRTRIM....#
         6206  +|   3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49   ..ENABLE FTS5XBI
         6207  +|   3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c   NARY....#..ENABL
         6208  +|   3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05   E FTS5XNOCASE...
         6209  +|   3728: 00 23 0f a4 45 4e 41 42 4c 45 20 46 54 53 35 58   .#..ENABLE FTS5X
         6210  +|   3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42   RTRIM....#..ENAB
         6211  +|   3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b   LE FTS4XBINARY..
         6212  +|   3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 34   ..#..ENABLE FTS4
         6213  +|   3792: 58 4e 4f 43 41 53 45 16 0a 05 00 23 0f 17 45 4e   XNOCASE....#..EN
         6214  +|   3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e   ABLE FTS4XRTRIM.
         6215  +|   3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         6216  +|   3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e   TAT VTABXBINARY.
         6217  +|   3856: 08 04 f0 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         6218  +|   3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d   TAT VTABXNOCASE.
         6219  +|   3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         6220  +|   3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06   TAT VTABXRTRIM..
         6221  +|   3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52   .....DEBUGXBINAR
         6222  +|   3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f   Y.......DEBUGXNO
         6223  +|   3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47   CASE.......DEBUG
         6224  +|   3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d   XRTRIM'...C..COM
         6225  +|   3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20   PILER=gcc-5.4.0 
         6226  +|   4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27   20160609XBINARY'
         6227  +|   4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67   ...C..COMPILER=g
         6228  +|   4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30   cc-5.4.0 2016060
         6229  +|   4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43   9XNOCASE&...C..C
         6230  +|   4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e   OMPILER=gcc-5.4.
         6231  +|   4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d   0 20160609XRTRIM
         6232  +| page 6 offset 20480
         6233  +|      0: 0d 00 00 00 24 0e e0 00 0f f8 0f f0 0f e8 0f e0   ....$...........
         6234  +|     16: 0f d8 0f d0 0f c8 0f c0 0f b8 0f b0 0f a8 0f a0   ................
         6235  +|     32: 0f 98 0f 90 0f 88 0f 80 0f 78 0f 70 0f 68 0f 60   .........x.p.h.`
         6236  +|     48: 0f 58 0f 50 0f 48 0f 40 0f 38 0f 30 0f 28 0f 20   .X.P.H.@.8.0.(. 
         6237  +|     64: 0f 18 0f 10 0f 08 0f 00 0e f8 0e f0 0e e8 0e e0   ................
         6238  +|   3808: 06 24 03 00 12 02 01 01 06 23 03 00 12 02 01 01   .$.......#......
         6239  +|   3824: 06 22 03 00 12 02 01 01 06 21 03 00 12 03 01 01   .........!......
         6240  +|   3840: 06 20 03 00 22 03 01 01 06 1f 03 00 12 03 01 01   . ..............
         6241  +|   3856: 06 1e 03 00 12 03 01 01 06 1d 03 00 12 03 01 01   ................
         6242  +|   3872: 06 1c 03 00 12 03 01 01 06 1b 03 00 12 02 01 01   ................
         6243  +|   3888: 06 1a 03 00 12 02 01 01 06 19 03 00 12 02 01 01   ................
         6244  +|   3904: 06 18 03 00 12 02 01 01 06 17 03 00 12 02 01 01   ................
         6245  +|   3920: 06 16 03 00 12 02 01 01 06 15 03 00 12 02 01 01   ................
         6246  +|   3936: 06 14 03 00 12 02 01 01 06 13 03 00 12 02 01 01   ................
         6247  +|   3952: 06 12 03 00 12 02 01 01 06 11 03 00 12 02 01 01   ................
         6248  +|   3968: 06 10 03 00 12 02 01 01 06 0f 03 00 12 02 01 01   ................
         6249  +|   3984: 06 0e 03 00 12 02 01 01 06 0d 03 00 12 02 01 01   ................
         6250  +|   4000: 06 0c 03 00 12 02 01 01 06 0b 03 00 12 02 01 01   ................
         6251  +|   4016: 06 0a 03 00 12 02 01 01 06 09 03 00 12 03 01 01   ................
         6252  +|   4032: 06 08 03 00 12 03 01 01 06 07 03 00 12 03 01 01   ................
         6253  +|   4048: 06 a2 03 00 12 01 01 01 06 05 03 00 12 01 01 01   ................
         6254  +|   4064: 06 04 03 00 12 01 01 01 06 03 03 00 12 06 01 01   ................
         6255  +|   4080: 06 02 03 00 12 06 01 01 06 01 03 00 12 06 01 01   ................
         6256  +| page 7 offset 24576
         6257  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         6258  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         6259  +| page 8 offset 28672
         6260  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e9 0f d6 00 00   ................
         6261  +|   4048: 00 00 00 00 00 00 11 03 02 2b 69 6e 74 65 67 72   .........+integr
         6262  +|   4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity-check....reb
         6263  +|   4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   uild....optimize
         6264  +| end crash-1ee8bd451dd1ad.db
         6265  +}]} {}
         6266  +
         6267  +do_catchsql_test 46.1 {
         6268  +  SELECT snippet(t1,'[','', '--',-1,10) FROM t1('*');
         6269  +} {0 {{}}}
         6270  +
         6271  +#--------------------------------------------------------------------------
         6272  +reset_db
         6273  +do_test 47.0 {
         6274  +  sqlite3 db {}
         6275  +  db deserialize [decode_hexdb {
         6276  +| size 40960 pagesize 4096 filename 4b6fc659283f2735616c.db
         6277  +| page 1 offset 0
         6278  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         6279  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 0a   .....@  ........
         6280  +|     32: 00 00 00 00 00 00 00 00 00 00 00 0d 00 00 00 04   ................
         6281  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         6282  +|     96: 00 00 00 00 0d 00 00 00 0d 0b 6e 00 0f a3 0f 4c   ..........n....L
         6283  +|    112: 0e e1 0e 81 0e 24 0d cc 0d 72 0d 1b 0c b0 0c 50   .....$...r.....P
         6284  +|    128: 0b f8 0b b3 0b 6e 00 00 00 00 00 00 00 00 00 00   .....n..........
         6285  +|   2912: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 43 0d   ..............C.
         6286  +|   2928: 06 17 11 11 08 75 74 61 62 6c 65 74 34 74 34 43   .....utablet4t4C
         6287  +|   2944: 52 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41   REATE VIRTUAL TA
         6288  +|   2960: 42 4c 45 20 74 34 20 55 53 49 4e 47 20 66 74 73   BLE t4 USING fts
         6289  +|   2976: 35 76 6f 63 61 62 28 27 74 32 27 2c 20 27 72 6f   5vocab('t2', 'ro
         6290  +|   2992: 77 27 29 43 0c 06 17 11 11 08 75 74 61 62 6c 65   w')C......utable
         6291  +|   3008: 74 33 74 33 43 52 45 41 54 45 20 56 49 52 54 55   t3t3CREATE VIRTU
         6292  +|   3024: 41 4c 20 54 41 42 4c 45 20 74 33 20 55 53 49 4e   AL TABLE t3 USIN
         6293  +|   3040: 47 20 66 74 73 35 76 6f 63 61 62 28 27 74 31 27   G fts5vocab('t1'
         6294  +|   3056: 2c 20 27 72 6f 77 27 29 56 0b 06 17 1f 1f 01 7d   , 'row')V.......
         6295  +|   3072: 74 61 62 6c 65 7d 42 5f 63 6f 6e 66 69 67 74 32   table.B_configt2
         6296  +|   3088: 5f 63 6f 6e 66 69 67 0a 43 52 45 41 54 45 20 54   _config.CREATE T
         6297  +|   3104: 41 42 4c 45 20 27 74 32 5f 63 6f 6e 66 69 67 27   ABLE 't2_config'
         6298  +|   3120: 28 6b 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20   (k PRIMARY KEY, 
         6299  +|   3136: 76 29 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44   v) WITHOUT ROWID
         6300  +|   3152: 5e 0a 07 17 21 21 01 81 07 74 61 62 6c 65 74 32   ^...!!...tablet2
         6301  +|   3168: 5f 63 6f 6e 74 65 6e 74 74 32 5f 63 6f 6e 74 65   _contentt2_conte
         6302  +|   3184: 6e 74 09 43 52 45 41 54 45 20 54 41 42 4c 45 20   nt.CREATE TABLE 
         6303  +|   3200: 27 74 32 5f 63 6f 6e 74 65 6e 74 27 28 69 64 20   't2_content'(id 
         6304  +|   3216: 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20   INTEGER PRIMARY 
         6305  +|   3232: 4b 45 59 2c 20 63 30 2c 20 63 31 2c 20 63 32 29   KEY, c0, c1, c2)
         6306  +|   3248: 69 09 07 17 19 19 01 81 2d 74 61 62 6c 65 74 32   i.......-tablet2
         6307  +|   3264: 5f 69 64 78 74 32 5f 69 64 78 08 43 52 45 41 54   _idxt2_idx.CREAT
         6308  +|   3280: 45 20 54 41 42 4c 45 20 27 74 32 5f 69 64 78 27   E TABLE 't2_idx'
         6309  +|   3296: 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20 70 67   (segid, term, pg
         6310  +|   3312: 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45 59 28   no, PRIMARY KEY(
         6311  +|   3328: 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20 57 49   segid, term)) WI
         6312  +|   3344: 54 48 4f 55 54 20 52 4f 57 49 44 55 08 07 17 1b   THOUT ROWIDU....
         6313  +|   3360: 1b 01 81 01 74 61 62 6c 65 74 32 5f 64 61 74 61   ....tablet2_data
         6314  +|   3376: 74 32 5f 64 61 74 61 07 43 52 45 41 54 45 20 54   t2_data.CREATE T
         6315  +|   3392: 41 42 4c 45 20 27 74 32 5f 64 61 74 61 27 28 69   ABLE 't2_data'(i
         6316  +|   3408: 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52   d INTEGER PRIMAR
         6317  +|   3424: 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f   Y KEY, block BLO
         6318  +|   3440: 42 29 58 07 07 17 11 11 08 81 1d 74 61 62 6c 65   B)X........table
         6319  +|   3456: 74 32 74 32 43 52 45 41 54 45 20 56 49 52 54 55   t2t2CREATE VIRTU
         6320  +|   3472: 41 4c 20 54 41 42 4c 45 20 74 32 20 55 53 49 4e   AL TABLE t2 USIN
         6321  +|   3488: 47 20 66 74 73 35 28 27 61 27 2c 5b 62 5d 2c 22   G fts5('a',[b],.
         6322  +|   3504: 63 22 2c 64 65 74 61 69 6c 3d 6e 6f 6e 65 2c 63   c.,detail=none,c
         6323  +|   3520: 6f 6c 75 6d 6e 73 69 7a 65 3d 30 29 56 06 06 17   olumnsize=0)V...
         6324  +|   3536: 1f 1f 01 7d 74 61 62 6c 65 74 31 5f 63 6f 6e 66   ....tablet1_conf
         6325  +|   3552: 69 67 74 31 5f 63 6f 6e 66 69 67 06 43 52 45 41   igt1_config.CREA
         6326  +|   3568: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f 6e   TE TABLE 't1_con
         6327  +|   3584: 66 69 67 27 28 6b 20 50 52 49 4d 41 52 59 20 4b   fig'(k PRIMARY K
         6328  +|   3600: 45 59 2c 20 76 29 20 57 49 54 48 4f 55 54 20 52   EY, v) WITHOUT R
         6329  +|   3616: 4f 57 49 44 5b 05 07 17 21 21 01 81 01 74 61 62   OWID[...!!...tab
         6330  +|   3632: 6c 65 74 31 5f 64 6f 63 73 69 7a 65 74 31 5f 64   let1_docsizet1_d
         6331  +|   3648: 6f 63 73 69 7a 65 05 43 52 45 41 54 45 20 54 41   ocsize.CREATE TA
         6332  +|   3664: 42 4c 45 20 27 74 31 5f 64 6f 63 73 69 7a 65 27   BLE 't1_docsize'
         6333  +|   3680: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         6334  +|   3696: 41 52 59 20 4b 45 59 2c 20 73 7a 20 42 4c 4f 42   ARY KEY, sz BLOB
         6335  +|   3712: 29 5e 04 07 17 21 21 01 81 07 74 61 62 6c 65 74   )^...!!...tablet
         6336  +|   3728: 31 5f 63 6f 6e 74 65 6f 74 74 31 5f 63 6f 6e 74   1_conteott1_cont
         6337  +|   3744: 65 6e 74 04 43 52 45 41 54 45 20 54 41 42 4c 45   ent.CREATE TABLE
         6338  +|   3760: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 69 64    't1_content'(id
         6339  +|   3776: 20 49 4e 54 45 47 46 52 20 50 52 49 4d 41 52 59    INTEGFR PRIMARY
         6340  +|   3792: 20 4b 45 59 2c 20 63 30 2c 20 63 31 2c 20 63 32    KEY, c0, c1, c2
         6341  +|   3808: 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65 74   )i.......-tablet
         6342  +|   3824: 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45 41   1_idxt1_idx.CREA
         6343  +|   3840: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64 78   TE TABLE 't1_idx
         6344  +|   3856: 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20 70   '(segid, term, p
         6345  +|   3872: 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45 59   gno, PRIMARY KEY
         6346  +|   3888: 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20 57   (segid, term)) W
         6347  +|   3904: 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07 17   ITHOUT ROWIDU...
         6348  +|   3920: 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61 74   .....tablet1_dat
         6349  +|   3936: 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45 20   at1_data.CREATE 
         6350  +|   3952: 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27 28   TABLE 't1_data'(
         6351  +|   3968: 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41   id INTEGER PRIMA
         6352  +|   3984: 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c   RY KEY, block BL
         6353  +|   4000: 4f 42 29 5b 01 07 17 11 11 08 81 23 74 61 62 6c   OB)[.......#tabl
         6354  +|   4016: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
         6355  +|   4032: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
         6356  +|   4048: 4e 47 20 66 74 73 35 28 61 2c 62 20 75 6e 69 6e   NG fts5(a,b unin
         6357  +|   4064: 64 65 78 65 64 2c 63 2c 74 6f 6b 65 6e 69 7a 65   dexed,c,tokenize
         6358  +|   4080: 3d 22 70 6f 72 74 65 72 20 61 73 63 69 69 22 29   =.porter ascii.)
         6359  +| page 2 offset 4096
         6360  +|      0: 0d 0f 68 00 05 0f 13 00 0f e6 0f 13 0f a8 0f 7c   ..h............|
         6361  +|     16: 0f 2a 00 00 00 00 00 00 00 00 00 00 00 00 00 00   .*..............
         6362  +|   3856: 00 00 00 15 0a 03 00 30 00 00 00 00 01 03 03 00   .......0........
         6363  +|   3872: 03 01 01 01 02 01 01 03 01 01 37 8c 80 80 80 80   ..........7.....
         6364  +|   3888: 01 03 00 74 00 00 00 2e 02 30 61 03 02 02 01 01   ...t.....0a.....
         6365  +|   3904: 62 03 02 03 01 01 63 03 02 04 01 01 67 03 06 01   b.....c.....g...
         6366  +|   3920: 02 02 01 01 68 03 06 01 02 03 01 01 69 03 06 01   ....h.......i...
         6367  +|   3936: 02 04 04 06 06 06 08 08 0f ef 00 14 2a 00 00 00   ............*...
         6368  +|   3952: 00 01 02 02 00 02 01 01 01 02 01 01 25 88 80 80   ............%...
         6369  +|   3968: 80 80 01 03 00 50 00 00 00 1f 02 30 67 02 08 02   .....P.....0g...
         6370  +|   3984: 01 02 02 01 01 68 02 08 03 01 02 03 01 01 69 02   .....h........i.
         6371  +|   4000: 08 04 01 02 04 04 09 09 37 84 80 80 80 80 01 03   ........7.......
         6372  +|   4016: 00 74 00 00 00 2e 02 30 61 01 02 02 01 01 62 01   .t.....0a.....b.
         6373  +|   4032: 02 03 01 01 63 01 02 04 01 01 67 01 06 01 02 01   ....c.....g.....
         6374  +|   4048: 01 01 68 01 06 01 02 03 01 01 69 01 06 01 02 04   ..h.......i.....
         6375  +|   4064: 04 06 06 06 08 08 07 01 03 00 14 03 09 00 09 00   ................
         6376  +|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         6377  +| page 3 offset 8192
         6378  +|      0: 0a 00 00 00 03 0f ec 00 0f fa 0f f3 0f ec 00 00   ................
         6379  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 06 04 01 0c   ................
         6380  +|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0c 01 02   ................
         6381  +| page 4 offset 12288
         6382  +|      0: 0d 00 00 00 03 0f be 00 0f ea 0f d4 0f be 00 00   ................
         6383  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 03   ................
         6384  +|   4032: 05 00 17 17 17 61 20 62 20 63 67 20 68 20 69 67   .....a b cg h ig
         6385  +|   4048: 20 68 20 69 14 02 05 00 17 17 17 67 20 68 20 69    h i.......g h i
         6386  +|   4064: 61 20 62 20 63 67 20 68 20 69 14 01 05 00 17 17   a b cg h i......
         6387  +|   4080: 17 61 20 62 20 63 64 20 65 20 66 67 20 68 20 69   .a b cd e fg h i
         6388  +| page 5 offset 16384
         6389  +|      0: 0d 00 00 00 03 0f e8 00 0f f8 0f f0 0f e8 00 00   ................
         6390  +|   4064: 00 00 00 00 00 00 00 00 06 03 03 00 12 03 00 03   ................
         6391  +|   4080: 06 02 03 00 12 03 00 03 06 01 03 00 12 03 00 03   ................
         6392  +| page 6 offset 20480
         6393  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         6394  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         6395  +| page 7 offset 24576
         6396  +|      0: 0d 00 00 00 03 0f 9e 00 0f e6 0f ef 0f 9e 00 00   ................
         6397  +|   3984: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 41 84   ..............A.
         6398  +|   4000: 80 80 80 80 01 04 00 81 06 00 00 00 34 02 30 61   ............4.0a
         6399  +|   4016: 01 01 01 01 01 62 01 01 01 01 01 63 01 01 01 01   .....b.....c....
         6400  +|   4032: 01 64 01 01 01 65 01 01 01 66 01 01 01 67 01 01   .d...e...f...g..
         6401  +|   4048: 01 01 01 68 01 01 01 01 01 69 01 01 01 04 06 06   ...h.....i......
         6402  +|   4064: 06 04 04 04 06 06 07 01 03 00 14 03 09 09 09 0f   ................
         6403  +|   4080: 0a 03 00 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
         6404  +| page 8 offset 28672
         6405  +|      0: 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00 00   ................
         6406  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
         6407  +| page 9 offset 32768
         6408  +|      0: 0d 00 00 00 03 0f be 00 0f ea 0f d4 0f be 00 00   ................
         6409  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 14 03   ................
         6410  +|   4032: 05 00 17 17 17 61 20 62 20 63 67 20 68 20 69 67   .....a b cg h ig
         6411  +|   4048: 20 68 20 69 14 02 05 00 17 17 17 67 20 68 20 69    h i.......g h i
         6412  +|   4064: 61 20 62 20 63 67 20 68 20 69 14 01 05 00 17 17   a b cg h i......
         6413  +|   4080: 17 61 20 62 20 63 64 20 65 20 66 67 20 68 20 69   .a b cd e fg h i
         6414  +| page 10 offset 36864
         6415  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
         6416  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
         6417  +| end 4b6fc659283f2735616c.db
         6418  +}]} {}
         6419  +
         6420  +do_catchsql_test 47.1 {
         6421  +  SELECT snippet(t1, -1, '.', '..', '[', 50), 
         6422  +         highlight(t1, 2, '[', ']') FROM t1('g h') 
         6423  +  WHERE rank MATCH 'bm25(1.0, 1.0)' ORDER BY rank;
         6424  +} {1 {database disk image is malformed}}
         6425  +
  4053   6426   
  4054   6427   sqlite3_fts5_may_be_corrupt 0
  4055   6428   finish_test
  4056   6429   

Changes to ext/fts5/test/fts5vocab.test.

   475    475     expr [lsearch $e2 SorterSort]<0
   476    476   } 1
   477    477   do_test 9.6 {
   478    478     set e2 [db eval { EXPLAIN SELECT * FROM rrr ORDER BY term DESC }]
   479    479     expr [lsearch $e2 SorterSort]<0
   480    480   } 0
   481    481   
          482  +#-------------------------------------------------------------------------
          483  +do_execsql_test 10.0 {
          484  +  CREATE VIRTUAL TABLE ft USING fts5(a, b, c);
          485  +  CREATE VIRTUAL TABLE t2 USING fts5vocab('ft','row');
          486  +  CREATE VIRTUAL TABLE t3 USING fts5vocab('ft','row');
          487  +}
          488  +
          489  +do_execsql_test 10.1 {
          490  +  BEGIN;
          491  +    INSERT INTO ft(b) VALUES('x y');
          492  +}
          493  +
          494  +do_execsql_test 10.2 {
          495  +  SELECT t2.term FROM t2;
          496  +} {x y}
          497  +
          498  +do_execsql_test 10.3 {
          499  +  SELECT t2.term, t3.term FROM t2, t3;
          500  +} {x x x y y x y y}
          501  +
          502  +do_execsql_test 10.4 {
          503  +  COMMIT;
          504  +}
          505  +
          506  +do_execsql_test 10.5 {
          507  +  BEGIN;
          508  +    INSERT INTO ft(a) VALUES('1 2 3');
          509  +    INSERT INTO ft(a) VALUES('4 5 6');
          510  +    INSERT INTO ft(a) VALUES('1 2 3');
          511  +    INSERT INTO ft(a) VALUES('4 5 6');
          512  +    INSERT INTO ft(a) VALUES('1 2 3');
          513  +    INSERT INTO ft(a) VALUES('4 5 6');
          514  +}
          515  +
          516  +do_test 10.6 {
          517  +  set res [list]
          518  +  db eval { SELECT rowid FROM ft('4') } x {
          519  +    db eval { SELECT * FROM t2 }
          520  +    lappend res $x(rowid)
          521  +  }
          522  +  db eval COMMIT
          523  +  set res
          524  +} {3 5 7}
   482    525   
          526  +do_execsql_test 10.6.1 {
          527  +  SELECT * FROM t2 WHERE term<NULL;
          528  +}
          529  +do_execsql_test 10.6.2 {
          530  +  SELECT * FROM t2 WHERE term>NULL;
          531  +}
          532  +do_execsql_test 10.6.3 {
          533  +  SELECT * FROM t2 WHERE term=NULL;
          534  +}
          535  +do_execsql_test 10.7.1 {
          536  +  SELECT * FROM t2 WHERE term<?;
          537  +}
          538  +do_execsql_test 10.7.2 {
          539  +  SELECT * FROM t2 WHERE term>?;
          540  +}
          541  +do_execsql_test 10.7.3 {
          542  +  SELECT * FROM t2 WHERE term=?;
          543  +}
   483    544   
   484    545   finish_test
          546  +

Added ext/misc/memtrace.c.

            1  +/*
            2  +** 2019-01-21
            3  +**
            4  +** The author disclaims copyright to this source code.  In place of
            5  +** a legal notice, here is a blessing:
            6  +**
            7  +**    May you do good and not evil.
            8  +**    May you find forgiveness for yourself and forgive others.
            9  +**    May you share freely, never taking more than you give.
           10  +**
           11  +*************************************************************************
           12  +**
           13  +** This file implements an extension that uses the SQLITE_CONFIG_MALLOC
           14  +** mechanism to add a tracing layer on top of SQLite.  If this extension
           15  +** is registered prior to sqlite3_initialize(), it will cause all memory
           16  +** allocation activities to be logged on standard output, or to some other
           17  +** FILE specified by the initializer.
           18  +**
           19  +** This file needs to be compiled into the application that uses it.
           20  +**
           21  +** This extension is used to implement the --memtrace option of the
           22  +** command-line shell.
           23  +*/
           24  +#include <assert.h>
           25  +#include <string.h>
           26  +#include <stdio.h>
           27  +
           28  +/* The original memory allocation routines */
           29  +static sqlite3_mem_methods memtraceBase;
           30  +static FILE *memtraceOut;
           31  +
           32  +/* Methods that trace memory allocations */
           33  +static void *memtraceMalloc(int n){
           34  +  if( memtraceOut ){
           35  +    fprintf(memtraceOut, "MEMTRACE: allocate %d bytes\n", 
           36  +            memtraceBase.xRoundup(n));
           37  +  }
           38  +  return memtraceBase.xMalloc(n);
           39  +}
           40  +static void memtraceFree(void *p){
           41  +  if( p==0 ) return;
           42  +  if( memtraceOut ){
           43  +    fprintf(memtraceOut, "MEMTRACE: free %d bytes\n", memtraceBase.xSize(p));
           44  +  }
           45  +  memtraceBase.xFree(p);
           46  +}
           47  +static void *memtraceRealloc(void *p, int n){
           48  +  if( p==0 ) return memtraceMalloc(n);
           49  +  if( n==0 ){
           50  +    memtraceFree(p);
           51  +    return 0;
           52  +  }
           53  +  if( memtraceOut ){
           54  +    fprintf(memtraceOut, "MEMTRACE: resize %d -> %d bytes\n",
           55  +            memtraceBase.xSize(p), memtraceBase.xRoundup(n));
           56  +  }
           57  +  return memtraceBase.xRealloc(p, n);
           58  +}
           59  +static int memtraceSize(void *p){
           60  +  return memtraceBase.xSize(p);
           61  +}
           62  +static int memtraceRoundup(int n){
           63  +  return memtraceBase.xRoundup(n);
           64  +}
           65  +static int memtraceInit(void *p){
           66  +  return memtraceBase.xInit(p);
           67  +}
           68  +static void memtraceShutdown(void *p){
           69  +  memtraceBase.xShutdown(p);
           70  +}
           71  +
           72  +/* The substitute memory allocator */
           73  +static sqlite3_mem_methods ersaztMethods = {
           74  +  memtraceMalloc,
           75  +  memtraceFree,
           76  +  memtraceRealloc,
           77  +  memtraceSize,
           78  +  memtraceRoundup,
           79  +  memtraceInit,
           80  +  memtraceShutdown
           81  +};
           82  +
           83  +/* Begin tracing memory allocations to out. */
           84  +int sqlite3MemTraceActivate(FILE *out){
           85  +  int rc = SQLITE_OK;
           86  +  if( memtraceBase.xMalloc==0 ){
           87  +    rc = sqlite3_config(SQLITE_CONFIG_GETMALLOC, &memtraceBase);
           88  +    if( rc==SQLITE_OK ){
           89  +      rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &ersaztMethods);
           90  +    }
           91  +  }
           92  +  memtraceOut = out;
           93  +  return rc;
           94  +}
           95  +
           96  +/* Deactivate memory tracing */
           97  +int sqlite3MemTraceDeactivate(void){
           98  +  int rc = SQLITE_OK;
           99  +  if( memtraceBase.xMalloc!=0 ){
          100  +    rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &memtraceBase);
          101  +    if( rc==SQLITE_OK ){
          102  +      memset(&memtraceBase, 0, sizeof(memtraceBase));
          103  +    }
          104  +  }
          105  +  memtraceOut = 0;
          106  +  return rc;
          107  +}

Changes to ext/rtree/geopoly.c.

   119    119     GeoCoord a[8];        /* 2*nVertex values. X (longitude) first, then Y */
   120    120   };
   121    121   
   122    122   /* The size of a memory allocation needed for a GeoPoly object sufficient
   123    123   ** to hold N coordinate pairs.
   124    124   */
   125    125   #define GEOPOLY_SZ(N)  (sizeof(GeoPoly) + sizeof(GeoCoord)*2*((N)-4))
          126  +
          127  +/* Macros to access coordinates of a GeoPoly.
          128  +** We have to use these macros, rather than just say p->a[i] in order
          129  +** to silence (incorrect) UBSAN warnings if the array index is too large.
          130  +*/
          131  +#define GeoX(P,I)  (((GeoCoord*)(P)->a)[(I)*2])
          132  +#define GeoY(P,I)  (((GeoCoord*)(P)->a)[(I)*2+1])
          133  +
   126    134   
   127    135   /*
   128    136   ** State of a parse of a GeoJSON input.
   129    137   */
   130    138   typedef struct GeoParse GeoParse;
   131    139   struct GeoParse {
   132    140     const unsigned char *z;   /* Unparsed input */
................................................................................
   312    320           if( pCtx ) sqlite3_result_error_nomem(pCtx);
   313    321         }else{
   314    322           int x = 1;
   315    323           p->nVertex = nVertex;
   316    324           memcpy(p->hdr, a, nByte);
   317    325           if( a[0] != *(unsigned char*)&x ){
   318    326             int ii;
   319         -          for(ii=0; ii<nVertex*2; ii++){
   320         -            geopolySwab32((unsigned char*)&p->a[ii]);
          327  +          for(ii=0; ii<nVertex; ii++){
          328  +            geopolySwab32((unsigned char*)&GeoX(p,ii));
          329  +            geopolySwab32((unsigned char*)&GeoY(p,ii));
   321    330             }
   322    331             p->hdr[0] ^= 1;
   323    332           }
   324    333         }
   325    334       }
   326    335       if( pRc ) *pRc = SQLITE_OK;
   327    336       return p;
................................................................................
   372    381     GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
   373    382     if( p ){
   374    383       sqlite3 *db = sqlite3_context_db_handle(context);
   375    384       sqlite3_str *x = sqlite3_str_new(db);
   376    385       int i;
   377    386       sqlite3_str_append(x, "[", 1);
   378    387       for(i=0; i<p->nVertex; i++){
   379         -      sqlite3_str_appendf(x, "[%!g,%!g],", p->a[i*2], p->a[i*2+1]);
          388  +      sqlite3_str_appendf(x, "[%!g,%!g],", GeoX(p,i), GeoY(p,i));
   380    389       }
   381         -    sqlite3_str_appendf(x, "[%!g,%!g]]", p->a[0], p->a[1]);
          390  +    sqlite3_str_appendf(x, "[%!g,%!g]]", GeoX(p,0), GeoY(p,0));
   382    391       sqlite3_result_text(context, sqlite3_str_finish(x), -1, sqlite3_free);
   383    392       sqlite3_free(p);
   384    393     }
   385    394   }
   386    395   
   387    396   /*
   388    397   ** SQL function:     geopoly_svg(X, ....)
................................................................................
   401    410     if( p ){
   402    411       sqlite3 *db = sqlite3_context_db_handle(context);
   403    412       sqlite3_str *x = sqlite3_str_new(db);
   404    413       int i;
   405    414       char cSep = '\'';
   406    415       sqlite3_str_appendf(x, "<polyline points=");
   407    416       for(i=0; i<p->nVertex; i++){
   408         -      sqlite3_str_appendf(x, "%c%g,%g", cSep, p->a[i*2], p->a[i*2+1]);
          417  +      sqlite3_str_appendf(x, "%c%g,%g", cSep, GeoX(p,i), GeoY(p,i));
   409    418         cSep = ' ';
   410    419       }
   411         -    sqlite3_str_appendf(x, " %g,%g'", p->a[0], p->a[1]);
          420  +    sqlite3_str_appendf(x, " %g,%g'", GeoX(p,0), GeoY(p,0));
   412    421       for(i=1; i<argc; i++){
   413    422         const char *z = (const char*)sqlite3_value_text(argv[i]);
   414    423         if( z && z[0] ){
   415    424           sqlite3_str_appendf(x, " %s", z);
   416    425         }
   417    426       }
   418    427       sqlite3_str_appendf(x, "></polyline>");
................................................................................
   449    458     double D = sqlite3_value_double(argv[4]);
   450    459     double E = sqlite3_value_double(argv[5]);
   451    460     double F = sqlite3_value_double(argv[6]);
   452    461     GeoCoord x1, y1, x0, y0;
   453    462     int ii;
   454    463     if( p ){
   455    464       for(ii=0; ii<p->nVertex; ii++){
   456         -      x0 = p->a[ii*2];
   457         -      y0 = p->a[ii*2+1];
          465  +      x0 = GeoX(p,ii);
          466  +      y0 = GeoY(p,ii);
   458    467         x1 = (GeoCoord)(A*x0 + B*y0 + E);
   459    468         y1 = (GeoCoord)(C*x0 + D*y0 + F);
   460         -      p->a[ii*2] = x1;
   461         -      p->a[ii*2+1] = y1;
          469  +      GeoX(p,ii) = x1;
          470  +      GeoY(p,ii) = y1;
   462    471       }
   463    472       sqlite3_result_blob(context, p->hdr, 
   464    473          4+8*p->nVertex, SQLITE_TRANSIENT);
   465    474       sqlite3_free(p);
   466    475     }
   467    476   }
   468    477   
................................................................................
   473    482   ** the wrong direction.  Polygons are suppose to be counter-clockwise (CCW).
   474    483   ** This routine returns a negative value for clockwise (CW) polygons.
   475    484   */
   476    485   static double geopolyArea(GeoPoly *p){
   477    486     double rArea = 0.0;
   478    487     int ii;
   479    488     for(ii=0; ii<p->nVertex-1; ii++){
   480         -    rArea += (p->a[ii*2] - p->a[ii*2+2])           /* (x0 - x1) */
   481         -              * (p->a[ii*2+1] + p->a[ii*2+3])      /* (y0 + y1) */
          489  +    rArea += (GeoX(p,ii) - GeoX(p,ii+1))           /* (x0 - x1) */
          490  +              * (GeoY(p,ii) + GeoY(p,ii+1))        /* (y0 + y1) */
   482    491                 * 0.5;
   483    492     }
   484         -  rArea += (p->a[ii*2] - p->a[0])                  /* (xN - x0) */
   485         -           * (p->a[ii*2+1] + p->a[1])              /* (yN + y0) */
          493  +  rArea += (GeoX(p,ii) - GeoX(p,0))                /* (xN - x0) */
          494  +           * (GeoY(p,ii) + GeoY(p,0))              /* (yN + y0) */
   486    495              * 0.5;
   487    496     return rArea;
   488    497   }
   489    498   
   490    499   /*
   491    500   ** Implementation of the geopoly_area(X) function.
   492    501   **
................................................................................
   525    534     int argc,
   526    535     sqlite3_value **argv
   527    536   ){
   528    537     GeoPoly *p = geopolyFuncParam(context, argv[0], 0);
   529    538     if( p ){
   530    539       if( geopolyArea(p)<0.0 ){
   531    540         int ii, jj;
   532         -      for(ii=2, jj=p->nVertex*2 - 2; ii<jj; ii+=2, jj-=2){
   533         -        GeoCoord t = p->a[ii];
   534         -        p->a[ii] = p->a[jj];
   535         -        p->a[jj] = t;
   536         -        t = p->a[ii+1];
   537         -        p->a[ii+1] = p->a[jj+1];
   538         -        p->a[jj+1] = t;
          541  +      for(ii=1, jj=p->nVertex-1; ii<jj; ii++, jj--){
          542  +        GeoCoord t = GeoX(p,ii);
          543  +        GeoX(p,ii) = GeoX(p,jj);
          544  +        GeoX(p,jj) = t;
          545  +        t = GeoY(p,ii);
          546  +        GeoY(p,ii) = GeoY(p,jj);
          547  +        GeoY(p,jj) = t;
   539    548         }
   540    549       }
   541    550       sqlite3_result_blob(context, p->hdr, 
   542    551          4+8*p->nVertex, SQLITE_TRANSIENT);
   543    552       sqlite3_free(p);
   544    553     }            
   545    554   }
................................................................................
   591    600     i = 1;
   592    601     p->hdr[0] = *(unsigned char*)&i;
   593    602     p->hdr[1] = 0;
   594    603     p->hdr[2] = (n>>8)&0xff;
   595    604     p->hdr[3] = n&0xff;
   596    605     for(i=0; i<n; i++){
   597    606       double rAngle = 2.0*GEOPOLY_PI*i/n;
   598         -    p->a[i*2] = x - r*geopolySine(rAngle-0.5*GEOPOLY_PI);
   599         -    p->a[i*2+1] = y + r*geopolySine(rAngle);
          607  +    GeoX(p,i) = x - r*geopolySine(rAngle-0.5*GEOPOLY_PI);
          608  +    GeoY(p,i) = y + r*geopolySine(rAngle);
   600    609     }
   601    610     sqlite3_result_blob(context, p->hdr, 4+8*n, SQLITE_TRANSIENT);
   602    611     sqlite3_free(p);
   603    612   }
   604    613   
   605    614   /*
   606    615   ** If pPoly is a polygon, compute its bounding box. Then:
................................................................................
   629    638       mxY = aCoord[3].f;
   630    639       goto geopolyBboxFill;
   631    640     }else{
   632    641       p = geopolyFuncParam(context, pPoly, pRc);
   633    642     }
   634    643     if( p ){
   635    644       int ii;
   636         -    mnX = mxX = p->a[0];
   637         -    mnY = mxY = p->a[1];
          645  +    mnX = mxX = GeoX(p,0);
          646  +    mnY = mxY = GeoY(p,0);
   638    647       for(ii=1; ii<p->nVertex; ii++){
   639         -      double r = p->a[ii*2];
          648  +      double r = GeoX(p,ii);
   640    649         if( r<mnX ) mnX = (float)r;
   641    650         else if( r>mxX ) mxX = (float)r;
   642         -      r = p->a[ii*2+1];
          651  +      r = GeoY(p,ii);
   643    652         if( r<mnY ) mnY = (float)r;
   644    653         else if( r>mxY ) mxY = (float)r;
   645    654       }
   646    655       if( pRc ) *pRc = SQLITE_OK;
   647    656       if( aCoord==0 ){
   648    657         geopolyBboxFill:
   649    658         pOut = sqlite3_realloc(p, GEOPOLY_SZ(4));
................................................................................
   655    664         }
   656    665         pOut->nVertex = 4;
   657    666         ii = 1;
   658    667         pOut->hdr[0] = *(unsigned char*)&ii;
   659    668         pOut->hdr[1] = 0;
   660    669         pOut->hdr[2] = 0;
   661    670         pOut->hdr[3] = 4;
   662         -      pOut->a[0] = mnX;
   663         -      pOut->a[1] = mnY;
   664         -      pOut->a[2] = mxX;
   665         -      pOut->a[3] = mnY;
   666         -      pOut->a[4] = mxX;
   667         -      pOut->a[5] = mxY;
   668         -      pOut->a[6] = mnX;
   669         -      pOut->a[7] = mxY;
          671  +      GeoX(pOut,0) = mnX;
          672  +      GeoY(pOut,0) = mnY;
          673  +      GeoX(pOut,1) = mxX;
          674  +      GeoY(pOut,1) = mnY;
          675  +      GeoX(pOut,2) = mxX;
          676  +      GeoY(pOut,2) = mxY;
          677  +      GeoX(pOut,3) = mnX;
          678  +      GeoY(pOut,3) = mxY;
   670    679       }else{
   671    680         sqlite3_free(p);
   672    681         aCoord[0].f = mnX;
   673    682         aCoord[1].f = mxX;
   674    683         aCoord[2].f = mnY;
   675    684         aCoord[3].f = mxY;
   676    685       }
................................................................................
   800    809     double x0 = sqlite3_value_double(argv[1]);
   801    810     double y0 = sqlite3_value_double(argv[2]);
   802    811     int v = 0;
   803    812     int cnt = 0;
   804    813     int ii;
   805    814     if( p1==0 ) return;
   806    815     for(ii=0; ii<p1->nVertex-1; ii++){
   807         -    v = pointBeneathLine(x0,y0,p1->a[ii*2],p1->a[ii*2+1],
   808         -                               p1->a[ii*2+2],p1->a[ii*2+3]);
          816  +    v = pointBeneathLine(x0,y0,GeoX(p1,ii), GeoY(p1,ii),
          817  +                               GeoX(p1,ii+1),GeoY(p1,ii+1));
   809    818       if( v==2 ) break;
   810    819       cnt += v;
   811    820     }
   812    821     if( v!=2 ){
   813         -    v = pointBeneathLine(x0,y0,p1->a[ii*2],p1->a[ii*2+1],
   814         -                               p1->a[0],p1->a[1]);
          822  +    v = pointBeneathLine(x0,y0,GeoX(p1,ii), GeoY(p1,ii),
          823  +                               GeoX(p1,0),  GeoY(p1,0));
   815    824     }
   816    825     if( v==2 ){
   817    826       sqlite3_result_int(context, 1);
   818    827     }else if( ((v+cnt)&1)==0 ){
   819    828       sqlite3_result_int(context, 0);
   820    829     }else{
   821    830       sqlite3_result_int(context, 2);
................................................................................
   929    938     GeoOverlap *p,          /* Add segments to this Overlap object */
   930    939     GeoPoly *pPoly,         /* Take all segments from this polygon */
   931    940     unsigned char side      /* The side of pPoly */
   932    941   ){
   933    942     unsigned int i;
   934    943     GeoCoord *x;
   935    944     for(i=0; i<(unsigned)pPoly->nVertex-1; i++){
   936         -    x = pPoly->a + (i*2);
          945  +    x = &GeoX(pPoly,i);
   937    946       geopolyAddOneSegment(p, x[0], x[1], x[2], x[3], side, i);
   938    947     }
   939         -  x = pPoly->a + (i*2);
          948  +  x = &GeoX(pPoly,i);
   940    949     geopolyAddOneSegment(p, x[0], x[1], pPoly->a[0], pPoly->a[1], side, i);
   941    950   }
   942    951   
   943    952   /*
   944    953   ** Merge two lists of sorted events by X coordinate
   945    954   */
   946    955   static GeoEvent *geopolyEventMerge(GeoEvent *pLeft, GeoEvent *pRight){

Changes to ext/rtree/rtree.c.

  1996   1996         case 2:  area *= p->aCoord[3].f - p->aCoord[2].f;
  1997   1997         default: area *= p->aCoord[1].f - p->aCoord[0].f;
  1998   1998       }
  1999   1999     }else
  2000   2000   #endif
  2001   2001     {
  2002   2002       switch( pRtree->nDim ){
  2003         -      case 5:  area  = p->aCoord[9].i - p->aCoord[8].i;
  2004         -      case 4:  area *= p->aCoord[7].i - p->aCoord[6].i;
  2005         -      case 3:  area *= p->aCoord[5].i - p->aCoord[4].i;
  2006         -      case 2:  area *= p->aCoord[3].i - p->aCoord[2].i;
  2007         -      default: area *= p->aCoord[1].i - p->aCoord[0].i;
         2003  +      case 5:  area  = (i64)p->aCoord[9].i - (i64)p->aCoord[8].i;
         2004  +      case 4:  area *= (i64)p->aCoord[7].i - (i64)p->aCoord[6].i;
         2005  +      case 3:  area *= (i64)p->aCoord[5].i - (i64)p->aCoord[4].i;
         2006  +      case 2:  area *= (i64)p->aCoord[3].i - (i64)p->aCoord[2].i;
         2007  +      default: area *= (i64)p->aCoord[1].i - (i64)p->aCoord[0].i;
  2008   2008       }
  2009   2009     }
  2010   2010     return area;
  2011   2011   }
  2012   2012   
  2013   2013   /*
  2014   2014   ** Return the margin length of cell p. The margin length is the sum

Changes to main.mk.

   511    511   FUZZDATA = \
   512    512     $(TOP)/test/fuzzdata1.db \
   513    513     $(TOP)/test/fuzzdata2.db \
   514    514     $(TOP)/test/fuzzdata3.db \
   515    515     $(TOP)/test/fuzzdata4.db \
   516    516     $(TOP)/test/fuzzdata5.db \
   517    517     $(TOP)/test/fuzzdata6.db \
   518         -  $(TOP)/test/fuzzdata7.db
          518  +  $(TOP)/test/fuzzdata7.db \
          519  +  $(TOP)/test/fuzzdata8.db
   519    520   
   520    521   # Standard options to testfixture
   521    522   #
   522    523   TESTOPTS = --verbose=file --output=test-out.txt
   523    524   
   524    525   # Extra compiler options for various shell tools
   525    526   #
................................................................................
   532    533   SHELL_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
   533    534   SHELL_OPT += -DSQLITE_ENABLE_OFFSET_SQL_FUNC
   534    535   SHELL_OPT += -DSQLITE_INTROSPECTION_PRAGMAS
   535    536   FUZZERSHELL_OPT = -DSQLITE_ENABLE_JSON1
   536    537   FUZZCHECK_OPT = -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_MEMSYS5
   537    538   FUZZCHECK_OPT += -DSQLITE_MAX_MEMORY=50000000
   538    539   FUZZCHECK_OPT += -DSQLITE_PRINTF_PRECISION_LIMIT=1000
          540  +FUZZCHECK_OPT += -DSQLITE_ENABLE_DESERIALIZE
          541  +FUZZCHECK_OPT += -DSQLITE_ENABLE_FTS4
          542  +FUZZCHECK_OPT += -DSQLITE_ENABLE_RTREE
          543  +FUZZCHECK_OPT += -DSQLITE_ENABLE_GEOPOLY
          544  +FUZZCHECK_OPT += -DSQLITE_ENABLE_DBSTAT_VTAB
   539    545   DBFUZZ_OPT =
   540    546   KV_OPT = -DSQLITE_THREADSAFE=0 -DSQLITE_DIRECT_OVERFLOW_READ
   541    547   ST_OPT = -DSQLITE_THREADSAFE=0
   542    548   
   543    549   # This is the default Makefile target.  The objects listed here
   544    550   # are what get build when you type just "make" with no arguments.
   545    551   #
................................................................................
   735    741   	$(TOP)/ext/misc/shathree.c \
   736    742   	$(TOP)/ext/misc/fileio.c \
   737    743   	$(TOP)/ext/misc/completion.c \
   738    744   	$(TOP)/ext/misc/sqlar.c \
   739    745   	$(TOP)/ext/expert/sqlite3expert.c \
   740    746   	$(TOP)/ext/expert/sqlite3expert.h \
   741    747   	$(TOP)/ext/misc/zipfile.c \
          748  +	$(TOP)/ext/misc/memtrace.c \
   742    749           $(TOP)/src/test_windirent.c
   743    750   
   744    751   shell.c:	$(SHELL_SRC) $(TOP)/tool/mkshellc.tcl
   745    752   	tclsh $(TOP)/tool/mkshellc.tcl >shell.c
   746    753   
   747    754   
   748    755   

Changes to src/alter.c.

  1077   1077   ** message in the Parse object.
  1078   1078   */
  1079   1079   static int renameResolveTrigger(Parse *pParse, const char *zDb){
  1080   1080     sqlite3 *db = pParse->db;
  1081   1081     Trigger *pNew = pParse->pNewTrigger;
  1082   1082     TriggerStep *pStep;
  1083   1083     NameContext sNC;
  1084         -  SrcList sSrc;
  1085   1084     int rc = SQLITE_OK;
  1086   1085   
  1087   1086     memset(&sNC, 0, sizeof(sNC));
  1088   1087     sNC.pParse = pParse;
  1089   1088     assert( pNew->pTabSchema );
  1090   1089     pParse->pTriggerTab = sqlite3FindTable(db, pNew->table, 
  1091   1090         db->aDb[sqlite3SchemaToIndex(db, pNew->pTabSchema)].zDbSName
................................................................................
  1108   1107         if( pParse->nErr ) rc = pParse->rc;
  1109   1108       }
  1110   1109       if( rc==SQLITE_OK && pStep->zTarget ){
  1111   1110         Table *pTarget = sqlite3LocateTable(pParse, 0, pStep->zTarget, zDb);
  1112   1111         if( pTarget==0 ){
  1113   1112           rc = SQLITE_ERROR;
  1114   1113         }else if( SQLITE_OK==(rc = sqlite3ViewGetColumnNames(pParse, pTarget)) ){
         1114  +        SrcList sSrc;
  1115   1115           memset(&sSrc, 0, sizeof(sSrc));
  1116   1116           sSrc.nSrc = 1;
  1117   1117           sSrc.a[0].zName = pStep->zTarget;
  1118   1118           sSrc.a[0].pTab = pTarget;
  1119   1119           sNC.pSrcList = &sSrc;
  1120   1120           if( pStep->pWhere ){
  1121   1121             rc = sqlite3ResolveExprNames(&sNC, pStep->pWhere);
................................................................................
  1139   1139               rc = sqlite3ResolveExprNames(&sNC, pUpsert->pUpsertWhere);
  1140   1140             }
  1141   1141             if( rc==SQLITE_OK ){
  1142   1142               rc = sqlite3ResolveExprNames(&sNC, pUpsert->pUpsertTargetWhere);
  1143   1143             }
  1144   1144             sNC.ncFlags = 0;
  1145   1145           }
         1146  +        sNC.pSrcList = 0;
  1146   1147         }
  1147   1148       }
  1148   1149     }
  1149   1150     return rc;
  1150   1151   }
  1151   1152   
  1152   1153   /*

Changes to src/btree.c.

   674    674       ** below. */
   675    675       void *pKey;
   676    676       pCur->nKey = sqlite3BtreePayloadSize(pCur);
   677    677       pKey = sqlite3Malloc( pCur->nKey + 9 + 8 );
   678    678       if( pKey ){
   679    679         rc = sqlite3BtreePayload(pCur, 0, (int)pCur->nKey, pKey);
   680    680         if( rc==SQLITE_OK ){
          681  +        memset(((u8*)pKey)+pCur->nKey, 0, 9+8);
   681    682           pCur->pKey = pKey;
   682    683         }else{
   683    684           sqlite3_free(pKey);
   684    685         }
   685    686       }else{
   686    687         rc = SQLITE_NOMEM_BKPT;
   687    688       }
................................................................................
   805    806     int bias,           /* Bias search to the high end */
   806    807     int *pRes           /* Write search results here */
   807    808   ){
   808    809     int rc;                    /* Status code */
   809    810     UnpackedRecord *pIdxKey;   /* Unpacked index key */
   810    811   
   811    812     if( pKey ){
          813  +    KeyInfo *pKeyInfo = pCur->pKeyInfo;
   812    814       assert( nKey==(i64)(int)nKey );
   813         -    pIdxKey = sqlite3VdbeAllocUnpackedRecord(pCur->pKeyInfo);
          815  +    pIdxKey = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
   814    816       if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
   815         -    sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
   816         -    if( pIdxKey->nField==0 ){
          817  +    sqlite3VdbeRecordUnpack(pKeyInfo, (int)nKey, pKey, pIdxKey);
          818  +    if( pIdxKey->nField==0 || pIdxKey->nField>pKeyInfo->nAllField ){
   817    819         rc = SQLITE_CORRUPT_BKPT;
   818    820         goto moveto_done;
   819    821       }
   820    822     }else{
   821    823       pIdxKey = 0;
   822    824     }
   823    825     rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
................................................................................
   845    847     }
   846    848     pCur->eState = CURSOR_INVALID;
   847    849     rc = btreeMoveto(pCur, pCur->pKey, pCur->nKey, 0, &skipNext);
   848    850     if( rc==SQLITE_OK ){
   849    851       sqlite3_free(pCur->pKey);
   850    852       pCur->pKey = 0;
   851    853       assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_INVALID );
   852         -    pCur->skipNext |= skipNext;
          854  +    if( skipNext ) pCur->skipNext = skipNext;
   853    855       if( pCur->skipNext && pCur->eState==CURSOR_VALID ){
   854    856         pCur->eState = CURSOR_SKIPNEXT;
   855    857       }
   856    858     }
   857    859     return rc;
   858    860   }
   859    861   
................................................................................
   915    917     if( rc ){
   916    918       *pDifferentRow = 1;
   917    919       return rc;
   918    920     }
   919    921     if( pCur->eState!=CURSOR_VALID ){
   920    922       *pDifferentRow = 1;
   921    923     }else{
   922         -    assert( pCur->skipNext==0 );
   923    924       *pDifferentRow = 0;
   924    925     }
   925    926     return SQLITE_OK;
   926    927   }
   927    928   
   928    929   #ifdef SQLITE_ENABLE_CURSOR_HINTS
   929    930   /*
................................................................................
  5334   5335           *pRes = -1;
  5335   5336           return SQLITE_OK;
  5336   5337         }
  5337   5338         /* If the requested key is one more than the previous key, then
  5338   5339         ** try to get there using sqlite3BtreeNext() rather than a full
  5339   5340         ** binary search.  This is an optimization only.  The correct answer
  5340   5341         ** is still obtained without this case, only a little more slowely */
  5341         -      if( pCur->info.nKey+1==intKey && !pCur->skipNext ){
         5342  +      if( pCur->info.nKey+1==intKey ){
  5342   5343           *pRes = 0;
  5343   5344           rc = sqlite3BtreeNext(pCur, 0);
  5344   5345           if( rc==SQLITE_OK ){
  5345   5346             getCellInfo(pCur);
  5346   5347             if( pCur->info.nKey==intKey ){
  5347   5348               return SQLITE_OK;
  5348   5349             }
................................................................................
  5476   5477             u8 * const pCellBody = pCell - pPage->childPtrSize;
  5477   5478             pPage->xParseCell(pPage, pCellBody, &pCur->info);
  5478   5479             nCell = (int)pCur->info.nKey;
  5479   5480             testcase( nCell<0 );   /* True if key size is 2^32 or more */
  5480   5481             testcase( nCell==0 );  /* Invalid key size:  0x80 0x80 0x00 */
  5481   5482             testcase( nCell==1 );  /* Invalid key size:  0x80 0x80 0x01 */
  5482   5483             testcase( nCell==2 );  /* Minimum legal index key size */
  5483         -          if( nCell<2 ){
         5484  +          if( nCell<2 || nCell/pCur->pBt->usableSize>pCur->pBt->nPage ){
  5484   5485               rc = SQLITE_CORRUPT_PAGE(pPage);
  5485   5486               goto moveto_finish;
  5486   5487             }
  5487   5488             pCellKey = sqlite3Malloc( nCell+18 );
  5488   5489             if( pCellKey==0 ){
  5489   5490               rc = SQLITE_NOMEM_BKPT;
  5490   5491               goto moveto_finish;
................................................................................
  5608   5609   */
  5609   5610   static SQLITE_NOINLINE int btreeNext(BtCursor *pCur){
  5610   5611     int rc;
  5611   5612     int idx;
  5612   5613     MemPage *pPage;
  5613   5614   
  5614   5615     assert( cursorOwnsBtShared(pCur) );
  5615         -  assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
  5616   5616     if( pCur->eState!=CURSOR_VALID ){
  5617   5617       assert( (pCur->curFlags & BTCF_ValidOvfl)==0 );
  5618   5618       rc = restoreCursorPosition(pCur);
  5619   5619       if( rc!=SQLITE_OK ){
  5620   5620         return rc;
  5621   5621       }
  5622   5622       if( CURSOR_INVALID==pCur->eState ){
  5623   5623         return SQLITE_DONE;
  5624   5624       }
  5625         -    if( pCur->skipNext ){
  5626         -      assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT );
         5625  +    if( pCur->eState==CURSOR_SKIPNEXT ){
  5627   5626         pCur->eState = CURSOR_VALID;
  5628         -      if( pCur->skipNext>0 ){
  5629         -        pCur->skipNext = 0;
  5630         -        return SQLITE_OK;
  5631         -      }
  5632         -      pCur->skipNext = 0;
         5627  +      if( pCur->skipNext>0 ) return SQLITE_OK;
  5633   5628       }
  5634   5629     }
  5635   5630   
  5636   5631     pPage = pCur->pPage;
  5637   5632     idx = ++pCur->ix;
  5638   5633     if( !pPage->isInit ){
  5639   5634       /* The only known way for this to happen is for there to be a
................................................................................
  5680   5675     }
  5681   5676   }
  5682   5677   int sqlite3BtreeNext(BtCursor *pCur, int flags){
  5683   5678     MemPage *pPage;
  5684   5679     UNUSED_PARAMETER( flags );  /* Used in COMDB2 but not native SQLite */
  5685   5680     assert( cursorOwnsBtShared(pCur) );
  5686   5681     assert( flags==0 || flags==1 );
  5687         -  assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
  5688   5682     pCur->info.nSize = 0;
  5689   5683     pCur->curFlags &= ~(BTCF_ValidNKey|BTCF_ValidOvfl);
  5690   5684     if( pCur->eState!=CURSOR_VALID ) return btreeNext(pCur);
  5691   5685     pPage = pCur->pPage;
  5692   5686     if( (++pCur->ix)>=pPage->nCell ){
  5693   5687       pCur->ix--;
  5694   5688       return btreeNext(pCur);
................................................................................
  5721   5715   ** use this hint, but COMDB2 does.
  5722   5716   */
  5723   5717   static SQLITE_NOINLINE int btreePrevious(BtCursor *pCur){
  5724   5718     int rc;
  5725   5719     MemPage *pPage;
  5726   5720   
  5727   5721     assert( cursorOwnsBtShared(pCur) );
  5728         -  assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
  5729   5722     assert( (pCur->curFlags & (BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey))==0 );
  5730   5723     assert( pCur->info.nSize==0 );
  5731   5724     if( pCur->eState!=CURSOR_VALID ){
  5732   5725       rc = restoreCursorPosition(pCur);
  5733   5726       if( rc!=SQLITE_OK ){
  5734   5727         return rc;
  5735   5728       }
  5736   5729       if( CURSOR_INVALID==pCur->eState ){
  5737   5730         return SQLITE_DONE;
  5738   5731       }
  5739         -    if( pCur->skipNext ){
  5740         -      assert( pCur->eState==CURSOR_VALID || pCur->eState==CURSOR_SKIPNEXT );
         5732  +    if( CURSOR_SKIPNEXT==pCur->eState ){
  5741   5733         pCur->eState = CURSOR_VALID;
  5742         -      if( pCur->skipNext<0 ){
  5743         -        pCur->skipNext = 0;
  5744         -        return SQLITE_OK;
  5745         -      }
  5746         -      pCur->skipNext = 0;
         5734  +      if( pCur->skipNext<0 ) return SQLITE_OK;
  5747   5735       }
  5748   5736     }
  5749   5737   
  5750   5738     pPage = pCur->pPage;
  5751   5739     assert( pPage->isInit );
  5752   5740     if( !pPage->leaf ){
  5753   5741       int idx = pCur->ix;
................................................................................
  5774   5762       }
  5775   5763     }
  5776   5764     return rc;
  5777   5765   }
  5778   5766   int sqlite3BtreePrevious(BtCursor *pCur, int flags){
  5779   5767     assert( cursorOwnsBtShared(pCur) );
  5780   5768     assert( flags==0 || flags==1 );
  5781         -  assert( pCur->skipNext==0 || pCur->eState!=CURSOR_VALID );
  5782   5769     UNUSED_PARAMETER( flags );  /* Used in COMDB2 but not native SQLite */
  5783   5770     pCur->curFlags &= ~(BTCF_AtLast|BTCF_ValidOvfl|BTCF_ValidNKey);
  5784   5771     pCur->info.nSize = 0;
  5785   5772     if( pCur->eState!=CURSOR_VALID
  5786   5773      || pCur->ix==0
  5787   5774      || pCur->pPage->leaf==0
  5788   5775     ){
................................................................................
  6110   6097       if( rc!=SQLITE_OK ){
  6111   6098         releasePage(*ppPage);
  6112   6099         *ppPage = 0;
  6113   6100       }
  6114   6101       TRACE(("ALLOCATE: %d from end of file\n", *pPgno));
  6115   6102     }
  6116   6103   
  6117         -  assert( *pPgno!=PENDING_BYTE_PAGE(pBt) );
         6104  +  assert( CORRUPT_DB || *pPgno!=PENDING_BYTE_PAGE(pBt) );
  6118   6105   
  6119   6106   end_allocate_page:
  6120   6107     releasePage(pTrunk);
  6121   6108     releasePage(pPrevTrunk);
  6122   6109     assert( rc!=SQLITE_OK || sqlite3PagerPageRefcount((*ppPage)->pDbPage)<=1 );
  6123   6110     assert( rc!=SQLITE_OK || (*ppPage)->isInit==0 );
  6124   6111     return rc;
................................................................................
  6694   6681         */
  6695   6682         ptrmapPutOvflPtr(pPage, pPage, pCell, pRC);
  6696   6683       }
  6697   6684   #endif
  6698   6685     }
  6699   6686   }
  6700   6687   
         6688  +/*
         6689  +** The following parameters determine how many adjacent pages get involved
         6690  +** in a balancing operation.  NN is the number of neighbors on either side
         6691  +** of the page that participate in the balancing operation.  NB is the
         6692  +** total number of pages that participate, including the target page and
         6693  +** NN neighbors on either side.
         6694  +**
         6695  +** The minimum value of NN is 1 (of course).  Increasing NN above 1
         6696  +** (to 2 or 3) gives a modest improvement in SELECT and DELETE performance
         6697  +** in exchange for a larger degradation in INSERT and UPDATE performance.
         6698  +** The value of NN appears to give the best results overall.
         6699  +**
         6700  +** (Later:) The description above makes it seem as if these values are
         6701  +** tunable - as if you could change them and recompile and it would all work.
         6702  +** But that is unlikely.  NB has been 3 since the inception of SQLite and
         6703  +** we have never tested any other value.
         6704  +*/
         6705  +#define NN 1             /* Number of neighbors on either side of pPage */
         6706  +#define NB 3             /* (NN*2+1): Total pages involved in the balance */
         6707  +
  6701   6708   /*
  6702   6709   ** A CellArray object contains a cache of pointers and sizes for a
  6703   6710   ** consecutive sequence of cells that might be held on multiple pages.
         6711  +**
         6712  +** The cells in this array are the divider cell or cells from the pParent
         6713  +** page plus up to three child pages.  There are a total of nCell cells.
         6714  +**
         6715  +** pRef is a pointer to one of the pages that contributes cells.  This is
         6716  +** used to access information such as MemPage.intKey and MemPage.pBt->pageSize
         6717  +** which should be common to all pages that contribute cells to this array.
         6718  +**
         6719  +** apCell[] and szCell[] hold, respectively, pointers to the start of each
         6720  +** cell and the size of each cell.  Some of the apCell[] pointers might refer
         6721  +** to overflow cells.  In other words, some apCel[] pointers might not point
         6722  +** to content area of the pages.
         6723  +**
         6724  +** A szCell[] of zero means the size of that cell has not yet been computed.
         6725  +**
         6726  +** The cells come from as many as four different pages:
         6727  +**
         6728  +**             -----------
         6729  +**             | Parent  |
         6730  +**             -----------
         6731  +**            /     |     \
         6732  +**           /      |      \
         6733  +**  ---------   ---------   ---------
         6734  +**  |Child-1|   |Child-2|   |Child-3|
         6735  +**  ---------   ---------   ---------
         6736  +**
         6737  +** The order of cells is in the array is:
         6738  +**
         6739  +**       1.  All cells from Child-1 in order
         6740  +**       2.  The first divider cell from Parent
         6741  +**       3.  All cells from Child-2 in order
         6742  +**       4.  The second divider cell from Parent
         6743  +**       5.  All cells from Child-3 in order
         6744  +**
         6745  +** The apEnd[] array holds pointer to the end of page for Child-1, the
         6746  +** Parent, Child-2, the Parent (again), and Child-3.  The ixNx[] array
         6747  +** holds the number of cells contained in each of these 5 stages, and
         6748  +** all stages to the left.  Hence:
         6749  +**    ixNx[0] = Number of cells in Child-1.
         6750  +**    ixNx[1] = Number of cells in Child-1 plus 1 for first divider.
         6751  +**    ixNx[2] = Number of cells in Child-1 and Child-2 + 1 for 1st divider.
         6752  +**    ixNx[3] = Number of cells in Child-1 and Child-2 + both divider cells
         6753  +**    ixNx[4] = Total number of cells.
  6704   6754   */
  6705   6755   typedef struct CellArray CellArray;
  6706   6756   struct CellArray {
  6707   6757     int nCell;              /* Number of cells in apCell[] */
  6708   6758     MemPage *pRef;          /* Reference page */
  6709   6759     u8 **apCell;            /* All cells begin balanced */
  6710   6760     u16 *szCell;            /* Local size of all cells in apCell[] */
         6761  +  u8 *apEnd[NB*2];        /* MemPage.aDataEnd values */
         6762  +  int ixNx[NB*2];         /* Index of at which we move to the next apEnd[] */
  6711   6763   };
  6712   6764   
  6713   6765   /*
  6714   6766   ** Make sure the cell sizes at idx, idx+1, ..., idx+N-1 have been
  6715   6767   ** computed.
  6716   6768   */
  6717   6769   static void populateCellCache(CellArray *p, int idx, int N){
................................................................................
  6754   6806   ** function works around problems caused by this by making a copy of any 
  6755   6807   ** such cells before overwriting the page data.
  6756   6808   **
  6757   6809   ** The MemPage.nFree field is invalidated by this function. It is the 
  6758   6810   ** responsibility of the caller to set it correctly.
  6759   6811   */
  6760   6812   static int rebuildPage(
  6761         -  MemPage *pPg,                   /* Edit this page */
         6813  +  CellArray *pCArray,             /* Content to be added to page pPg */
         6814  +  int iFirst,                     /* First cell in pCArray to use */
  6762   6815     int nCell,                      /* Final number of cells on page */
  6763         -  u8 **apCell,                    /* Array of cells */
  6764         -  u16 *szCell                     /* Array of cell sizes */
         6816  +  MemPage *pPg                    /* The page to be reconstructed */
  6765   6817   ){
  6766   6818     const int hdr = pPg->hdrOffset;          /* Offset of header on pPg */
  6767   6819     u8 * const aData = pPg->aData;           /* Pointer to data for pPg */
  6768   6820     const int usableSize = pPg->pBt->usableSize;
  6769   6821     u8 * const pEnd = &aData[usableSize];
  6770         -  int i;
         6822  +  int i = iFirst;                 /* Which cell to copy from pCArray*/
         6823  +  u32 j;                          /* Start of cell content area */
         6824  +  int iEnd = i+nCell;             /* Loop terminator */
  6771   6825     u8 *pCellptr = pPg->aCellIdx;
  6772   6826     u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
  6773   6827     u8 *pData;
         6828  +  int k;                          /* Current slot in pCArray->apEnd[] */
         6829  +  u8 *pSrcEnd;                    /* Current pCArray->apEnd[k] value */
  6774   6830   
  6775         -  i = get2byte(&aData[hdr+5]);
  6776         -  memcpy(&pTmp[i], &aData[i], usableSize - i);
         6831  +  assert( i<iEnd );
         6832  +  j = get2byte(&aData[hdr+5]);
         6833  +  if( NEVER(j>(u32)usableSize) ){ j = 0; }
         6834  +  memcpy(&pTmp[j], &aData[j], usableSize - j);
         6835  +
         6836  +  for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
         6837  +  pSrcEnd = pCArray->apEnd[k];
  6777   6838   
  6778   6839     pData = pEnd;
  6779         -  for(i=0; i<nCell; i++){
  6780         -    u8 *pCell = apCell[i];
         6840  +  while( 1/*exit by break*/ ){
         6841  +    u8 *pCell = pCArray->apCell[i];
         6842  +    u16 sz = pCArray->szCell[i];
         6843  +    assert( sz>0 );
  6781   6844       if( SQLITE_WITHIN(pCell,aData,pEnd) ){
  6782         -      if( ((uptr)(pCell+szCell[i]))>(uptr)pEnd ) return SQLITE_CORRUPT_BKPT;
         6845  +      if( ((uptr)(pCell+sz))>(uptr)pEnd ) return SQLITE_CORRUPT_BKPT;
  6783   6846         pCell = &pTmp[pCell - aData];
         6847  +    }else if( (uptr)(pCell+sz)>(uptr)pSrcEnd
         6848  +           && (uptr)(pCell)<(uptr)pSrcEnd
         6849  +    ){
         6850  +      return SQLITE_CORRUPT_BKPT;
  6784   6851       }
  6785         -    pData -= szCell[i];
         6852  +
         6853  +    pData -= sz;
  6786   6854       put2byte(pCellptr, (pData - aData));
  6787   6855       pCellptr += 2;
  6788   6856       if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT;
  6789         -    memcpy(pData, pCell, szCell[i]);
  6790         -    assert( szCell[i]==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
  6791         -    testcase( szCell[i]!=pPg->xCellSize(pPg,pCell) );
         6857  +    memcpy(pData, pCell, sz);
         6858  +    assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
         6859  +    testcase( sz!=pPg->xCellSize(pPg,pCell) );
         6860  +    i++;
         6861  +    if( i>=iEnd ) break;
         6862  +    if( pCArray->ixNx[k]<=i ){
         6863  +      k++;
         6864  +      pSrcEnd = pCArray->apEnd[k];
         6865  +    }
  6792   6866     }
  6793   6867   
  6794   6868     /* The pPg->nFree field is now set incorrectly. The caller will fix it. */
  6795   6869     pPg->nCell = nCell;
  6796   6870     pPg->nOverflow = 0;
  6797   6871   
  6798   6872     put2byte(&aData[hdr+1], 0);
................................................................................
  6799   6873     put2byte(&aData[hdr+3], pPg->nCell);
  6800   6874     put2byte(&aData[hdr+5], pData - aData);
  6801   6875     aData[hdr+7] = 0x00;
  6802   6876     return SQLITE_OK;
  6803   6877   }
  6804   6878   
  6805   6879   /*
  6806         -** Array apCell[] contains nCell pointers to b-tree cells. Array szCell
  6807         -** contains the size in bytes of each such cell. This function attempts to 
  6808         -** add the cells stored in the array to page pPg. If it cannot (because 
  6809         -** the page needs to be defragmented before the cells will fit), non-zero
  6810         -** is returned. Otherwise, if the cells are added successfully, zero is
  6811         -** returned.
         6880  +** The pCArray objects contains pointers to b-tree cells and the cell sizes.
         6881  +** This function attempts to add the cells stored in the array to page pPg.
         6882  +** If it cannot (because the page needs to be defragmented before the cells
         6883  +** will fit), non-zero is returned. Otherwise, if the cells are added
         6884  +** successfully, zero is returned.
  6812   6885   **
  6813   6886   ** Argument pCellptr points to the first entry in the cell-pointer array
  6814   6887   ** (part of page pPg) to populate. After cell apCell[0] is written to the
  6815   6888   ** page body, a 16-bit offset is written to pCellptr. And so on, for each
  6816   6889   ** cell in the array. It is the responsibility of the caller to ensure
  6817   6890   ** that it is safe to overwrite this part of the cell-pointer array.
  6818   6891   **
................................................................................
  6832   6905     u8 *pBegin,                     /* End of cell-pointer array */
  6833   6906     u8 **ppData,                    /* IN/OUT: Page content -area pointer */
  6834   6907     u8 *pCellptr,                   /* Pointer to cell-pointer area */
  6835   6908     int iFirst,                     /* Index of first cell to add */
  6836   6909     int nCell,                      /* Number of cells to add to pPg */
  6837   6910     CellArray *pCArray              /* Array of cells */
  6838   6911   ){
  6839         -  int i;
  6840         -  u8 *aData = pPg->aData;
  6841         -  u8 *pData = *ppData;
  6842         -  int iEnd = iFirst + nCell;
         6912  +  int i = iFirst;                 /* Loop counter - cell index to insert */
         6913  +  u8 *aData = pPg->aData;         /* Complete page */
         6914  +  u8 *pData = *ppData;            /* Content area.  A subset of aData[] */
         6915  +  int iEnd = iFirst + nCell;      /* End of loop. One past last cell to ins */
         6916  +  int k;                          /* Current slot in pCArray->apEnd[] */
         6917  +  u8 *pEnd;                       /* Maximum extent of cell data */
  6843   6918     assert( CORRUPT_DB || pPg->hdrOffset==0 );    /* Never called on page 1 */
  6844         -  for(i=iFirst; i<iEnd; i++){
         6919  +  if( iEnd<=iFirst ) return 0;
         6920  +  for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
         6921  +  pEnd = pCArray->apEnd[k];
         6922  +  while( 1 /*Exit by break*/ ){
  6845   6923       int sz, rc;
  6846   6924       u8 *pSlot;
  6847   6925       sz = cachedCellSize(pCArray, i);
  6848   6926       if( (aData[1]==0 && aData[2]==0) || (pSlot = pageFindSlot(pPg,sz,&rc))==0 ){
  6849   6927         if( (pData - pBegin)<sz ) return 1;
  6850   6928         pData -= sz;
  6851   6929         pSlot = pData;
................................................................................
  6852   6930       }
  6853   6931       /* pSlot and pCArray->apCell[i] will never overlap on a well-formed
  6854   6932       ** database.  But they might for a corrupt database.  Hence use memmove()
  6855   6933       ** since memcpy() sends SIGABORT with overlapping buffers on OpenBSD */
  6856   6934       assert( (pSlot+sz)<=pCArray->apCell[i]
  6857   6935            || pSlot>=(pCArray->apCell[i]+sz)
  6858   6936            || CORRUPT_DB );
         6937  +    if( (uptr)(pCArray->apCell[i]+sz)>(uptr)pEnd
         6938  +     && (uptr)(pCArray->apCell[i])<(uptr)pEnd
         6939  +    ){
         6940  +      assert( CORRUPT_DB );
         6941  +      (void)SQLITE_CORRUPT_BKPT;
         6942  +      return 1;
         6943  +    }
  6859   6944       memmove(pSlot, pCArray->apCell[i], sz);
  6860   6945       put2byte(pCellptr, (pSlot - aData));
  6861   6946       pCellptr += 2;
         6947  +    i++;
         6948  +    if( i>=iEnd ) break;
         6949  +    if( pCArray->ixNx[k]<=i ){
         6950  +      k++;
         6951  +      pEnd = pCArray->apEnd[k];
         6952  +    }
  6862   6953     }
  6863   6954     *ppData = pData;
  6864   6955     return 0;
  6865   6956   }
  6866   6957   
  6867   6958   /*
  6868         -** Array apCell[] contains nCell pointers to b-tree cells. Array szCell 
  6869         -** contains the size in bytes of each such cell. This function adds the
  6870         -** space associated with each cell in the array that is currently stored 
  6871         -** within the body of pPg to the pPg free-list. The cell-pointers and other
  6872         -** fields of the page are not updated.
         6959  +** The pCArray object contains pointers to b-tree cells and their sizes.
         6960  +**
         6961  +** This function adds the space associated with each cell in the array
         6962  +** that is currently stored within the body of pPg to the pPg free-list.
         6963  +** The cell-pointers and other fields of the page are not updated.
  6873   6964   **
  6874   6965   ** This function returns the total number of cells added to the free-list.
  6875   6966   */
  6876   6967   static int pageFreeArray(
  6877   6968     MemPage *pPg,                   /* Page to edit */
  6878   6969     int iFirst,                     /* First cell to delete */
  6879   6970     int nCell,                      /* Cells to delete */
................................................................................
  6915   7006       assert( pFree>aData && (pFree - aData)<65536 );
  6916   7007       freeSpace(pPg, (u16)(pFree - aData), szFree);
  6917   7008     }
  6918   7009     return nRet;
  6919   7010   }
  6920   7011   
  6921   7012   /*
  6922         -** apCell[] and szCell[] contains pointers to and sizes of all cells in the
  6923         -** pages being balanced.  The current page, pPg, has pPg->nCell cells starting
  6924         -** with apCell[iOld].  After balancing, this page should hold nNew cells
         7013  +** pCArray contains pointers to and sizes of all cells in the page being
         7014  +** balanced.  The current page, pPg, has pPg->nCell cells starting with
         7015  +** pCArray->apCell[iOld].  After balancing, this page should hold nNew cells
  6925   7016   ** starting at apCell[iNew].
  6926   7017   **
  6927   7018   ** This routine makes the necessary adjustments to pPg so that it contains
  6928   7019   ** the correct cells after being balanced.
  6929   7020   **
  6930   7021   ** The pPg->nFree field is invalid when this function returns. It is the
  6931   7022   ** responsibility of the caller to set it correctly.
................................................................................
  6949   7040   
  6950   7041   #ifdef SQLITE_DEBUG
  6951   7042     u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
  6952   7043     memcpy(pTmp, aData, pPg->pBt->usableSize);
  6953   7044   #endif
  6954   7045   
  6955   7046     /* Remove cells from the start and end of the page */
         7047  +  assert( nCell>=0 );
  6956   7048     if( iOld<iNew ){
  6957   7049       int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray);
         7050  +    if( nShift>nCell ) return SQLITE_CORRUPT_BKPT;
  6958   7051       memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
  6959   7052       nCell -= nShift;
  6960   7053     }
  6961   7054     if( iNewEnd < iOldEnd ){
  6962         -    nCell -= pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray);
         7055  +    int nTail = pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray);
         7056  +    assert( nCell>=nTail );
         7057  +    nCell -= nTail;
  6963   7058     }
  6964   7059   
  6965   7060     pData = &aData[get2byteNotZero(&aData[hdr+5])];
  6966   7061     if( pData<pBegin ) goto editpage_fail;
  6967   7062   
  6968   7063     /* Add cells to the start of the page */
  6969   7064     if( iNew<iOld ){
  6970   7065       int nAdd = MIN(nNew,iOld-iNew);
  6971   7066       assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
         7067  +    assert( nAdd>=0 );
  6972   7068       pCellptr = pPg->aCellIdx;
  6973   7069       memmove(&pCellptr[nAdd*2], pCellptr, nCell*2);
  6974   7070       if( pageInsertArray(
  6975   7071             pPg, pBegin, &pData, pCellptr,
  6976   7072             iNew, nAdd, pCArray
  6977   7073       ) ) goto editpage_fail;
  6978   7074       nCell += nAdd;
................................................................................
  6979   7075     }
  6980   7076   
  6981   7077     /* Add any overflow cells */
  6982   7078     for(i=0; i<pPg->nOverflow; i++){
  6983   7079       int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
  6984   7080       if( iCell>=0 && iCell<nNew ){
  6985   7081         pCellptr = &pPg->aCellIdx[iCell * 2];
         7082  +      assert( nCell>=iCell );
  6986   7083         memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
  6987   7084         nCell++;
  6988   7085         if( pageInsertArray(
  6989   7086               pPg, pBegin, &pData, pCellptr,
  6990   7087               iCell+iNew, 1, pCArray
  6991   7088         ) ) goto editpage_fail;
  6992   7089       }
  6993   7090     }
  6994   7091   
  6995   7092     /* Append cells to the end of the page */
         7093  +  assert( nCell>=0 );
  6996   7094     pCellptr = &pPg->aCellIdx[nCell*2];
  6997   7095     if( pageInsertArray(
  6998   7096           pPg, pBegin, &pData, pCellptr,
  6999   7097           iNew+nCell, nNew-nCell, pCArray
  7000   7098     ) ) goto editpage_fail;
  7001   7099   
  7002   7100     pPg->nCell = nNew;
................................................................................
  7017   7115     }
  7018   7116   #endif
  7019   7117   
  7020   7118     return SQLITE_OK;
  7021   7119    editpage_fail:
  7022   7120     /* Unable to edit this page. Rebuild it from scratch instead. */
  7023   7121     populateCellCache(pCArray, iNew, nNew);
  7024         -  return rebuildPage(pPg, nNew, &pCArray->apCell[iNew], &pCArray->szCell[iNew]);
         7122  +  return rebuildPage(pCArray, iNew, nNew, pPg);
  7025   7123   }
  7026   7124   
  7027         -/*
  7028         -** The following parameters determine how many adjacent pages get involved
  7029         -** in a balancing operation.  NN is the number of neighbors on either side
  7030         -** of the page that participate in the balancing operation.  NB is the
  7031         -** total number of pages that participate, including the target page and
  7032         -** NN neighbors on either side.
  7033         -**
  7034         -** The minimum value of NN is 1 (of course).  Increasing NN above 1
  7035         -** (to 2 or 3) gives a modest improvement in SELECT and DELETE performance
  7036         -** in exchange for a larger degradation in INSERT and UPDATE performance.
  7037         -** The value of NN appears to give the best results overall.
  7038         -*/
  7039         -#define NN 1             /* Number of neighbors on either side of pPage */
  7040         -#define NB (NN*2+1)      /* Total pages involved in the balance */
  7041         -
  7042   7125   
  7043   7126   #ifndef SQLITE_OMIT_QUICKBALANCE
  7044   7127   /*
  7045   7128   ** This version of balance() handles the common special case where
  7046   7129   ** a new entry is being inserted on the extreme right-end of the
  7047   7130   ** tree, in other words, when the new entry will become the largest
  7048   7131   ** entry in the tree.
................................................................................
  7084   7167   
  7085   7168     if( rc==SQLITE_OK ){
  7086   7169   
  7087   7170       u8 *pOut = &pSpace[4];
  7088   7171       u8 *pCell = pPage->apOvfl[0];
  7089   7172       u16 szCell = pPage->xCellSize(pPage, pCell);
  7090   7173       u8 *pStop;
         7174  +    CellArray b;
  7091   7175   
  7092   7176       assert( sqlite3PagerIswriteable(pNew->pDbPage) );
  7093         -    assert( pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
         7177  +    assert( CORRUPT_DB || pPage->aData[0]==(PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF) );
  7094   7178       zeroPage(pNew, PTF_INTKEY|PTF_LEAFDATA|PTF_LEAF);
  7095         -    rc = rebuildPage(pNew, 1, &pCell, &szCell);
  7096         -    if( NEVER(rc) ) return rc;
         7179  +    b.nCell = 1;
         7180  +    b.pRef = pPage;
         7181  +    b.apCell = &pCell;
         7182  +    b.szCell = &szCell;
         7183  +    b.apEnd[0] = pPage->aDataEnd;
         7184  +    b.ixNx[0] = 2;
         7185  +    rc = rebuildPage(&b, 0, 1, pNew);
         7186  +    if( NEVER(rc) ){
         7187  +      releasePage(pNew);
         7188  +      return rc;
         7189  +    }
  7097   7190       pNew->nFree = pBt->usableSize - pNew->cellOffset - 2 - szCell;
  7098   7191   
  7099   7192       /* If this is an auto-vacuum database, update the pointer map
  7100   7193       ** with entries for the new page, and any pointer from the 
  7101   7194       ** cell on the page to an overflow page. If either of these
  7102   7195       ** operations fails, the return code is set, but the contents
  7103   7196       ** of the parent page are still manipulated by thh code below.
................................................................................
  7569   7662     **              the right of the i-th sibling page.
  7570   7663     ** usableSpace: Number of bytes of space available on each sibling.
  7571   7664     ** 
  7572   7665     */
  7573   7666     usableSpace = pBt->usableSize - 12 + leafCorrection;
  7574   7667     for(i=0; i<nOld; i++){
  7575   7668       MemPage *p = apOld[i];
         7669  +    b.apEnd[i*2] = p->aDataEnd;
         7670  +    b.apEnd[i*2+1] = pParent->aDataEnd;
         7671  +    b.ixNx[i*2] = cntOld[i];
         7672  +    b.ixNx[i*2+1] = cntOld[i]+1;
  7576   7673       szNew[i] = usableSpace - p->nFree;
  7577   7674       for(j=0; j<p->nOverflow; j++){
  7578   7675         szNew[i] += 2 + p->xCellSize(p, p->apOvfl[j]);
  7579   7676       }
  7580   7677       cntNew[i] = cntOld[i];
  7581   7678     }
  7582   7679     k = nOld;
................................................................................
  8250   8347                                    iAmt-nData);
  8251   8348         if( rc ) return rc;
  8252   8349         iAmt = nData;
  8253   8350       }
  8254   8351       if( memcmp(pDest, ((u8*)pX->pData) + iOffset, iAmt)!=0 ){
  8255   8352         int rc = sqlite3PagerWrite(pPage->pDbPage);
  8256   8353         if( rc ) return rc;
  8257         -      memcpy(pDest, ((u8*)pX->pData) + iOffset, iAmt);
         8354  +      /* In a corrupt database, it is possible for the source and destination
         8355  +      ** buffers to overlap.  This is harmless since the database is already
         8356  +      ** corrupt but it does cause valgrind and ASAN warnings.  So use
         8357  +      ** memmove(). */
         8358  +      memmove(pDest, ((u8*)pX->pData) + iOffset, iAmt);
  8258   8359       }
  8259   8360     }
  8260   8361     return SQLITE_OK;
  8261   8362   }
  8262   8363   
  8263   8364   /*
  8264   8365   ** Overwrite the cell that cursor pCur is pointing to with fresh content

Changes to src/btreeInt.h.

   474    474   ** but cursors cannot be shared.  Each cursor is associated with a
   475    475   ** particular database connection identified BtCursor.pBtree.db.
   476    476   **
   477    477   ** Fields in this structure are accessed under the BtShared.mutex
   478    478   ** found at self->pBt->mutex. 
   479    479   **
   480    480   ** skipNext meaning:
   481         -**    eState==SKIPNEXT && skipNext>0:  Next sqlite3BtreeNext() is no-op.
   482         -**    eState==SKIPNEXT && skipNext<0:  Next sqlite3BtreePrevious() is no-op.
   483         -**    eState==FAULT:                   Cursor fault with skipNext as error code.
          481  +** The meaning of skipNext depends on the value of eState:
          482  +**
          483  +**   eState            Meaning of skipNext
          484  +**   VALID             skipNext is meaningless and is ignored
          485  +**   INVALID           skipNext is meaningless and is ignored
          486  +**   SKIPNEXT          sqlite3BtreeNext() is a no-op if skipNext>0 and
          487  +**                     sqlite3BtreePrevious() is no-op if skipNext<0.
          488  +**   REQUIRESEEK       restoreCursorPosition() restores the cursor to
          489  +**                     eState=SKIPNEXT if skipNext!=0
          490  +**   FAULT             skipNext holds the cursor fault error code.
   484    491   */
   485    492   struct BtCursor {
   486    493     u8 eState;                /* One of the CURSOR_XXX constants (see below) */
   487    494     u8 curFlags;              /* zero or more BTCF_* flags defined below */
   488    495     u8 curPagerFlags;         /* Flags to send to sqlite3PagerGet() */
   489    496     u8 hints;                 /* As configured by CursorSetHints() */
   490    497     int skipNext;    /* Prev() is noop if negative. Next() is noop if positive.

Changes to src/expr.c.

   846    846   Expr *sqlite3PExpr(
   847    847     Parse *pParse,          /* Parsing context */
   848    848     int op,                 /* Expression opcode */
   849    849     Expr *pLeft,            /* Left operand */
   850    850     Expr *pRight            /* Right operand */
   851    851   ){
   852    852     Expr *p;
   853         -  if( op==TK_AND && pParse->nErr==0 ){
          853  +  if( op==TK_AND && pParse->nErr==0 && !IN_RENAME_OBJECT ){
   854    854       /* Take advantage of short-circuit false optimization for AND */
   855    855       p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
   856    856     }else{
   857    857       p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr));
   858    858       if( p ){
   859    859         memset(p, 0, sizeof(Expr));
   860    860         p->op = op & TKFLG_MASK;
................................................................................
  5362   5362   void sqlite3ExprAnalyzeAggregates(NameContext *pNC, Expr *pExpr){
  5363   5363     Walker w;
  5364   5364     w.xExprCallback = analyzeAggregate;
  5365   5365     w.xSelectCallback = analyzeAggregatesInSelect;
  5366   5366     w.xSelectCallback2 = analyzeAggregatesInSelectEnd;
  5367   5367     w.walkerDepth = 0;
  5368   5368     w.u.pNC = pNC;
         5369  +  w.pParse = 0;
  5369   5370     assert( pNC->pSrcList!=0 );
  5370   5371     sqlite3WalkExpr(&w, pExpr);
  5371   5372   }
  5372   5373   
  5373   5374   /*
  5374   5375   ** Call sqlite3ExprAnalyzeAggregates() for every expression in an
  5375   5376   ** expression list.  Return the number of errors.

Changes to src/func.c.

   510    510   ** that is N bytes long.
   511    511   */
   512    512   static void randomBlob(
   513    513     sqlite3_context *context,
   514    514     int argc,
   515    515     sqlite3_value **argv
   516    516   ){
   517         -  int n;
          517  +  sqlite3_int64 n;
   518    518     unsigned char *p;
   519    519     assert( argc==1 );
   520    520     UNUSED_PARAMETER(argc);
   521         -  n = sqlite3_value_int(argv[0]);
          521  +  n = sqlite3_value_int64(argv[0]);
   522    522     if( n<1 ){
   523    523       n = 1;
   524    524     }
   525    525     p = contextMalloc(context, n);
   526    526     if( p ){
   527    527       sqlite3_randomness(n, p);
   528    528       sqlite3_result_blob(context, (char*)p, n, sqlite3_free);

Changes to src/insert.c.

  2204   2204     ** we have to check the semantics.
  2205   2205     */
  2206   2206     pItem = pSelect->pSrc->a;
  2207   2207     pSrc = sqlite3LocateTableItem(pParse, 0, pItem);
  2208   2208     if( pSrc==0 ){
  2209   2209       return 0;   /* FROM clause does not contain a real table */
  2210   2210     }
  2211         -  if( pSrc==pDest ){
         2211  +  if( pSrc->tnum==pDest->tnum && pSrc->pSchema==pDest->pSchema ){
         2212  +    testcase( pSrc!=pDest ); /* Possible due to bad sqlite_master.rootpage */
  2212   2213       return 0;   /* tab1 and tab2 may not be the same table */
  2213   2214     }
  2214   2215     if( HasRowid(pDest)!=HasRowid(pSrc) ){
  2215   2216       return 0;   /* source and destination must both be WITHOUT ROWID or not */
  2216   2217     }
  2217   2218   #ifndef SQLITE_OMIT_VIRTUALTABLE
  2218   2219     if( IsVirtual(pSrc) ){

Changes to src/memdb.c.

    30     30   */
    31     31   #define ORIGVFS(p) ((sqlite3_vfs*)((p)->pAppData))
    32     32   
    33     33   /* An open file */
    34     34   struct MemFile {
    35     35     sqlite3_file base;              /* IO methods */
    36     36     sqlite3_int64 sz;               /* Size of the file */
    37         -  sqlite3_int64 szMax;            /* Space allocated to aData */
           37  +  sqlite3_int64 szAlloc;          /* Space allocated to aData */
           38  +  sqlite3_int64 szMax;            /* Maximum allowed size of the file */
    38     39     unsigned char *aData;           /* content of the file */
    39     40     int nMmap;                      /* Number of memory mapped pages */
    40     41     unsigned mFlags;                /* Flags */
    41     42     int eLock;                      /* Most recent lock against this file */
    42     43   };
           44  +
           45  +/* The default maximum size of an in-memory database */
           46  +#ifndef SQLITE_MEMDB_DEFAULT_MAXSIZE
           47  +# define SQLITE_MEMDB_DEFAULT_MAXSIZE 1073741824
           48  +#endif
    43     49   
    44     50   /*
    45     51   ** Methods for MemFile
    46     52   */
    47     53   static int memdbClose(sqlite3_file*);
    48     54   static int memdbRead(sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst);
    49     55   static int memdbWrite(sqlite3_file*,const void*,int iAmt, sqlite3_int64 iOfst);
................................................................................
   156    162   ** Try to enlarge the memory allocation to hold at least sz bytes
   157    163   */
   158    164   static int memdbEnlarge(MemFile *p, sqlite3_int64 newSz){
   159    165     unsigned char *pNew;
   160    166     if( (p->mFlags & SQLITE_DESERIALIZE_RESIZEABLE)==0 || p->nMmap>0 ){
   161    167       return SQLITE_FULL;
   162    168     }
          169  +  if( newSz>p->szMax ){
          170  +    return SQLITE_FULL;
          171  +  }
          172  +  newSz *= 2;
          173  +  if( newSz>p->szMax ) newSz = p->szMax;
   163    174     pNew = sqlite3_realloc64(p->aData, newSz);
   164    175     if( pNew==0 ) return SQLITE_NOMEM;
   165    176     p->aData = pNew;
   166         -  p->szMax = newSz;
          177  +  p->szAlloc = newSz;
   167    178     return SQLITE_OK;
   168    179   }
   169    180   
   170    181   /*
   171    182   ** Write data to an memdb-file.
   172    183   */
   173    184   static int memdbWrite(
   174    185     sqlite3_file *pFile,
   175    186     const void *z,
   176    187     int iAmt,
   177    188     sqlite_int64 iOfst
   178    189   ){
   179    190     MemFile *p = (MemFile *)pFile;
          191  +  if( NEVER(p->mFlags & SQLITE_DESERIALIZE_READONLY) ) return SQLITE_READONLY;
   180    192     if( iOfst+iAmt>p->sz ){
   181    193       int rc;
   182         -    if( iOfst+iAmt>p->szMax
   183         -     && (rc = memdbEnlarge(p, (iOfst+iAmt)*2))!=SQLITE_OK
          194  +    if( iOfst+iAmt>p->szAlloc
          195  +     && (rc = memdbEnlarge(p, iOfst+iAmt))!=SQLITE_OK
   184    196       ){
   185    197         return rc;
   186    198       }
   187    199       if( iOfst>p->sz ) memset(p->aData+p->sz, 0, iOfst-p->sz);
   188    200       p->sz = iOfst+iAmt;
   189    201     }
   190    202     memcpy(p->aData+iOfst, z, iAmt);
................................................................................
   222    234   }
   223    235   
   224    236   /*
   225    237   ** Lock an memdb-file.
   226    238   */
   227    239   static int memdbLock(sqlite3_file *pFile, int eLock){
   228    240     MemFile *p = (MemFile *)pFile;
          241  +  if( eLock>SQLITE_LOCK_SHARED 
          242  +   && (p->mFlags & SQLITE_DESERIALIZE_READONLY)!=0
          243  +  ){
          244  +    return SQLITE_READONLY;
          245  +  }
   229    246     p->eLock = eLock;
   230    247     return SQLITE_OK;
   231    248   }
   232    249   
   233    250   #if 0 /* Never used because memdbAccess() always returns false */
   234    251   /*
   235    252   ** Check if another file-handle holds a RESERVED lock on an memdb-file.
................................................................................
   245    262   */
   246    263   static int memdbFileControl(sqlite3_file *pFile, int op, void *pArg){
   247    264     MemFile *p = (MemFile *)pFile;
   248    265     int rc = SQLITE_NOTFOUND;
   249    266     if( op==SQLITE_FCNTL_VFSNAME ){
   250    267       *(char**)pArg = sqlite3_mprintf("memdb(%p,%lld)", p->aData, p->sz);
   251    268       rc = SQLITE_OK;
          269  +  }
          270  +  if( op==SQLITE_FCNTL_SIZE_LIMIT ){
          271  +    sqlite3_int64 iLimit = *(sqlite3_int64*)pArg;
          272  +    if( iLimit<p->sz ){
          273  +      if( iLimit<0 ){
          274  +        iLimit = p->szMax;
          275  +      }else{
          276  +        iLimit = p->sz;
          277  +      }
          278  +    }
          279  +    p->szMax = iLimit;
          280  +    *(sqlite3_int64*)pArg = iLimit;
          281  +    rc = SQLITE_OK;
   252    282     }
   253    283     return rc;
   254    284   }
   255    285   
   256    286   #if 0  /* Not used because of SQLITE_IOCAP_POWERSAFE_OVERWRITE */
   257    287   /*
   258    288   ** Return the sector-size in bytes for an memdb-file.
................................................................................
   276    306   static int memdbFetch(
   277    307     sqlite3_file *pFile,
   278    308     sqlite3_int64 iOfst,
   279    309     int iAmt,
   280    310     void **pp
   281    311   ){
   282    312     MemFile *p = (MemFile *)pFile;
          313  +  if( iOfst+iAmt>p->sz ){
          314  +    assert( CORRUPT_DB );
          315  +    *pp = 0;
          316  +  }else{
   283    317     p->nMmap++;
   284    318     *pp = (void*)(p->aData + iOfst);
          319  +  }
   285    320     return SQLITE_OK;
   286    321   }
   287    322   
   288    323   /* Release a memory-mapped page */
   289    324   static int memdbUnfetch(sqlite3_file *pFile, sqlite3_int64 iOfst, void *pPage){
   290    325     MemFile *p = (MemFile *)pFile;
   291    326     p->nMmap--;
................................................................................
   307    342       return ORIGVFS(pVfs)->xOpen(ORIGVFS(pVfs), zName, pFile, flags, pOutFlags);
   308    343     }
   309    344     memset(p, 0, sizeof(*p));
   310    345     p->mFlags = SQLITE_DESERIALIZE_RESIZEABLE | SQLITE_DESERIALIZE_FREEONCLOSE;
   311    346     assert( pOutFlags!=0 );  /* True because flags==SQLITE_OPEN_MAIN_DB */
   312    347     *pOutFlags = flags | SQLITE_OPEN_MEMORY;
   313    348     p->base.pMethods = &memdb_io_methods;
          349  +  p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE;
   314    350     return SQLITE_OK;
   315    351   }
   316    352   
   317    353   #if 0 /* Only used to delete rollback journals, master journals, and WAL
   318    354         ** files, none of which exist in memdb.  So this routine is never used */
   319    355   /*
   320    356   ** Delete the file located at zPath. If the dirSync argument is true,
................................................................................
   556    592     }
   557    593     p = memdbFromDbSchema(db, zSchema);
   558    594     if( p==0 ){
   559    595       rc = SQLITE_ERROR;
   560    596     }else{
   561    597       p->aData = pData;
   562    598       p->sz = szDb;
          599  +    p->szAlloc = szBuf;
   563    600       p->szMax = szBuf;
          601  +    if( p->szMax<SQLITE_MEMDB_DEFAULT_MAXSIZE ){
          602  +      p->szMax = SQLITE_MEMDB_DEFAULT_MAXSIZE;
          603  +    }
   564    604       p->mFlags = mFlags;
   565    605       rc = SQLITE_OK;
   566    606     }
   567    607   
   568    608   end_deserialize:
   569    609     sqlite3_finalize(pStmt);
   570    610     sqlite3_mutex_leave(db->mutex);

Changes to src/pager.c.

  3847   3847   ** Regardless of mxPage, return the current maximum page count.
  3848   3848   */
  3849   3849   int sqlite3PagerMaxPageCount(Pager *pPager, int mxPage){
  3850   3850     if( mxPage>0 ){
  3851   3851       pPager->mxPgno = mxPage;
  3852   3852     }
  3853   3853     assert( pPager->eState!=PAGER_OPEN );      /* Called only by OP_MaxPgcnt */
  3854         -  assert( pPager->mxPgno>=pPager->dbSize );  /* OP_MaxPgcnt enforces this */
         3854  +  /* assert( pPager->mxPgno>=pPager->dbSize ); */
         3855  +  /* OP_MaxPgcnt ensures that the parameter passed to this function is not
         3856  +  ** less than the total number of valid pages in the database. But this
         3857  +  ** may be less than Pager.dbSize, and so the assert() above is not valid */
  3855   3858     return pPager->mxPgno;
  3856   3859   }
  3857   3860   
  3858   3861   /*
  3859   3862   ** The following set of routines are used to disable the simulated
  3860   3863   ** I/O error mechanism.  These routines are used to avoid simulated
  3861   3864   ** errors in places where we do not care about errors.

Changes to src/parse.y.

  1162   1162         **
  1163   1163         **      expr1 IN ()
  1164   1164         **      expr1 NOT IN ()
  1165   1165         **
  1166   1166         ** simplify to constants 0 (false) and 1 (true), respectively,
  1167   1167         ** regardless of the value of expr1.
  1168   1168         */
         1169  +      if( IN_RENAME_OBJECT==0 ){
  1169   1170         sqlite3ExprDelete(pParse->db, A);
  1170   1171         A = sqlite3ExprAlloc(pParse->db, TK_INTEGER,&sqlite3IntTokens[N],1);
         1172  +      }
  1171   1173       }else if( Y->nExpr==1 ){
  1172   1174         /* Expressions of the form:
  1173   1175         **
  1174   1176         **      expr1 IN (?1)
  1175   1177         **      expr1 NOT IN (?2)
  1176   1178         **
  1177   1179         ** with exactly one value on the RHS can be simplified to something

Changes to src/pragma.h.

   207    207    {/* zName:     */ "compile_options",
   208    208     /* ePragTyp:  */ PragTyp_COMPILE_OPTIONS,
   209    209     /* ePragFlg:  */ PragFlg_Result0,
   210    210     /* ColNames:  */ 0, 0,
   211    211     /* iArg:      */ 0 },
   212    212   #endif
   213    213   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
          214  +#if !defined(SQLITE_OMIT_DEPRECATED)
   214    215    {/* zName:     */ "count_changes",
   215    216     /* ePragTyp:  */ PragTyp_FLAG,
   216    217     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
   217    218     /* ColNames:  */ 0, 0,
   218    219     /* iArg:      */ SQLITE_CountRows },
          220  +#endif
   219    221   #endif
   220    222   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
          223  +#if !defined(SQLITE_OMIT_DEPRECATED)
   221    224    {/* zName:     */ "data_store_directory",
   222    225     /* ePragTyp:  */ PragTyp_DATA_STORE_DIRECTORY,
   223    226     /* ePragFlg:  */ PragFlg_NoColumns1,
   224    227     /* ColNames:  */ 0, 0,
   225    228     /* iArg:      */ 0 },
          229  +#endif
   226    230   #endif
   227    231   #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   228    232    {/* zName:     */ "data_version",
   229    233     /* ePragTyp:  */ PragTyp_HEADER_VALUE,
   230    234     /* ePragFlg:  */ PragFlg_ReadOnly|PragFlg_Result0,
   231    235     /* ColNames:  */ 0, 0,
   232    236     /* iArg:      */ BTREE_DATA_VERSION },
................................................................................
   234    238   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   235    239    {/* zName:     */ "database_list",
   236    240     /* ePragTyp:  */ PragTyp_DATABASE_LIST,
   237    241     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0,
   238    242     /* ColNames:  */ 35, 3,
   239    243     /* iArg:      */ 0 },
   240    244   #endif
   241         -#if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
          245  +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          246  +#if !defined(SQLITE_OMIT_DEPRECATED)
   242    247    {/* zName:     */ "default_cache_size",
   243    248     /* ePragTyp:  */ PragTyp_DEFAULT_CACHE_SIZE,
   244    249     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
   245    250     /* ColNames:  */ 45, 1,
   246    251     /* iArg:      */ 0 },
          252  +#endif
   247    253   #endif
   248    254   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   249    255   #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
   250    256    {/* zName:     */ "defer_foreign_keys",
   251    257     /* ePragTyp:  */ PragTyp_FLAG,
   252    258     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
   253    259     /* ColNames:  */ 0, 0,
   254    260     /* iArg:      */ SQLITE_DeferFKs },
   255    261   #endif
   256    262   #endif
   257    263   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
          264  +#if !defined(SQLITE_OMIT_DEPRECATED)
   258    265    {/* zName:     */ "empty_result_callbacks",
   259    266     /* ePragTyp:  */ PragTyp_FLAG,
   260    267     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
   261    268     /* ColNames:  */ 0, 0,
   262    269     /* iArg:      */ SQLITE_NullCallback },
          270  +#endif
   263    271   #endif
   264    272   #if !defined(SQLITE_OMIT_UTF16)
   265    273    {/* zName:     */ "encoding",
   266    274     /* ePragTyp:  */ PragTyp_ENCODING,
   267    275     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
   268    276     /* ColNames:  */ 0, 0,
   269    277     /* iArg:      */ 0 },
................................................................................
   295    303    {/* zName:     */ "freelist_count",
   296    304     /* ePragTyp:  */ PragTyp_HEADER_VALUE,
   297    305     /* ePragFlg:  */ PragFlg_ReadOnly|PragFlg_Result0,
   298    306     /* ColNames:  */ 0, 0,
   299    307     /* iArg:      */ BTREE_FREE_PAGE_COUNT },
   300    308   #endif
   301    309   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
          310  +#if !defined(SQLITE_OMIT_DEPRECATED)
   302    311    {/* zName:     */ "full_column_names",
   303    312     /* ePragTyp:  */ PragTyp_FLAG,
   304    313     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
   305    314     /* ColNames:  */ 0, 0,
   306    315     /* iArg:      */ SQLITE_FullColNames },
          316  +#endif
          317  +#endif
          318  +#if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   307    319    {/* zName:     */ "fullfsync",
   308    320     /* ePragTyp:  */ PragTyp_FLAG,
   309    321     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
   310    322     /* ColNames:  */ 0, 0,
   311    323     /* iArg:      */ SQLITE_FullFSync },
   312    324   #endif
   313    325   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
................................................................................
   526    538    {/* zName:     */ "secure_delete",
   527    539     /* ePragTyp:  */ PragTyp_SECURE_DELETE,
   528    540     /* ePragFlg:  */ PragFlg_Result0,
   529    541     /* ColNames:  */ 0, 0,
   530    542     /* iArg:      */ 0 },
   531    543   #endif
   532    544   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
          545  +#if !defined(SQLITE_OMIT_DEPRECATED)
   533    546    {/* zName:     */ "short_column_names",
   534    547     /* ePragTyp:  */ PragTyp_FLAG,
   535    548     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
   536    549     /* ColNames:  */ 0, 0,
   537    550     /* iArg:      */ SQLITE_ShortColNames },
          551  +#endif
   538    552   #endif
   539    553    {/* zName:     */ "shrink_memory",
   540    554     /* ePragTyp:  */ PragTyp_SHRINK_MEMORY,
   541    555     /* ePragFlg:  */ PragFlg_NoColumns,
   542    556     /* ColNames:  */ 0, 0,
   543    557     /* iArg:      */ 0 },
   544    558    {/* zName:     */ "soft_heap_limit",
................................................................................
   583    597   #endif
   584    598   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   585    599    {/* zName:     */ "temp_store",
   586    600     /* ePragTyp:  */ PragTyp_TEMP_STORE,
   587    601     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
   588    602     /* ColNames:  */ 0, 0,
   589    603     /* iArg:      */ 0 },
          604  +#endif
          605  +#if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
          606  +#if !defined(SQLITE_OMIT_DEPRECATED)
   590    607    {/* zName:     */ "temp_store_directory",
   591    608     /* ePragTyp:  */ PragTyp_TEMP_STORE_DIRECTORY,
   592    609     /* ePragFlg:  */ PragFlg_NoColumns1,
   593    610     /* ColNames:  */ 0, 0,
   594    611     /* iArg:      */ 0 },
          612  +#endif
   595    613   #endif
   596    614   #if defined(SQLITE_HAS_CODEC)
   597    615    {/* zName:     */ "textkey",
   598    616     /* ePragTyp:  */ PragTyp_KEY,
   599    617     /* ePragFlg:  */ 0,
   600    618     /* ColNames:  */ 0, 0,
   601    619     /* iArg:      */ 4 },

Changes to src/resolve.c.

   854    854           }
   855    855         }
   856    856         sqlite3WalkExprList(pWalker, pList);
   857    857         if( is_agg ){
   858    858   #ifndef SQLITE_OMIT_WINDOWFUNC
   859    859           if( pExpr->y.pWin ){
   860    860             Select *pSel = pNC->pWinSelect;
          861  +          sqlite3WindowUpdate(pParse, pSel->pWinDefn, pExpr->y.pWin, pDef);
   861    862             sqlite3WalkExprList(pWalker, pExpr->y.pWin->pPartition);
   862    863             sqlite3WalkExprList(pWalker, pExpr->y.pWin->pOrderBy);
   863    864             sqlite3WalkExpr(pWalker, pExpr->y.pWin->pFilter);
   864         -          sqlite3WindowUpdate(pParse, pSel->pWinDefn, pExpr->y.pWin, pDef);
   865    865             if( 0==pSel->pWin 
   866    866              || 0==sqlite3WindowCompare(pParse, pSel->pWin, pExpr->y.pWin) 
   867    867             ){
   868    868               pExpr->y.pWin->pNextWin = pSel->pWin;
   869    869               pSel->pWin = pExpr->y.pWin;
   870    870             }
   871    871             pNC->ncFlags |= NC_AllowWin;
................................................................................
  1156   1156             }else{
  1157   1157               pDup = sqlite3ExprDup(db, pE, 0);
  1158   1158             }
  1159   1159             if( !db->mallocFailed ){
  1160   1160               assert(pDup);
  1161   1161               iCol = resolveOrderByTermToExprList(pParse, pSelect, pDup);
  1162   1162             }
  1163         -          if( IN_RENAME_OBJECT ){
  1164         -            if( iCol>0 ){
  1165         -              pItem->done = 1;
  1166         -              continue;
  1167         -            }
  1168         -          }else{
         1163  +          if( !IN_RENAME_OBJECT ){
  1169   1164               sqlite3ExprDelete(db, pDup);
  1170   1165             }
  1171   1166           }
  1172   1167         }
  1173   1168         if( iCol>0 ){
  1174   1169           /* Convert the ORDER BY term into an integer column number iCol,
  1175   1170           ** taking care to preserve the COLLATE clause if it exists */
         1171  +        if( !IN_RENAME_OBJECT ){
  1176   1172           Expr *pNew = sqlite3Expr(db, TK_INTEGER, 0);
  1177   1173           if( pNew==0 ) return 1;
  1178   1174           pNew->flags |= EP_IntValue;
  1179   1175           pNew->u.iValue = iCol;
  1180   1176           if( pItem->pExpr==pE ){
  1181   1177             pItem->pExpr = pNew;
  1182   1178           }else{
................................................................................
  1184   1180             assert( pParent->op==TK_COLLATE );
  1185   1181             while( pParent->pLeft->op==TK_COLLATE ) pParent = pParent->pLeft;
  1186   1182             assert( pParent->pLeft==pE );
  1187   1183             pParent->pLeft = pNew;
  1188   1184           }
  1189   1185           sqlite3ExprDelete(db, pE);
  1190   1186           pItem->u.x.iOrderByCol = (u16)iCol;
         1187  +        }
  1191   1188           pItem->done = 1;
  1192   1189         }else{
  1193   1190           moreToDo = 1;
  1194   1191         }
  1195   1192       }
  1196   1193       pSelect = pSelect->pNext;
  1197   1194     }
................................................................................
  1531   1528           if( ExprHasProperty(pItem->pExpr, EP_Agg) ){
  1532   1529             sqlite3ErrorMsg(pParse, "aggregate functions are not allowed in "
  1533   1530                 "the GROUP BY clause");
  1534   1531             return WRC_Abort;
  1535   1532           }
  1536   1533         }
  1537   1534       }
         1535  +
         1536  +    if( IN_RENAME_OBJECT ){
         1537  +      Window *pWin;
         1538  +      for(pWin=p->pWinDefn; pWin; pWin=pWin->pNextWin){
         1539  +        if( sqlite3ResolveExprListNames(&sNC, pWin->pOrderBy)
         1540  +         || sqlite3ResolveExprListNames(&sNC, pWin->pPartition)
         1541  +        ){
         1542  +          return WRC_Abort;
         1543  +        }
         1544  +      }
         1545  +    }
  1538   1546   
  1539   1547       /* If this is part of a compound SELECT, check that it has the right
  1540   1548       ** number of expressions in the select list. */
  1541   1549       if( p->pNext && p->pEList->nExpr!=p->pNext->pEList->nExpr ){
  1542   1550         sqlite3SelectWrongNumTermsError(pParse, p->pNext);
  1543   1551         return WRC_Abort;
  1544   1552       }

Changes to src/select.c.

  2085   2085     sqlite3 *db = pParse->db;
  2086   2086     u64 savedFlags;
  2087   2087   
  2088   2088     savedFlags = db->flags;
  2089   2089     db->flags &= ~(u64)SQLITE_FullColNames;
  2090   2090     db->flags |= SQLITE_ShortColNames;
  2091   2091     sqlite3SelectPrep(pParse, pSelect, 0);
         2092  +  db->flags = savedFlags;
  2092   2093     if( pParse->nErr ) return 0;
  2093   2094     while( pSelect->pPrior ) pSelect = pSelect->pPrior;
  2094         -  db->flags = savedFlags;
  2095   2095     pTab = sqlite3DbMallocZero(db, sizeof(Table) );
  2096   2096     if( pTab==0 ){
  2097   2097       return 0;
  2098   2098     }
  2099   2099     /* The sqlite3ResultSetOfSelect() is only used n contexts where lookaside
  2100   2100     ** is disabled */
  2101   2101     assert( db->lookaside.bDisable );

Changes to src/shell.c.in.

   134    134   # define isatty(h) _isatty(h)
   135    135   # ifndef access
   136    136   #  define access(f,m) _access((f),(m))
   137    137   # endif
   138    138   # ifndef unlink
   139    139   #  define unlink _unlink
   140    140   # endif
          141  +# ifndef strdup
          142  +#  define strdup _strdup
          143  +# endif
   141    144   # undef popen
   142    145   # define popen _popen
   143    146   # undef pclose
   144    147   # define pclose _pclose
   145    148   #else
   146    149    /* Make sure isatty() has a prototype. */
   147    150    extern int isatty(int);
................................................................................
   933    936   INCLUDE test_windirent.c
   934    937   #define dirent DIRENT
   935    938   #endif
   936    939   INCLUDE ../ext/misc/shathree.c
   937    940   INCLUDE ../ext/misc/fileio.c
   938    941   INCLUDE ../ext/misc/completion.c
   939    942   INCLUDE ../ext/misc/appendvfs.c
          943  +INCLUDE ../ext/misc/memtrace.c
   940    944   #ifdef SQLITE_HAVE_ZLIB
   941    945   INCLUDE ../ext/misc/zipfile.c
   942    946   INCLUDE ../ext/misc/sqlar.c
   943    947   #endif
   944    948   INCLUDE ../ext/expert/sqlite3expert.h
   945    949   INCLUDE ../ext/expert/sqlite3expert.c
   946    950   
................................................................................
   998   1002   */
   999   1003   typedef struct ShellState ShellState;
  1000   1004   struct ShellState {
  1001   1005     sqlite3 *db;           /* The database */
  1002   1006     u8 autoExplain;        /* Automatically turn on .explain mode */
  1003   1007     u8 autoEQP;            /* Run EXPLAIN QUERY PLAN prior to seach SQL stmt */
  1004   1008     u8 autoEQPtest;        /* autoEQP is in test mode */
         1009  +  u8 autoEQPtrace;       /* autoEQP is in trace mode */
  1005   1010     u8 statsOn;            /* True to display memory stats before each finalize */
  1006   1011     u8 scanstatsOn;        /* True to display scan stats before each finalize */
  1007   1012     u8 openMode;           /* SHELL_OPEN_NORMAL, _APPENDVFS, or _ZIPFILE */
  1008   1013     u8 doXdgOpen;          /* Invoke start/open/xdg-open in output_reset() */
  1009   1014     u8 nEqpLevel;          /* Depth of the EQP output graph */
  1010   1015     u8 eTraceType;         /* SHELL_TRACE_* value for type of trace */
  1011   1016     unsigned mEqpLines;    /* Mask of veritical lines in the EQP output graph */
................................................................................
  1020   1025     int modePrior;         /* Saved mode */
  1021   1026     int cMode;             /* temporary output mode for the current query */
  1022   1027     int normalMode;        /* Output mode before ".explain on" */
  1023   1028     int writableSchema;    /* True if PRAGMA writable_schema=ON */
  1024   1029     int showHeader;        /* True to show column names in List or Column mode */
  1025   1030     int nCheck;            /* Number of ".check" commands run */
  1026   1031     unsigned shellFlgs;    /* Various flags */
         1032  +  sqlite3_int64 szMax;   /* --maxsize argument to .open */
  1027   1033     char *zDestTable;      /* Name of destination table when MODE_Insert */
  1028   1034     char *zTempFile;       /* Temporary file that might need deleting */
  1029   1035     char zTestcase[30];    /* Name of current test case */
  1030   1036     char colSeparator[20]; /* Column separator character for several modes */
  1031   1037     char rowSeparator[20]; /* Row separator character for MODE_Ascii */
  1032   1038     char colSepPrior[20];  /* Saved column separator */
  1033   1039     char rowSepPrior[20];  /* Saved row separator */
................................................................................
  3392   3398     ".dbinfo ?DB?             Show status information about the database",
  3393   3399     ".dump ?TABLE? ...        Render all database content as SQL",
  3394   3400     "   Options:",
  3395   3401     "     --preserve-rowids      Include ROWID values in the output",
  3396   3402     "     --newlines             Allow unescaped newline characters in output",
  3397   3403     "   TABLE is LIKE pattern for the tables to dump",
  3398   3404     ".echo on|off             Turn command echo on or off",
  3399         -  ".eqp on|off|full         Enable or disable automatic EXPLAIN QUERY PLAN",
         3405  +  ".eqp on|off|full|...     Enable or disable automatic EXPLAIN QUERY PLAN",
         3406  +  "   Other Modes:",
         3407  +#ifdef SQLITE_DEBUG
         3408  +  "      test                  Show raw EXPLAIN QUERY PLAN output",
         3409  +  "      trace                 Like \"full\" but also enable \"PRAGMA vdbe_trace\"",
         3410  +#endif
         3411  +  "      trigger               Like \"full\" but also show trigger bytecode",
  3400   3412     ".excel                   Display the output of next command in a spreadsheet",
  3401   3413     ".exit ?CODE?             Exit this program with return-code CODE",
  3402   3414     ".expert                  EXPERIMENTAL. Suggest indexes for specified queries",
  3403   3415   /* Because explain mode comes on automatically now, the ".explain" mode
  3404   3416   ** is removed from the help screen.  It is still supported for legacy, however */
  3405   3417   /*".explain ?on|off|auto?   Turn EXPLAIN output mode on or off or to automatic",*/
  3406   3418     ".fullschema ?--indent?   Show schema and the content of sqlite_stat tables",
................................................................................
  3444   3456     "       -x    Open in a spreadsheet",
  3445   3457     ".open ?OPTIONS? ?FILE?   Close existing database and reopen FILE",
  3446   3458     "     Options:",
  3447   3459     "        --append        Use appendvfs to append database to the end of FILE",
  3448   3460   #ifdef SQLITE_ENABLE_DESERIALIZE
  3449   3461     "        --deserialize   Load into memory useing sqlite3_deserialize()",
  3450   3462     "        --hexdb         Load the output of \"dbtotxt\" as an in-memory database",
         3463  +  "        --maxsize N     Maximum size for --hexdb or --deserialized database",
  3451   3464   #endif
  3452   3465     "        --new           Initialize FILE to an empty database",
  3453   3466     "        --readonly      Open FILE readonly",
  3454   3467     "        --zip           FILE is a ZIP archive",
  3455   3468     ".output ?FILE?           Send output to FILE or stdout if FILE is omitted",
  3456   3469     "     If FILE begins with '|' then open it as a pipe.",
  3457   3470     ".print STRING...         Print literal STRING",
................................................................................
  3922   3935         }
  3923   3936         rc = sqlite3_deserialize(p->db, "main", aData, nData, nData,
  3924   3937                      SQLITE_DESERIALIZE_RESIZEABLE |
  3925   3938                      SQLITE_DESERIALIZE_FREEONCLOSE);
  3926   3939         if( rc ){
  3927   3940           utf8_printf(stderr, "Error: sqlite3_deserialize() returns %d\n", rc);
  3928   3941         }
         3942  +      if( p->szMax>0 ){
         3943  +        sqlite3_file_control(p->db, "main", SQLITE_FCNTL_SIZE_LIMIT, &p->szMax);
         3944  +      }
  3929   3945       }
  3930   3946   #endif
  3931   3947     }
  3932   3948   }
  3933   3949   
  3934   3950   /*
  3935   3951   ** Attempt to close the databaes connection.  Report errors.
................................................................................
  6251   6267         rc = 1;
  6252   6268       }
  6253   6269     }else
  6254   6270   
  6255   6271     if( c=='e' && strncmp(azArg[0], "eqp", n)==0 ){
  6256   6272       if( nArg==2 ){
  6257   6273         p->autoEQPtest = 0;
         6274  +      if( p->autoEQPtrace ){
         6275  +        if( p->db ) sqlite3_exec(p->db, "PRAGMA vdbe_trace=OFF;", 0, 0, 0);
         6276  +        p->autoEQPtrace = 0;
         6277  +      }
  6258   6278         if( strcmp(azArg[1],"full")==0 ){
  6259   6279           p->autoEQP = AUTOEQP_full;
  6260   6280         }else if( strcmp(azArg[1],"trigger")==0 ){
  6261   6281           p->autoEQP = AUTOEQP_trigger;
         6282  +#ifdef SQLITE_DEBUG
  6262   6283         }else if( strcmp(azArg[1],"test")==0 ){
  6263   6284           p->autoEQP = AUTOEQP_on;
  6264   6285           p->autoEQPtest = 1;
         6286  +      }else if( strcmp(azArg[1],"trace")==0 ){
         6287  +        p->autoEQP = AUTOEQP_full;
         6288  +        p->autoEQPtrace = 1;
         6289  +        open_db(p, 0);
         6290  +        sqlite3_exec(p->db, "SELECT name FROM sqlite_master LIMIT 1", 0, 0, 0);
         6291  +        sqlite3_exec(p->db, "PRAGMA vdbe_trace=ON;", 0, 0, 0);
         6292  +#endif
  6265   6293         }else{
  6266   6294           p->autoEQP = (u8)booleanValue(azArg[1]);
  6267   6295         }
  6268   6296       }else{
  6269         -      raw_printf(stderr, "Usage: .eqp off|on|trigger|full\n");
         6297  +      raw_printf(stderr, "Usage: .eqp off|on|trace|trigger|full\n");
  6270   6298         rc = 1;
  6271   6299       }
  6272   6300     }else
  6273   6301   
  6274   6302     if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
  6275   6303       if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
  6276   6304       rc = 2;
................................................................................
  6836   6864       session_close_all(p);
  6837   6865       close_db(p->db);
  6838   6866       p->db = 0;
  6839   6867       p->zDbFilename = 0;
  6840   6868       sqlite3_free(p->zFreeOnClose);
  6841   6869       p->zFreeOnClose = 0;
  6842   6870       p->openMode = SHELL_OPEN_UNSPEC;
         6871  +    p->szMax = 0;
  6843   6872       /* Check for command-line arguments */
  6844   6873       for(iName=1; iName<nArg && azArg[iName][0]=='-'; iName++){
  6845   6874         const char *z = azArg[iName];
  6846   6875         if( optionMatch(z,"new") ){
  6847   6876           newFlag = 1;
  6848   6877   #ifdef SQLITE_HAVE_ZLIB
  6849   6878         }else if( optionMatch(z, "zip") ){
................................................................................
  6854   6883         }else if( optionMatch(z, "readonly") ){
  6855   6884           p->openMode = SHELL_OPEN_READONLY;
  6856   6885   #ifdef SQLITE_ENABLE_DESERIALIZE
  6857   6886         }else if( optionMatch(z, "deserialize") ){
  6858   6887           p->openMode = SHELL_OPEN_DESERIALIZE;
  6859   6888         }else if( optionMatch(z, "hexdb") ){
  6860   6889           p->openMode = SHELL_OPEN_HEXDB;
         6890  +      }else if( optionMatch(z, "maxsize") && iName+1<nArg ){
         6891  +        p->szMax = integerValue(azArg[++iName]);
  6861   6892   #endif /* SQLITE_ENABLE_DESERIALIZE */
  6862   6893         }else if( z[0]=='-' ){
  6863   6894           utf8_printf(stderr, "unknown option: %s\n", z);
  6864   6895           rc = 1;
  6865   6896           goto meta_command_exit;
  6866   6897         }
  6867   6898       }
................................................................................
  8544   8575     "   -append              append the database to the end of the file\n"
  8545   8576     "   -ascii               set output mode to 'ascii'\n"
  8546   8577     "   -bail                stop after hitting an error\n"
  8547   8578     "   -batch               force batch I/O\n"
  8548   8579     "   -column              set output mode to 'column'\n"
  8549   8580     "   -cmd COMMAND         run \"COMMAND\" before reading stdin\n"
  8550   8581     "   -csv                 set output mode to 'csv'\n"
         8582  +#if defined(SQLITE_ENABLE_DESERIALIZE)
         8583  +  "   -deserialize         open the database using sqlite3_deserialize()\n"
         8584  +#endif
  8551   8585     "   -echo                print commands before execution\n"
  8552   8586     "   -init FILENAME       read/process named file\n"
  8553   8587     "   -[no]header          turn headers on or off\n"
  8554   8588   #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5)
  8555   8589     "   -heap SIZE           Size of heap for memsys3 or memsys5\n"
  8556   8590   #endif
  8557   8591     "   -help                show this message\n"
  8558   8592     "   -html                set output mode to HTML\n"
  8559   8593     "   -interactive         force interactive I/O\n"
  8560   8594     "   -line                set output mode to 'line'\n"
  8561   8595     "   -list                set output mode to 'list'\n"
  8562   8596     "   -lookaside SIZE N    use N entries of SZ bytes for lookaside memory\n"
         8597  +#if defined(SQLITE_ENABLE_DESERIALIZE)
         8598  +  "   -maxsize N           maximum size for a --deserialize database\n"
         8599  +#endif
  8563   8600     "   -mmap N              default mmap size set to N\n"
  8564   8601   #ifdef SQLITE_ENABLE_MULTIPLEX
  8565   8602     "   -multiplex           enable the multiplexor VFS\n"
  8566   8603   #endif
  8567   8604     "   -newline SEP         set output row separator. Default: '\\n'\n"
  8568   8605     "   -nullvalue TEXT      set text string for NULL values. Default ''\n"
  8569   8606     "   -pagecache SIZE N    use N slots of SZ bytes each for page cache memory\n"
................................................................................
  8866   8903         data.openMode = SHELL_OPEN_ZIPFILE;
  8867   8904   #endif
  8868   8905       }else if( strcmp(z,"-append")==0 ){
  8869   8906         data.openMode = SHELL_OPEN_APPENDVFS;
  8870   8907   #ifdef SQLITE_ENABLE_DESERIALIZE
  8871   8908       }else if( strcmp(z,"-deserialize")==0 ){
  8872   8909         data.openMode = SHELL_OPEN_DESERIALIZE;
         8910  +    }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
         8911  +      data.szMax = integerValue(argv[++i]);
  8873   8912   #endif
  8874   8913       }else if( strcmp(z,"-readonly")==0 ){
  8875   8914         data.openMode = SHELL_OPEN_READONLY;
  8876   8915   #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(SQLITE_HAVE_ZLIB)
  8877   8916       }else if( strncmp(z, "-A",2)==0 ){
  8878   8917         /* All remaining command-line arguments are passed to the ".archive"
  8879   8918         ** command, so ignore them */
  8880   8919         break;
  8881   8920   #endif
         8921  +    }else if( strcmp(z, "-memtrace")==0 ){
         8922  +      sqlite3MemTraceActivate(stderr);
  8882   8923       }
  8883   8924     }
  8884   8925     verify_uninitialized();
  8885   8926   
  8886   8927   
  8887   8928   #ifdef SQLITE_SHELL_INIT_PROC
  8888   8929     {
................................................................................
  8965   9006         data.openMode = SHELL_OPEN_ZIPFILE;
  8966   9007   #endif
  8967   9008       }else if( strcmp(z,"-append")==0 ){
  8968   9009         data.openMode = SHELL_OPEN_APPENDVFS;
  8969   9010   #ifdef SQLITE_ENABLE_DESERIALIZE
  8970   9011       }else if( strcmp(z,"-deserialize")==0 ){
  8971   9012         data.openMode = SHELL_OPEN_DESERIALIZE;
         9013  +    }else if( strcmp(z,"-maxsize")==0 && i+1<argc ){
         9014  +      data.szMax = integerValue(argv[++i]);
  8972   9015   #endif
  8973   9016       }else if( strcmp(z,"-readonly")==0 ){
  8974   9017         data.openMode = SHELL_OPEN_READONLY;
  8975   9018       }else if( strcmp(z,"-ascii")==0 ){
  8976   9019         data.mode = MODE_Ascii;
  8977   9020         sqlite3_snprintf(sizeof(data.colSeparator), data.colSeparator,
  8978   9021                          SEP_Unit);
................................................................................
  9020   9063       }else if( strcmp(z,"-heap")==0 ){
  9021   9064         i++;
  9022   9065       }else if( strcmp(z,"-pagecache")==0 ){
  9023   9066         i+=2;
  9024   9067       }else if( strcmp(z,"-lookaside")==0 ){
  9025   9068         i+=2;
  9026   9069       }else if( strcmp(z,"-mmap")==0 ){
         9070  +      i++;
         9071  +    }else if( strcmp(z,"-memtrace")==0 ){
  9027   9072         i++;
  9028   9073   #ifdef SQLITE_ENABLE_SORTER_REFERENCES
  9029   9074       }else if( strcmp(z,"-sorterref")==0 ){
  9030   9075         i++;
  9031   9076   #endif
  9032   9077       }else if( strcmp(z,"-vfs")==0 ){
  9033   9078         i++;

Changes to src/sqlite.h.in.

   820    820   ** The [SQLITE_FCNTL_SIZE_HINT] opcode is used by SQLite to give the VFS
   821    821   ** layer a hint of how large the database file will grow to be during the
   822    822   ** current transaction.  This hint is not guaranteed to be accurate but it
   823    823   ** is often close.  The underlying VFS might choose to preallocate database
   824    824   ** file space based on this hint in order to help writes to the database
   825    825   ** file run faster.
   826    826   **
          827  +** <li>[[SQLITE_FCNTL_SIZE_LIMIT]]
          828  +** The [SQLITE_FCNTL_SIZE_LIMIT] opcode is used by in-memory VFS that
          829  +** implements [sqlite3_deserialize()] to set an upper bound on the size
          830  +** of the in-memory database.  The argument is a pointer to a [sqlite3_int64].
          831  +** If the integer pointed to is negative, then it is filled in with the
          832  +** current limit.  Otherwise the limit is set to the larger of the value
          833  +** of the integer pointed to and the current database size.  The integer
          834  +** pointed to is set to the new limit.
          835  +**
   827    836   ** <li>[[SQLITE_FCNTL_CHUNK_SIZE]]
   828    837   ** The [SQLITE_FCNTL_CHUNK_SIZE] opcode is used to request that the VFS
   829    838   ** extends and truncates the database file in chunks of a size specified
   830    839   ** by the user. The fourth argument to [sqlite3_file_control()] should 
   831    840   ** point to an integer (type int) containing the new chunk-size to use
   832    841   ** for the nominated database. Allocating database file space in large
   833    842   ** chunks (say 1MB at a time), may reduce file-system fragmentation and
................................................................................
  1128   1137   #define SQLITE_FCNTL_WIN32_GET_HANDLE       29
  1129   1138   #define SQLITE_FCNTL_PDB                    30
  1130   1139   #define SQLITE_FCNTL_BEGIN_ATOMIC_WRITE     31
  1131   1140   #define SQLITE_FCNTL_COMMIT_ATOMIC_WRITE    32
  1132   1141   #define SQLITE_FCNTL_ROLLBACK_ATOMIC_WRITE  33
  1133   1142   #define SQLITE_FCNTL_LOCK_TIMEOUT           34
  1134   1143   #define SQLITE_FCNTL_DATA_VERSION           35
         1144  +#define SQLITE_FCNTL_SIZE_LIMIT             36
  1135   1145   
  1136   1146   /* deprecated names */
  1137   1147   #define SQLITE_GET_LOCKPROXYFILE      SQLITE_FCNTL_GET_LOCKPROXYFILE
  1138   1148   #define SQLITE_SET_LOCKPROXYFILE      SQLITE_FCNTL_SET_LOCKPROXYFILE
  1139   1149   #define SQLITE_LAST_ERRNO             SQLITE_FCNTL_LAST_ERRNO
  1140   1150   
  1141   1151   

Changes to src/tclsqlite.c.

  2414   2414                          (char*)0);
  2415   2415         rc = TCL_ERROR;
  2416   2416       }
  2417   2417       break;
  2418   2418     }
  2419   2419   
  2420   2420     /*
  2421         -  **     $db deserialize ?DATABASE? VALUE
         2421  +  **     $db deserialize ?-maxsize N? ?-readonly BOOL? ?DATABASE? VALUE
  2422   2422     **
  2423   2423     ** Reopen DATABASE (default "main") using the content in $VALUE
  2424   2424     */
  2425   2425     case DB_DESERIALIZE: {
  2426   2426   #ifndef SQLITE_ENABLE_DESERIALIZE
  2427   2427       Tcl_AppendResult(interp, "MEMDB not available in this build",
  2428   2428                        (char*)0);
  2429   2429       rc = TCL_ERROR;
  2430   2430   #else
  2431         -    const char *zSchema;
  2432         -    Tcl_Obj *pValue;
         2431  +    const char *zSchema = 0;
         2432  +    Tcl_Obj *pValue = 0;
  2433   2433       unsigned char *pBA;
  2434   2434       unsigned char *pData;
  2435   2435       int len, xrc;
         2436  +    sqlite3_int64 mxSize = 0;
         2437  +    int i;
         2438  +    int isReadonly = 0;
  2436   2439       
  2437         -    if( objc==3 ){
  2438         -      zSchema = 0;
  2439         -      pValue = objv[2];
  2440         -    }else if( objc==4 ){
  2441         -      zSchema = Tcl_GetString(objv[2]);
  2442         -      pValue = objv[3];
  2443         -    }else{
         2440  +
         2441  +    if( objc<3 ){
  2444   2442         Tcl_WrongNumArgs(interp, 2, objv, "?DATABASE? VALUE");
  2445   2443         rc = TCL_ERROR;
  2446   2444         break;
  2447   2445       }
         2446  +    for(i=2; i<objc-1; i++){
         2447  +      const char *z = Tcl_GetString(objv[i]);
         2448  +      if( strcmp(z,"-maxsize")==0 && i<objc-2 ){
         2449  +        rc = Tcl_GetWideIntFromObj(interp, objv[++i], &mxSize);
         2450  +        if( rc ) goto deserialize_error;
         2451  +        continue;
         2452  +      }
         2453  +      if( strcmp(z,"-readonly")==0 && i<objc-2 ){
         2454  +        rc = Tcl_GetBooleanFromObj(interp, objv[++i], &isReadonly);
         2455  +        if( rc ) goto deserialize_error;
         2456  +        continue;
         2457  +      }
         2458  +      if( zSchema==0 && i==objc-2 && z[0]!='-' ){
         2459  +        zSchema = z;
         2460  +        continue;
         2461  +      }
         2462  +      Tcl_AppendResult(interp, "unknown option: ", z, (char*)0);
         2463  +      rc = TCL_ERROR;
         2464  +      goto deserialize_error;
         2465  +    }
         2466  +    pValue = objv[objc-1];
  2448   2467       pBA = Tcl_GetByteArrayFromObj(pValue, &len);
  2449   2468       pData = sqlite3_malloc64( len );
  2450   2469       if( pData==0 && len>0 ){
  2451   2470         Tcl_AppendResult(interp, "out of memory", (char*)0);
  2452   2471         rc = TCL_ERROR;
  2453   2472       }else{
         2473  +      int flags;
  2454   2474         if( len>0 ) memcpy(pData, pBA, len);
  2455         -      xrc = sqlite3_deserialize(pDb->db, zSchema, pData, len, len,
  2456         -                SQLITE_DESERIALIZE_FREEONCLOSE |
  2457         -                SQLITE_DESERIALIZE_RESIZEABLE);
         2475  +      if( isReadonly ){
         2476  +        flags = SQLITE_DESERIALIZE_FREEONCLOSE | SQLITE_DESERIALIZE_READONLY;
         2477  +      }else{
         2478  +        flags = SQLITE_DESERIALIZE_FREEONCLOSE | SQLITE_DESERIALIZE_RESIZEABLE;
         2479  +      }
         2480  +      xrc = sqlite3_deserialize(pDb->db, zSchema, pData, len, len, flags);
  2458   2481         if( xrc ){
  2459   2482           Tcl_AppendResult(interp, "unable to set MEMDB content", (char*)0);
  2460   2483           rc = TCL_ERROR;
  2461   2484         }
         2485  +      if( mxSize>0 ){
         2486  +        sqlite3_file_control(pDb->db, zSchema,SQLITE_FCNTL_SIZE_LIMIT,&mxSize);
  2462   2487       }
         2488  +    }
         2489  +deserialize_error:
  2463   2490   #endif
  2464   2491       break; 
  2465   2492     }
  2466   2493   
  2467   2494     /*
  2468   2495     **    $db enable_load_extension BOOLEAN
  2469   2496     **

Changes to src/update.c.

   350    350   
   351    351     hasFK = sqlite3FkRequired(pParse, pTab, aXRef, chngKey);
   352    352   
   353    353     /* There is one entry in the aRegIdx[] array for each index on the table
   354    354     ** being updated.  Fill in aRegIdx[] with a register number that will hold
   355    355     ** the key for accessing each index.
   356    356     */
          357  +  if( onError==OE_Replace ) bReplace = 1;
   357    358     for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
   358    359       int reg;
   359    360       if( chngKey || hasFK>1 || pIdx==pPk
   360    361        || indexWhereClauseMightChange(pIdx,aXRef,chngRowid)
   361    362       ){
   362    363         reg = ++pParse->nMem;
   363    364         pParse->nMem += pIdx->nColumn;
   364    365       }else{
   365    366         reg = 0;
   366    367         for(i=0; i<pIdx->nKeyCol; i++){
   367    368           if( indexColumnIsBeingUpdated(pIdx, i, aXRef, chngRowid) ){
   368    369             reg = ++pParse->nMem;
   369    370             pParse->nMem += pIdx->nColumn;
   370         -          if( (onError==OE_Replace)
   371         -           || (onError==OE_Default && pIdx->onError==OE_Replace) 
   372         -          ){
          371  +          if( onError==OE_Default && pIdx->onError==OE_Replace ){
   373    372               bReplace = 1;
   374    373             }
   375    374             break;
   376    375           }
   377    376         }
   378    377       }
   379    378       if( reg==0 ) aToOpen[j+1] = 0;

Changes to src/vdbe.c.

   381    381   ** interpret as a string if we want to).  Compute its corresponding
   382    382   ** numeric type, if has one.  Set the pMem->u.r and pMem->u.i fields
   383    383   ** accordingly.
   384    384   */
   385    385   static u16 SQLITE_NOINLINE computeNumericType(Mem *pMem){
   386    386     assert( (pMem->flags & (MEM_Int|MEM_Real))==0 );
   387    387     assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
          388  +  ExpandBlob(pMem);
   388    389     if( sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc)==0 ){
   389    390       return 0;
   390    391     }
   391    392     if( sqlite3Atoi64(pMem->z, &pMem->u.i, pMem->n, pMem->enc)==0 ){
   392    393       return MEM_Int;
   393    394     }
   394    395     return MEM_Real;
................................................................................
  1580   1581         case OP_Divide: {
  1581   1582           /* (double)0 In case of SQLITE_OMIT_FLOATING_POINT... */
  1582   1583           if( rA==(double)0 ) goto arithmetic_result_is_null;
  1583   1584           rB /= rA;
  1584   1585           break;
  1585   1586         }
  1586   1587         default: {
  1587         -        iA = (i64)rA;
  1588         -        iB = (i64)rB;
         1588  +        iA = sqlite3VdbeIntValue(pIn1);
         1589  +        iB = sqlite3VdbeIntValue(pIn2);
  1589   1590           if( iA==0 ) goto arithmetic_result_is_null;
  1590   1591           if( iA==-1 ) iA = 1;
  1591   1592           rB = (double)(iB % iA);
  1592   1593           break;
  1593   1594         }
  1594   1595       }
  1595   1596   #ifdef SQLITE_OMIT_FLOATING_POINT
................................................................................
  6168   6169     p->apCsr = (VdbeCursor **)&aMem[p->nMem];
  6169   6170     pFrame->aOnce = (u8*)&p->apCsr[pProgram->nCsr];
  6170   6171     memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
  6171   6172     p->aOp = aOp = pProgram->aOp;
  6172   6173     p->nOp = pProgram->nOp;
  6173   6174   #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
  6174   6175     p->anExec = 0;
         6176  +#endif
         6177  +#ifdef SQLITE_DEBUG
         6178  +  /* Verify that second and subsequent executions of the same trigger do not
         6179  +  ** try to reuse register values from the first use. */
         6180  +  {
         6181  +    int i;
         6182  +    for(i=0; i<p->nMem; i++){
         6183  +      aMem[i].pScopyFrom = 0;  /* Prevent false-positive AboutToChange() errs */
         6184  +      aMem[i].flags |= MEM_Undefined; /* Cause a fault if this reg is reused */
         6185  +    }
         6186  +  }
  6175   6187   #endif
  6176   6188     pOp = &aOp[-1];
  6177   6189   
  6178   6190     break;
  6179   6191   }
  6180   6192   
  6181   6193   /* Opcode: Param P1 P2 * * *

Changes to src/vdbeaux.c.

   634    634     sIter.v = v;
   635    635   
   636    636     while( (pOp = opIterNext(&sIter))!=0 ){
   637    637       int opcode = pOp->opcode;
   638    638       if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename 
   639    639        || opcode==OP_VDestroy
   640    640        || ((opcode==OP_Halt || opcode==OP_HaltIfNull) 
   641         -      && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
          641  +      && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort))
   642    642       ){
   643    643         hasAbort = 1;
   644    644         break;
   645    645       }
   646    646       if( opcode==OP_CreateBtree && pOp->p3==BTREE_INTKEY ) hasCreateTable = 1;
   647    647       if( opcode==OP_InitCoroutine ) hasInitCoroutine = 1;
   648    648   #ifndef SQLITE_OMIT_FOREIGN_KEY
................................................................................
  3790   3790   void sqlite3VdbeRecordUnpack(
  3791   3791     KeyInfo *pKeyInfo,     /* Information about the record format */
  3792   3792     int nKey,              /* Size of the binary record */
  3793   3793     const void *pKey,      /* The binary record */
  3794   3794     UnpackedRecord *p      /* Populate this structure before returning. */
  3795   3795   ){
  3796   3796     const unsigned char *aKey = (const unsigned char *)pKey;
  3797         -  int d; 
         3797  +  u32 d; 
  3798   3798     u32 idx;                        /* Offset in aKey[] to read from */
  3799   3799     u16 u;                          /* Unsigned loop counter */
  3800   3800     u32 szHdr;
  3801   3801     Mem *pMem = p->aMem;
  3802   3802   
  3803   3803     p->default_rc = 0;
  3804   3804     assert( EIGHT_BYTE_ALIGNMENT(pMem) );
  3805   3805     idx = getVarint32(aKey, szHdr);
  3806   3806     d = szHdr;
  3807   3807     u = 0;
  3808         -  while( idx<szHdr && d<=nKey ){
         3808  +  while( idx<szHdr && d<=(u32)nKey ){
  3809   3809       u32 serial_type;
  3810   3810   
  3811   3811       idx += getVarint32(&aKey[idx], serial_type);
  3812   3812       pMem->enc = pKeyInfo->enc;
  3813   3813       pMem->db = pKeyInfo->db;
  3814   3814       /* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */
  3815   3815       pMem->szMalloc = 0;
  3816   3816       pMem->z = 0;
  3817   3817       d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
  3818   3818       pMem++;
  3819   3819       if( (++u)>=p->nField ) break;
  3820   3820     }
  3821         -  if( d>nKey && u ){
         3821  +  if( d>(u32)nKey && u ){
  3822   3822       assert( CORRUPT_DB );
  3823   3823       /* In a corrupt record entry, the last pMem might have been set up using 
  3824   3824       ** uninitialized memory. Overwrite its value with NULL, to prevent
  3825   3825       ** warnings from MSAN. */
  3826   3826       sqlite3VdbeMemSetNull(pMem-1);
  3827   3827     }
  3828   3828     assert( u<=pKeyInfo->nKeyField + 1 );
................................................................................
  3898   3898   
  3899   3899       /* Extract the values to be compared.
  3900   3900       */
  3901   3901       d1 += sqlite3VdbeSerialGet(&aKey1[d1], serial_type1, &mem1);
  3902   3902   
  3903   3903       /* Do the comparison
  3904   3904       */
  3905         -    rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i], pKeyInfo->aColl[i]);
         3905  +    rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i],
         3906  +                           pKeyInfo->nAllField>i ? pKeyInfo->aColl[i] : 0);
  3906   3907       if( rc!=0 ){
  3907   3908         assert( mem1.szMalloc==0 );  /* See comment below */
  3908   3909         if( pKeyInfo->aSortOrder[i] ){
  3909   3910           rc = -rc;  /* Invert the result for DESC sort order. */
  3910   3911         }
  3911   3912         goto debugCompareEnd;
  3912   3913       }
................................................................................
  4329   4330           rc = -1;
  4330   4331         }else if( !(serial_type & 0x01) ){
  4331   4332           rc = +1;
  4332   4333         }else{
  4333   4334           mem1.n = (serial_type - 12) / 2;
  4334   4335           testcase( (d1+mem1.n)==(unsigned)nKey1 );
  4335   4336           testcase( (d1+mem1.n+1)==(unsigned)nKey1 );
  4336         -        if( (d1+mem1.n) > (unsigned)nKey1 ){
         4337  +        if( (d1+mem1.n) > (unsigned)nKey1
         4338  +         || (pKeyInfo = pPKey2->pKeyInfo)->nAllField<=i
         4339  +        ){
  4337   4340             pPKey2->errCode = (u8)SQLITE_CORRUPT_BKPT;
  4338   4341             return 0;                /* Corruption */
  4339         -        }else if( (pKeyInfo = pPKey2->pKeyInfo)->aColl[i] ){
         4342  +        }else if( pKeyInfo->aColl[i] ){
  4340   4343             mem1.enc = pKeyInfo->enc;
  4341   4344             mem1.db = pKeyInfo->db;
  4342   4345             mem1.flags = MEM_Str;
  4343   4346             mem1.z = (char*)&aKey1[d1];
  4344   4347             rc = vdbeCompareMemString(
  4345   4348                 &mem1, pRhs, pKeyInfo->aColl[i], &pPKey2->errCode
  4346   4349             );

Changes to src/vdbemem.c.

   239    239   ** and MEM_Blob values may be discarded, MEM_Int, MEM_Real, and MEM_Null
   240    240   ** values are preserved.
   241    241   **
   242    242   ** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
   243    243   ** if unable to complete the resizing.
   244    244   */
   245    245   int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){
   246         -  assert( szNew>0 );
          246  +  assert( CORRUPT_DB || szNew>0 );
   247    247     assert( (pMem->flags & MEM_Dyn)==0 || pMem->szMalloc==0 );
   248    248     if( pMem->szMalloc<szNew ){
   249    249       return sqlite3VdbeMemGrow(pMem, szNew, 0);
   250    250     }
   251    251     assert( (pMem->flags & MEM_Dyn)==0 );
   252    252     pMem->z = pMem->zMalloc;
   253    253     pMem->flags &= (MEM_Null|MEM_Int|MEM_Real);
................................................................................
  1527   1527   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
  1528   1528     else if( op==TK_FUNCTION && pCtx!=0 ){
  1529   1529       rc = valueFromFunction(db, pExpr, enc, affinity, &pVal, pCtx);
  1530   1530     }
  1531   1531   #endif
  1532   1532     else if( op==TK_TRUEFALSE ){
  1533   1533        pVal = valueNew(db, pCtx);
         1534  +    if( pVal ){
  1534   1535        pVal->flags = MEM_Int;
  1535   1536        pVal->u.i = pExpr->u.zToken[4]==0;
  1536   1537     }
         1538  +  }
  1537   1539   
  1538   1540     *ppVal = pVal;
  1539   1541     return rc;
  1540   1542   
  1541   1543   no_mem:
  1542   1544   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
  1543   1545     if( pCtx==0 || pCtx->pParse->nErr==0 )

Changes to src/walker.c.

    13     13   ** an SQL statement.
    14     14   */
    15     15   #include "sqliteInt.h"
    16     16   #include <stdlib.h>
    17     17   #include <string.h>
    18     18   
    19     19   
           20  +#if !defined(SQLITE_OMIT_WINDOWFUNC)
           21  +/*
           22  +** Walk all expressions linked into the list of Window objects passed
           23  +** as the second argument.
           24  +*/
           25  +static int walkWindowList(Walker *pWalker, Window *pList){
           26  +  Window *pWin;
           27  +  for(pWin=pList; pWin; pWin=pWin->pNextWin){
           28  +    if( sqlite3WalkExprList(pWalker, pWin->pOrderBy) ) return WRC_Abort;
           29  +    if( sqlite3WalkExprList(pWalker, pWin->pPartition) ) return WRC_Abort;
           30  +    if( sqlite3WalkExpr(pWalker, pWin->pFilter) ) return WRC_Abort;
           31  +  }
           32  +  return WRC_Continue;
           33  +}
           34  +#endif
           35  +
    20     36   /*
    21     37   ** Walk an expression tree.  Invoke the callback once for each node
    22     38   ** of the expression, while descending.  (In other words, the callback
    23     39   ** is invoked before visiting children.)
    24     40   **
    25     41   ** The return value from the callback should be one of the WRC_*
    26     42   ** constants to specify how to proceed with the walk.
................................................................................
    52     68         }else if( ExprHasProperty(pExpr, EP_xIsSelect) ){
    53     69           if( sqlite3WalkSelect(pWalker, pExpr->x.pSelect) ) return WRC_Abort;
    54     70         }else if( pExpr->x.pList ){
    55     71           if( sqlite3WalkExprList(pWalker, pExpr->x.pList) ) return WRC_Abort;
    56     72         }
    57     73   #ifndef SQLITE_OMIT_WINDOWFUNC
    58     74         if( ExprHasProperty(pExpr, EP_WinFunc) ){
    59         -        Window *pWin = pExpr->y.pWin;
    60         -        if( sqlite3WalkExprList(pWalker, pWin->pPartition) ) return WRC_Abort;
    61         -        if( sqlite3WalkExprList(pWalker, pWin->pOrderBy) ) return WRC_Abort;
    62         -        if( sqlite3WalkExpr(pWalker, pWin->pFilter) ) return WRC_Abort;
           75  +        if( walkWindowList(pWalker, pExpr->y.pWin) ) return WRC_Abort;
    63     76         }
    64     77   #endif
    65     78       }
    66     79       break;
    67     80     }
    68     81     return WRC_Continue;
    69     82   }
................................................................................
    95    108   int sqlite3WalkSelectExpr(Walker *pWalker, Select *p){
    96    109     if( sqlite3WalkExprList(pWalker, p->pEList) ) return WRC_Abort;
    97    110     if( sqlite3WalkExpr(pWalker, p->pWhere) ) return WRC_Abort;
    98    111     if( sqlite3WalkExprList(pWalker, p->pGroupBy) ) return WRC_Abort;
    99    112     if( sqlite3WalkExpr(pWalker, p->pHaving) ) return WRC_Abort;
   100    113     if( sqlite3WalkExprList(pWalker, p->pOrderBy) ) return WRC_Abort;
   101    114     if( sqlite3WalkExpr(pWalker, p->pLimit) ) return WRC_Abort;
          115  +#if !defined(SQLITE_OMIT_WINDOWFUNC) && !defined(SQLITE_OMIT_ALTERTABLE)
          116  +  {
          117  +    Parse *pParse = pWalker->pParse;
          118  +    if( pParse && IN_RENAME_OBJECT ){
          119  +      int rc = walkWindowList(pWalker, p->pWinDefn);
          120  +      assert( rc==WRC_Continue );
          121  +      return rc;
          122  +    }
          123  +  }
          124  +#endif
   102    125     return WRC_Continue;
   103    126   }
   104    127   
   105    128   /*
   106    129   ** Walk the parse trees associated with all subqueries in the
   107    130   ** FROM clause of SELECT statement p.  Do not invoke the select
   108    131   ** callback on p, but do invoke it on each FROM clause subquery

Changes to src/where.c.

   305    305       if( pScan->iEquiv>=pScan->nEquiv ) break;
   306    306       pWC = pScan->pOrigWC;
   307    307       k = 0;
   308    308       pScan->iEquiv++;
   309    309     }
   310    310     return 0;
   311    311   }
          312  +
          313  +/*
          314  +** This is whereScanInit() for the case of an index on an expression.
          315  +** It is factored out into a separate tail-recursion subroutine so that
          316  +** the normal whereScanInit() routine, which is a high-runner, does not
          317  +** need to push registers onto the stack as part of its prologue.
          318  +*/
          319  +static SQLITE_NOINLINE WhereTerm *whereScanInitIndexExpr(WhereScan *pScan){
          320  +  pScan->idxaff = sqlite3ExprAffinity(pScan->pIdxExpr);
          321  +  return whereScanNext(pScan);
          322  +}
   312    323   
   313    324   /*
   314    325   ** Initialize a WHERE clause scanner object.  Return a pointer to the
   315    326   ** first match.  Return NULL if there are no matches.
   316    327   **
   317    328   ** The scanner will be searching the WHERE clause pWC.  It will look
   318    329   ** for terms of the form "X <op> <expr>" where X is column iColumn of table
................................................................................
   338    349     Index *pIdx             /* Must be compatible with this index */
   339    350   ){
   340    351     pScan->pOrigWC = pWC;
   341    352     pScan->pWC = pWC;
   342    353     pScan->pIdxExpr = 0;
   343    354     pScan->idxaff = 0;
   344    355     pScan->zCollName = 0;
          356  +  pScan->opMask = opMask;
          357  +  pScan->k = 0;
          358  +  pScan->aiCur[0] = iCur;
          359  +  pScan->nEquiv = 1;
          360  +  pScan->iEquiv = 1;
   345    361     if( pIdx ){
   346    362       int j = iColumn;
   347    363       iColumn = pIdx->aiColumn[j];
   348    364       if( iColumn==XN_EXPR ){
   349    365         pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
   350    366         pScan->zCollName = pIdx->azColl[j];
          367  +      pScan->aiColumn[0] = XN_EXPR;
          368  +      return whereScanInitIndexExpr(pScan);
   351    369       }else if( iColumn==pIdx->pTable->iPKey ){
   352    370         iColumn = XN_ROWID;
   353    371       }else if( iColumn>=0 ){
   354    372         pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
   355    373         pScan->zCollName = pIdx->azColl[j];
   356    374       }
   357    375     }else if( iColumn==XN_EXPR ){
   358    376       return 0;
   359    377     }
   360         -  pScan->opMask = opMask;
   361         -  pScan->k = 0;
   362         -  pScan->aiCur[0] = iCur;
   363    378     pScan->aiColumn[0] = iColumn;
   364         -  pScan->nEquiv = 1;
   365         -  pScan->iEquiv = 1;
   366    379     return whereScanNext(pScan);
   367    380   }
   368    381   
   369    382   /*
   370    383   ** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
   371    384   ** where X is a reference to the iColumn of table iCur or of index pIdx
   372    385   ** if pIdx!=0 and <op> is one of the WO_xx operator codes specified by
................................................................................
  5257   5270       */
  5258   5271       if( pTabItem->fg.viaCoroutine ){
  5259   5272         testcase( pParse->db->mallocFailed );
  5260   5273         translateColumnToCopy(pParse, pLevel->addrBody, pLevel->iTabCur,
  5261   5274                               pTabItem->regResult, 0);
  5262   5275         continue;
  5263   5276       }
         5277  +
         5278  +#ifdef SQLITE_ENABLE_EARLY_CURSOR_CLOSE
         5279  +    /* Close all of the cursors that were opened by sqlite3WhereBegin.
         5280  +    ** Except, do not close cursors that will be reused by the OR optimization
         5281  +    ** (WHERE_OR_SUBCLAUSE).  And do not close the OP_OpenWrite cursors
         5282  +    ** created for the ONEPASS optimization.
         5283  +    */
         5284  +    if( (pTab->tabFlags & TF_Ephemeral)==0
         5285  +     && pTab->pSelect==0
         5286  +     && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0
         5287  +    ){
         5288  +      int ws = pLoop->wsFlags;
         5289  +      if( pWInfo->eOnePass==ONEPASS_OFF && (ws & WHERE_IDX_ONLY)==0 ){
         5290  +        sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
         5291  +      }
         5292  +      if( (ws & WHERE_INDEXED)!=0
         5293  +       && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0 
         5294  +       && pLevel->iIdxCur!=pWInfo->aiCurOnePass[1]
         5295  +      ){
         5296  +        sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
         5297  +      }
         5298  +    }
         5299  +#endif
  5264   5300   
  5265   5301       /* If this scan uses an index, make VDBE code substitutions to read data
  5266   5302       ** from the index instead of from the table where possible.  In some cases
  5267   5303       ** this optimization prevents the table from ever being read, which can
  5268   5304       ** yield a significant performance boost.
  5269   5305       ** 
  5270   5306       ** Calls to the code generator in between sqlite3WhereBegin and

Changes to src/window.c.

  1071   1071     VdbeCoverageIf(v, eCond==0);
  1072   1072     VdbeCoverageIf(v, eCond==1);
  1073   1073     VdbeCoverageIf(v, eCond==2);
  1074   1074     sqlite3VdbeAddOp3(v, aOp[eCond], regZero, sqlite3VdbeCurrentAddr(v)+2, reg);
  1075   1075     VdbeCoverageNeverNullIf(v, eCond==0);
  1076   1076     VdbeCoverageNeverNullIf(v, eCond==1);
  1077   1077     VdbeCoverageNeverNullIf(v, eCond==2);
         1078  +  sqlite3MayAbort(pParse);
  1078   1079     sqlite3VdbeAddOp2(v, OP_Halt, SQLITE_ERROR, OE_Abort);
  1079   1080     sqlite3VdbeAppendP4(v, (void*)azErr[eCond], P4_STATIC);
  1080   1081     sqlite3ReleaseTempReg(pParse, regZero);
  1081   1082   }
  1082   1083   
  1083   1084   /*
  1084   1085   ** Return the number of arguments passed to the window-function associated

Changes to test/altertab2.test.

   178    178     END}
   179    179   }
   180    180   
   181    181   #-------------------------------------------------------------------------
   182    182   do_execsql_test 5.0 {
   183    183     CREATE TABLE t2(a);
   184    184     CREATE TRIGGER r2 AFTER INSERT ON t2 WHEN new.a NOT NULL BEGIN
   185         -    SELECT a, rank() OVER w1 FROM t2
          185  +    SELECT a, sum(a) OVER w1 FROM t2
   186    186         WINDOW w1 AS (
   187         -        PARTITION BY b ORDER BY d ROWS BETWEEN 2 PRECEDING AND a FOLLOWING
          187  +        PARTITION BY a ORDER BY a 
          188  +        ROWS BETWEEN 2 PRECEDING AND 3 FOLLOWING
   188    189         ),
   189    190         w2 AS (
   190         -        PARTITION BY b 
   191         -        ORDER BY d ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
          191  +        PARTITION BY a
          192  +        ORDER BY rowid ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
   192    193         );
   193    194     END;
   194    195   } {}
   195    196   
   196         -do_catchsql_test 5.0.1 {
          197  +do_execsql_test 5.0.1 {
   197    198     INSERT INTO t2 VALUES(1);
   198         -} {1 {no such column: b}}
          199  +} {}
   199    200   
   200    201   do_execsql_test 5.1 {
   201    202     ALTER TABLE t2 RENAME TO t2x;
   202    203     SELECT sql FROM sqlite_master WHERE name = 'r2';
   203    204   } {
   204    205     {CREATE TRIGGER r2 AFTER INSERT ON "t2x" WHEN new.a NOT NULL BEGIN
   205         -    SELECT a, rank() OVER w1 FROM "t2x"
          206  +    SELECT a, sum(a) OVER w1 FROM "t2x"
   206    207         WINDOW w1 AS (
   207         -        PARTITION BY b ORDER BY d ROWS BETWEEN 2 PRECEDING AND a FOLLOWING
          208  +        PARTITION BY a ORDER BY a 
          209  +        ROWS BETWEEN 2 PRECEDING AND 3 FOLLOWING
   208    210         ),
   209    211         w2 AS (
   210         -        PARTITION BY b 
   211         -        ORDER BY d ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
          212  +        PARTITION BY a
          213  +        ORDER BY rowid ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
   212    214         );
   213    215     END}
   214    216   }
   215    217   
   216    218   do_execsql_test 5.2 {
   217    219     ALTER TABLE t2x RENAME a TO aaaa;
   218    220     SELECT sql FROM sqlite_master WHERE name = 'r2';
   219    221   } {
   220    222     {CREATE TRIGGER r2 AFTER INSERT ON "t2x" WHEN new.aaaa NOT NULL BEGIN
   221         -    SELECT aaaa, rank() OVER w1 FROM "t2x"
          223  +    SELECT aaaa, sum(aaaa) OVER w1 FROM "t2x"
   222    224         WINDOW w1 AS (
   223         -        PARTITION BY b ORDER BY d ROWS BETWEEN 2 PRECEDING AND a FOLLOWING
          225  +        PARTITION BY aaaa ORDER BY aaaa 
          226  +        ROWS BETWEEN 2 PRECEDING AND 3 FOLLOWING
   224    227         ),
   225    228         w2 AS (
   226         -        PARTITION BY b 
   227         -        ORDER BY d ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
          229  +        PARTITION BY aaaa
          230  +        ORDER BY rowid ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING
   228    231         );
   229    232     END}
   230    233   }
   231    234   
   232         -do_catchsql_test 5.3 {
          235  +do_execsql_test 5.3 {
   233    236     INSERT INTO t2x VALUES(1);
   234         -} {1 {no such column: b}}
          237  +} {}
   235    238   
   236    239   #-------------------------------------------------------------------------
   237    240   
   238    241   do_execsql_test 6.0 {
   239    242     CREATE TABLE t3(a,b,c,d);
   240    243     CREATE TRIGGER r3 AFTER INSERT ON t3 WHEN new.a NOT NULL BEGIN
   241    244       SELECT a,b,c FROM t3 EXCEPT SELECT a,b,c FROM t3 ORDER BY a;
................................................................................
   301    304   } {
   302    305     {CREATE TRIGGER r1 AFTER INSERT ON "xyzzy" BEGIN
   303    306       INSERT INTO t2
   304    307       SELECT a,b,ccc FROM "xyzzy" UNION SELECT d,e,f FROM "xyzzy" ORDER BY b,ccc;
   305    308     END}
   306    309   }
   307    310   
          311  +#-------------------------------------------------------------------------
          312  +reset_db
          313  +do_execsql_test 8.0 {
          314  +  CREATE TABLE t1(a, b, c); 
          315  +  CREATE TABLE t2(a, b, c); 
          316  +  CREATE TABLE t3(d, e, f);
          317  +  CREATE VIEW v1 AS SELECT * FROM t1;
          318  +  CREATE TRIGGER tr AFTER INSERT ON t3 BEGIN
          319  +    UPDATE t2 SET a = new.d;
          320  +    SELECT a, b, c FROM v1;
          321  +  END;
          322  +}
          323  +
          324  +do_execsql_test 8.1 {
          325  +  INSERT INTO t3 VALUES(1, 2, 3);
          326  +}
          327  +
          328  +# The following ALTER TABLE fails as if column "t1.a" is renamed the "a"
          329  +# in the "SELECT a, b, c FROM v1" within the trigger can no longer be
          330  +# resolved. But at one point there was a bug allowing the ALTER TABLE
          331  +# succeed. Which meant the subsequent INSERT statement would fail.
          332  +do_catchsql_test 8.2 {
          333  +  ALTER TABLE t1 RENAME a TO aaa;
          334  +} {1 {error in trigger tr after rename: no such column: a}}
          335  +do_execsql_test 8.3 {
          336  +  INSERT INTO t3 VALUES(4, 5, 6);
          337  +}
          338  +
          339  +do_execsql_test 8.1 {
          340  +  CREATE TABLE t4(a, b);
          341  +  CREATE VIEW v4 AS SELECT * FROM t4 WHERE (a=1 AND 0) OR b=2;
          342  +}
          343  +do_execsql_test 8.2 {
          344  +  ALTER TABLE t4 RENAME a TO c;
          345  +  SELECT sql FROM sqlite_master WHERE name = 'v4'
          346  +} {{CREATE VIEW v4 AS SELECT * FROM t4 WHERE (c=1 AND 0) OR b=2}}
   308    347   
   309    348   finish_test
   310    349   
   311    350   

Added test/altertab3.test.

            1  +# 2019 January 23
            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  +#
           12  +
           13  +set testdir [file dirname $argv0]
           14  +source $testdir/tester.tcl
           15  +set testprefix altertab3
           16  +
           17  +# If SQLITE_OMIT_ALTERTABLE is defined, omit this file.
           18  +ifcapable !altertable {
           19  +  finish_test
           20  +  return
           21  +}
           22  +
           23  +do_execsql_test 1.0 {
           24  +  CREATE TABLE t1(a, b);
           25  +  CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
           26  +    SELECT sum(b) OVER w FROM t1 WINDOW w AS (ORDER BY a);
           27  +  END;
           28  +}
           29  +
           30  +do_execsql_test 1.1 {
           31  +  ALTER TABLE t1 RENAME a TO aaa;
           32  +}
           33  +
           34  +do_execsql_test 1.2 {
           35  +  SELECT sql FROM sqlite_master WHERE name='tr1'
           36  +} {{CREATE TRIGGER tr1 AFTER INSERT ON t1 BEGIN
           37  +    SELECT sum(b) OVER w FROM t1 WINDOW w AS (ORDER BY aaa);
           38  +  END}}
           39  +
           40  +do_execsql_test 1.3 {
           41  +  INSERT INTO t1 VALUES(1, 2);
           42  +}
           43  +
           44  +#-------------------------------------------------------------------------
           45  +reset_db
           46  +do_execsql_test 2.0 {
           47  +  CREATE TABLE t1(a,b,c);
           48  +  CREATE TABLE t2(a,b,c);
           49  +  CREATE TRIGGER r1 AFTER INSERT ON t1 WHEN new.a NOT NULL BEGIN
           50  +    SELECT a,b, a name FROM t1 
           51  +      INTERSECT 
           52  +    SELECT a,b,c FROM t1 WHERE b>='d' ORDER BY name;
           53  +    SELECT new.c;
           54  +  END;
           55  +}
           56  +
           57  +do_execsql_test 2.1 {
           58  +  ALTER TABLE t1 RENAME TO t1x;
           59  +  SELECT sql FROM sqlite_master WHERE name = 'r1';
           60  +} {{CREATE TRIGGER r1 AFTER INSERT ON "t1x" WHEN new.a NOT NULL BEGIN
           61  +    SELECT a,b, a name FROM "t1x" 
           62  +      INTERSECT 
           63  +    SELECT a,b,c FROM "t1x" WHERE b>='d' ORDER BY name;
           64  +    SELECT new.c;
           65  +  END}}
           66  +
           67  +#-------------------------------------------------------------------------
           68  +reset_db
           69  +do_execsql_test 3.0 {
           70  +  CREATE TABLE t1(a, b, c, d);
           71  +  CREATE VIEW v1 AS SELECT * FROM t1 WHERE a=1 OR (b IN ());
           72  +}
           73  +
           74  +do_execsql_test 3.1 {
           75  +  ALTER TABLE t1 RENAME b TO bbb;
           76  +}
           77  +
           78  +do_execsql_test 3.2 {
           79  +  SELECT sql FROM sqlite_master WHERE name = 'v1'
           80  +} {{CREATE VIEW v1 AS SELECT * FROM t1 WHERE a=1 OR (bbb IN ())}}
           81  +
           82  +
           83  +
           84  +finish_test
           85  +
           86  +

Changes to test/corruptL.test.

   128    128   do_catchsql_test 1.2 {
   129    129     SELECT sum(s+length(b)) FROM t1 WHERE a IN (110,10,150) AND q IS NULL;
   130    130   } {1 {no such table: t1}}
   131    131   
   132    132   do_catchsql_test 1.3 {
   133    133     REINDEX t1;
   134    134   } {1 {unable to identify the object to be reindexed}}
          135  +
          136  +#-------------------------------------------------------------------------
          137  +reset_db
          138  +do_test 2.0 {
          139  +  sqlite3 db {}
          140  +  db deserialize [decode_hexdb {
          141  +| size 20480 pagesize 4096 filename crash.txt.db
          142  +| page 1 offset 0
          143  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          144  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 05   .....@  ........
          145  +|     32: 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 04   ................
          146  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
          147  +|     96: 00 00 00 00 0d 00 00 00 05 0e 55 00 0f 74 0f 3c   ..........U..t.<
          148  +|    112: 0e f9 0e d1 0e 55 00 00 00 00 00 00 00 00 00 00   .....U..........
          149  +|   3664: 00 00 00 00 00 7a 05 07 15 11 11 08 81 63 76 69   .....z.......cvi
          150  +|   3680: 65 77 76 31 76 31 43 52 45 41 54 45 20 56 49 45   ewv1v1CREATE VIE
          151  +|   3696: 57 20 76 31 28 78 2c 79 29 20 41 53 0a 53 45 4c   W v1(x,y) AS.SEL
          152  +|   3712: 45 43 54 20 74 31 2e 62 2c 74 32 2e 62 20 46 52   ECT t1.b,t2.b FR
          153  +|   3728: 4f 4d 20 74 31 2c 74 32 20 57 48 45 52 45 20 74   OM t1,t2 WHERE t
          154  +|   3744: 31 2e 61 3d 74 32 2e 61 20 47 52 4f 55 50 20 42   1.a=t2.a GROUP B
          155  +|   3760: 59 20 31 20 48 41 56 49 4e 47 20 74 32 2e 63 20   Y 1 HAVING t2.c 
          156  +|   3776: 4e 4f 54 20 4e 55 4c 4c 0a 4c 49 4d 49 54 20 31   NOT NULL.LIMIT 1
          157  +|   3792: 30 26 04 06 17 11 11 01 39 74 61 62 6c 65 74 32   0&......9tablet2
          158  +|   3808: 74 32 05 43 52 45 41 54 45 20 54 41 42 4c 45 20   t2.CREATE TABLE 
          159  +|   3824: 74 32 28 61 2c 62 2c 63 29 41 03 06 17 15 11 01   t2(a,b,c)A......
          160  +|   3840: 6b 69 6e 64 65 78 74 31 78 31 74 31 04 43 52 45   kindext1x1t1.CRE
          161  +|   3856: 41 54 45 20 49 4e 44 45 58 20 73 31 78 31 20 4f   ATE INDEX s1x1 O
          162  +|   3872: 4e 20 74 31 28 64 29 20 57 48 45 52 45 20 65 65   N t1(d) WHERE ee
          163  +|   3888: 20 49 53 20 4e 4f 54 20 4e 55 4c 4c 36 02 06 17    IS NOT NULL6...
          164  +|   3904: 17 11 01 53 69 6e 64 65 78 74 31 61 62 63 74 31   ...Sindext1abct1
          165  +|   3920: 03 43 52 45 41 54 45 20 49 4e 44 45 58 20 74 31   .CREATE INDEX t1
          166  +|   3936: 61 62 63 20 4f 4e 20 74 31 28 61 2c 62 2c 63 2b   abc ON t1(a,b,c+
          167  +|   3952: 64 2b 65 29 81 09 01 07 17 11 11 01 81 7d 74 61   d+e)..........ta
          168  +|   3968: 62 6c 65 74 31 74 31 02 43 52 45 41 54 45 20 54   blet1t1.CREATE T
          169  +|   3984: 41 42 4c 45 20 74 31 28 61 2c 62 2c 63 2c 64 2c   ABLE t1(a,b,c,d,
          170  +|   4000: 65 2c 66 2c 67 2c 68 2c 6a 2c 6a 6a 2c 6a 6a 6a   e,f,g,h,j,jj,jjj
          171  +|   4016: 2c 6b 2c 61 61 2c 62 62 2c 63 63 2c 64 64 2c 65   ,k,aa,bb,cc,dd,e
          172  +|   4032: 65 20 44 45 46 41 55 4c 54 20 33 2e 31 34 2c 0a   e DEFAULT 3.14,.
          173  +|   4048: 66 66 20 44 45 46 41 55 4c 54 28 27 68 69 63 63   ff DEFAULT('hicc
          174  +|   4064: 75 70 27 29 2c 67 67 20 4e 4f 54 20 4e 55 4c 4c   up'),gg NOT NULL
          175  +|   4080: 20 44 45 46 41 55 4c 54 28 66 61 6c 73 65 29 29    DEFAULT(false))
          176  +| page 2 offset 4096
          177  +|      0: 0d 00 00 00 0a 0e 7b 00 0f dc 0f b6 0f 8f 0f 68   ...............h
          178  +|     16: 0f 41 0f 1a 0e f3 0e cb 0e a3 0e 7b 00 00 00 00   .A..............
          179  +|   3696: 00 00 00 00 00 00 00 00 00 00 00 26 0a 14 01 01   ...........&....
          180  +|   3712: 02 08 00 00 00 00 00 00 00 00 00 00 00 00 07 19   ................
          181  +|   3728: 08 09 5a 00 b4 40 09 1e b8 51 eb 85 1f 68 69 63   ..Z..@...Q...hic
          182  +|   3744: 63 75 70 26 09 14 01 01 02 08 00 00 00 00 00 00   cup&............
          183  +|   3760: 00 00 00 00 00 00 07 19 08 08 50 00 a0 40 09 1e   ..........P..@..
          184  +|   3776: b8 51 eb 85 1f 68 69 63 63 75 70 26 08 14 01 01   .Q...hiccup&....
          185  +|   3792: 02 08 00 00 00 00 00 00 00 00 00 00 00 00 07 19   ................
          186  +|   3808: 08 07 46 00 8c 40 09 1e b8 51 eb 85 1f 68 69 63   ..F..@...Q...hic
          187  +|   3824: 63 75 70 25 07 14 01 01 01 08 00 00 00 00 00 00   cup%............
          188  +|   3840: 00 00 00 00 00 00 07 b9 08 06 3c 78 40 09 1e b8   ..........<x@...
          189  +|   3856: 51 eb 85 1f 68 69 63 63 75 70 25 06 14 01 00 01   Q...hiccup%.....
          190  +|   3872: 08 00 00 00 00 00 00 00 00 00 00 00 00 07 19 08   ................
          191  +|   3888: 05 32 64 40 09 1e b8 51 eb 85 1f 68 69 63 63 75   .2d@...Q...hiccu
          192  +|   3904: 70 25 05 14 01 01 01 08 00 00 00 00 00 00 00 00   p%..............
          193  +|   3920: 00 00 00 00 07 19 08 04 28 50 40 09 1e b8 51 eb   ........(P@...Q.
          194  +|   3936: 85 1f 68 69 63 63 75 70 25 04 14 01 01 01 08 00   ..hiccup%.......
          195  +|   3952: 00 00 00 00 00 00 00 00 00 00 00 07 19 08 03 1e   ................
          196  +|   3968: 3c 40 09 1e b8 51 eb 85 1f 68 69 63 63 75 70 25   <@...Q...hiccup%
          197  +|   3984: 03 14 01 01 01 08 00 00 00 00 00 00 00 00 00 00   ................
          198  +|   4000: 00 00 07 19 08 02 14 28 40 09 1e b8 51 eb 85 1f   .......(@...Q...
          199  +|   4016: 68 69 63 63 75 70 24 02 14 09 01 01 08 00 00 00   hiccup$.........
          200  +|   4032: 00 00 00 00 00 00 00 00 00 07 19 08 0a 14 40 09   ..............@.
          201  +|   4048: 1e b8 51 eb 85 1f 68 69 63 63 75 70 22 01 14 08   ..Q...hiccup....
          202  +|   4064: 08 08 07 ff ff ff ff ff ff 00 00 00 00 00 00 07   ................
          203  +|   4080: 19 08 40 09 1e b8 51 eb 85 1f 68 69 63 63 75 70   ..@...Q...hiccup
          204  +| page 3 offset 8192
          205  +|      0: 0a 00 00 00 0a 0f aa 00 0f fa 0f f2 0f e9 0f e0   ................
          206  +|     16: 0f d7 0f ce 0f c5 0f bc 0e b3 0f aa 00 00 00 00   ................
          207  +|   4000: 00 00 00 00 00 00 00 00 00 00 08 05 01 01 00 01   ................
          208  +|   4016: 09 5a 0a 08 05 01 01 00 01 08 50 09 08 05 01 01   .Z........P.....
          209  +|   4032: 00 01 07 46 08 08 05 01 01 00 01 06 3c 07 08 05   ...F........<...
          210  +|   4048: 01 01 00 01 05 32 06 08 05 01 01 00 01 04 28 05   .....2........(.
          211  +|   4064: 08 05 01 01 00 01 03 1e 04 08 05 01 01 00 01 02   ................
          212  +|   4080: 14 03 07 05 09 01 00 01 0a 02 05 05 08 08 00 09   ................
          213  +| page 4 offset 12288
          214  +|      0: 0a 00 00 00 0a 0f cf 00 0f fc 0f f7 0f f2 0f ed   ................
          215  +|     16: 0f e8 0f e3 0f de 0f d9 0f d4 0f cf 00 00 00 00   ................
          216  +|   4032: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04   ................
          217  +|   4048: 03 08 01 0a 04 03 08 01 09 04 03 08 01 08 04 03   ................
          218  +|   4064: 08 01 07 04 03 08 01 06 04 03 08 01 05 04 03 08   ................
          219  +|   4080: 01 04 04 03 08 01 13 04 03 08 01 02 03 03 08 09   ................
          220  +| page 5 offset 16384
          221  +|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
          222  +| end crash.txt.db
          223  +}]} {}
          224  +
          225  +do_execsql_test 2.1 {
          226  +  INSERT INTO t1(b) VALUES(X'a0fee3669f9fddefc5cba913e4225d4b6ce2b04f26b87fad3ee6f9b7d90a1ea62a169bf41e5d32707a6ca5c3d05e4bde05c9d89eaaa8c50e74333d2e9fcd7dfe95528a3a016aac1102d825c5cd70cf99d8a88e0ea7f798d4334386518b7ad359beb168b93aba059a2a3bd93112d65b44c12b9904ea786b204d80531cdf0504bf9b203dbe927061974caf7b9f30cbc3397b61f802e732012a6663d41c3607d6f1c0dbcfd489adac05ca500c0b04439d894cd93a840159225ef73b627e178b9f84b3ffe66cf22a963a8368813ff7961fc47f573211ccec95e0220dcbb3bf429f4a50ba54d7a53784ac51bfef346e6ac8ae0d0e7c3175946e62ba2b');
          227  +}
          228  +
          229  +do_catchsql_test 2.2 {
          230  +  SELECT b,c FROM t1 ORDER BY a;
          231  +} {1 {database disk image is malformed}}
          232  +
          233  +#-------------------------------------------------------------------------
          234  +reset_db
          235  +do_execsql_test 3.0 {
          236  +  CREATE TABLE t1(a, b, c, d INTEGER PRIMARY KEY);
          237  +  CREATE TABLE t2(a, b, c, d INTEGER PRIMARY KEY);
          238  +
          239  +  INSERT INTO t1(a, b, c, d) VALUES (1, 2, 3, 100), (4, 5, 6, 101);
          240  +  INSERT INTO t2(a, b, c, d) VALUES (1, 100, 3, 1000), (4, 101, 6, 1001);
          241  +
          242  +  CREATE INDEX t1a ON t1(a);
          243  +  CREATE INDEX t2a ON t2(a, b, c);
          244  +
          245  +  PRAGMA writable_schema = 1;
          246  +  UPDATE sqlite_master SET sql = 'CREATE INDEX t2a ON t2(a)' WHERE name='t2a';
          247  +}
          248  +
          249  +db close
          250  +sqlite3 db test.db
          251  +
          252  +do_catchsql_test 3.1 {
          253  +  INSERT INTO t1 SELECT * FROM t2;
          254  +} {1 {database disk image is malformed}}
          255  +
          256  +#-------------------------------------------------------------------------
          257  +reset_db
          258  +do_test 4.0 {
          259  +  sqlite3 db {}
          260  +  db deserialize [decode_hexdb {
          261  +| size 4096 pagesize 512 filename crash-6b48ba69806134.db
          262  +| page 1 offset 0
          263  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          264  +|     16: 02 00 01 01 00 40 20 20 00 ff ff ff ff 00 00 07   .....@  ........
          265  +|     32: 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 04   ................
          266  +|     48: 00 00 00 00 00 00 00 05 00 eb 00 01 00 00 00 00   ................
          267  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0c   ................
          268  +|     96: 00 2e 2c 50 0d 00 00 00 06 01 06 00 01 da 01 b0   ..,P............
          269  +|    112: 05 56 01 86 01 2a 01 06 00 00 00 00 00 00 00 00   .V...*..........
          270  +|    128: 00 ff 00 00 ff ff ff e1 00 00 00 00 00 00 00 00   ................
          271  +|    144: 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00   ................
          272  +|    160: 00 00 00 00 00 00 00 00 f2 00 00 00 00 00 00 00   ................
          273  +|    176: 00 00 f9 ff ff ff ff ff ff ff 00 00 00 00 00 fb   ................
          274  +|    208: 00 00 00 00 00 00 00 00 1e 00 00 00 fe 00 00 00   ................
          275  +|    224: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ca 00   ................
          276  +|    256: 00 00 00 00 ef ff 22 07 06 17 11 11 01 31 74 61   .............1ta
          277  +|    272: 62 6c 65 74 38 38 74 04 43 52 45 41 54 45 20 54   blet88t.CREATE T
          278  +|    288: 41 42 4c 45 20 74 34 28 87 29 2a 06 06 17 13 11   ABLE t4(.)*.....
          279  +|    304: 01 3f 69 4f 64 65 78 74 33 78 74 33 05 43 52 45   .?iOdext3xt3.CRE
          280  +|    320: 41 54 45 20 49 6e 44 45 58 20 74 33 78 20 4f 4e   ATE InDEX t3x ON
          281  +|    336: 20 74 33 28 78 29 2e 04 06 17 15 11 01 45 69 6e    t3(x).......Ein
          282  +|    352: 64 65 2e 74 32 63 64 74 3d 05 43 52 45 41 54 45   de.t2cdt=.CREATE
          283  +|    368: 20 49 4e 44 45 58 20 74 32 63 64 20 4f 4e 20 74    INDEX t2cd ON t
          284  +|    384: 32 28 0a 0c 44 29 28 05 06 17 11 11 01 3d 74 61   2(..D)(......=ta
          285  +|    400: 62 6c 65 d4 33 74 33 04 43 52 45 41 54 45 20 54   ble.3t3.CREATE T
          286  +|    416: 41 42 4c 45 20 74 33 28 63 2c 78 2c 65 2c 66 29   ABLE t3(c,x,e,f)
          287  +|    432: 28 02 06 17 11 11 01 3d 74 61 62 6c 65 74 32 74   (......=tablet2t
          288  +|    448: 32 03 43 52 45 41 54 45 20 54 41 42 4c 45 20 74   2.CREATE TABLE t
          289  +|    464: 32 28 63 2c 64 2c 65 2c 66 29 24 01 06 17 11 11   2(c,d,e,f)$.....
          290  +|    480: 01 35 74 60 62 6c 65 74 31 74 31 02 43 52 45 41   .5t`blet1t1.CREA
          291  +|    496: 54 45 20 54 41 42 4c 45 20 74 30 28 61 2c 62 29   TE TABLE t0(a,b)
          292  +| page 2 offset 512
          293  +|      0: 0d 00 ff 11 04 01 cf 00 01 fa 01 f3 01 de 01 cf   ................
          294  +|     32: 00 00 08 00 00 00 00 00 00 00 00 00 00 00 00 13   ................
          295  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 20 00 00   ............. ..
          296  +|     64: 00 00 00 00 00 00 f8 ff ff ff 00 00 00 00 00 00   ................
          297  +|    160: 01 64 00 00 00 00 00 80 ff ff ff 00 00 00 00 00   .d..............
          298  +|    176: 00 00 00 00 00 00 00 00 1f 00 00 00 00 00 00 03   ................
          299  +|    192: 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00   ..@.............
          300  +|    288: 00 00 00 00 00 00 ff ff ff e9 00 00 00 00 00 00   ................
          301  +|    336: 01 00 00 ff ff 00 00 00 00 00 00 00 00 00 00 00   ................
          302  +|    368: 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ...............
          303  +|    384: 00 de ff 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
          304  +|    464: 00 00 00 00 00 13 76 65 6e 65 69 67 68 74 13 03   ......veneight..
          305  +|    480: 03 40 07 07 14 00 54 45 20 49 4e 44 45 58 20 74   .@....TE INDEX t
          306  +|    496: 32 63 64 20 4f 4e 20 74 32 28 0a 0c 44 09 01 02   2cd ON t2(..D...
          307  +| page 3 offset 1024
          308  +|      0: 0d 00 00 00 48 01 54 00 01 f7 01 ec 01 c5 01 aa   ....H.T.........
          309  +|     16: 30 34 28 87 29 2a 06 06 17 13 11 01 3f 69 4f 64   04(.)*......?iOd
          310  +|     32: 65 79 74 33 78 74 33 6d 6d 6d 6d 6d 6d 7d 6d 6d   eyt3xt3mmmmmm.mm
          311  +|     48: 6d 41 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d   mAmmmmmmmmmmmmmm
          312  +|     64: 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 66 6d 6d 6d 6d   mmmmmmmmmmmfmmmm
          313  +|     80: 6d 4e 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d   mNmmmmmmmmmmmmmm
          314  +|     96: 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d   mmmmmmmmmmmmmmmm
          315  +|    112: 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d 6d   mmmmmmmmmmmmmmmm
          316  +|    128: 6d 6d 6d 6d 6d 00 00 00 00 00 00 00 00 00 00 00   mmmmm...........
          317  +|    160: 80 00 00 00 00 00 00 03 00 00 00 ff e4 00 00 00   ................
          318  +|    208: 00 00 00 00 00 00 00 00 00 00 00 00 00 c5 00 00   ................
          319  +|    240: 14 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00   ................
          320  +|    256: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f ec   ................
          321  +|    304: 00 00 00 00 19 08 05 17 17 17 17 65 69 67 68 74   ...........eight
          322  +|    320: 65 69 67 68 74 73 65 00 00 00 00 00 00 00 00 00   eightse.........
          323  +|    336: 00 00 00 00 19 08 05 17 17 17 17 65 69 67 68 74   ...........eight
          324  +|    352: 65 69 67 68 74 73 65 01 65 6e 00 00 00 10 25 07   eightse.en....%.
          325  +|    368: 07 6e 25 07 07 07 40 18 00 00 00 00 00 00 40 18   .n%...@.......@.
          326  +|    384: 00 00 00 00 00 00 40 14 00 00 00 00 00 00 40 14   ......@.......@.
          327  +|    400: 00 00 00 00 00 00 09 06 05 01 01 01 01 04 04 03   ................
          328  +|    416: 03 07 05 05 01 01 09 09 02 02 19 04 05 17 17 17   ................
          329  +|    432: 17 10 65 76 65 6e 65 69 67 68 74 65 69 67 68 74   ..eveneighteight
          330  +|    448: 73 65 76 65 6e 25 03 05 07 07 07 07 40 14 00 00   seven%......@...
          331  +|    464: 00 00 00 00 40 18 00 00 00 00 00 00 40 18 00 00   ....@.......@...
          332  +|    480: 00 00 00 00 40 14 00 00 00 00 e8 f6 09 02 00 00   ....@...........
          333  +|    496: 00 00 00 00 00 00 00 00 00 00 64 00 00 00 00 02   ..........d.....
          334  +| page 4 offset 1536
          335  +|      0: 0d 00 00 00 00 02 00 00 00 00 00 00 00 00 00 fa   ................
          336  +|     16: 1f a1 07 00 00 00 00 00 01 00 00 00 00 00 00 00   ................
          337  +|     32: 00 00 00 00 00 00 00 00 00 00 00 00 00 73 69 6d   .............sim
          338  +|     48: 70 6c 65 00 00 00 00 00 00 00 00 00 00 00 00 00   ple.............
          339  +|     80: 00 00 00 00 00 10 00 00 00 00 00 00 01 00 00 00   ................
          340  +|     96: 00 00 00 00 00 00 00 00 00 00 00 00 00 fe ff ff   ................
          341  +|    112: ff 00 00 00 00 00 00 00 00 00 00 00 4a 00 00 00   ............J...
          342  +|    144: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
          343  +|    176: e5 ff ff ff 00 00 00 00 00 00 00 00 00 00 00 00   ................
          344  +|    208: 00 00 00 00 00 00 00 00 00 00 36 36 00 00 00 00   ..........66....
          345  +|    240: 00 00 00 6c 00 00 00 00 00 00 00 00 00 00 00 00   ...l............
          346  +|    256: 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
          347  +|    320: 00 00 00 00 00 00 00 00 01 00 00 02 00 80 00 00   ................
          348  +|    336: 00 00 00 00 00 19 08 05 17 17 17 17 65 69 67 68   ............eigh
          349  +|    352: 74 65 69 67 68 74 73 65 76 65 6e 73 65 76 65 6e   teightsevenseven
          350  +|    368: 25 07 05 07 07 07 07 40 18 00 00 00 00 00 00 40   %......@.......@
          351  +|    384: 18 00 20 00 00 00 40 00 14 00 00 00 00 00 00 40   .. ...@........@
          352  +|    400: 14 00 00 00 00 00 1c 09 06 05 01 01 01 01 04 04   ................
          353  +|    416: 03 03 07 05 05 01 01 00 00 00 00 00 00 00 00 00   ................
          354  +|    448: 74 73 65 76 65 6e 00 80 ff ff 00 00 00 00 00 aa   tseven..........
          355  +|    464: 00 9e 00 00 00 00 00 00 00 00 00 00 00 70 6f 72   .............por
          356  +|    480: 74 65 72 00 00 00 00 00 00 00 00 00 00 00 00 00   ter.............
          357  +|    496: 00 00 00 00 00 00 29 00 00 00 00 00 00 00 00 00   ......).........
          358  +| page 5 offset 2048
          359  +|      0: 0a 00 00 00 08 01 96 00 01 fa 01 c5 01 f2 01 bc   ................
          360  +|     16: 01 dc 01 a6 01 96 01 cc 00 00 00 00 00 00 00 00   ................
          361  +|    112: 00 00 00 09 00 00 00 00 01 00 00 00 00 00 00 00   ................
          362  +|    160: 74 72 69 67 62 ff ff ff ff fc 00 00 00 00 00 00   trigb...........
          363  +|    240: 00 00 00 00 00 00 00 00 00 00 ff 00 00 00 00 00   ................
          364  +|    256: e5 ff ff ff 00 00 54 00 00 00 00 00 00 00 00 00   ......T.........
          365  +|    304: 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00 00   ................
          366  +|    400: 00 00 00 00 00 09 00 00 00 00 01 00 00 00 00 00   ................
          367  +|    448: 00 00 74 72 69 67 62 ff ff ff ff fc 00 00 07 05   ..trigb.........
          368  +|    464: 05 01 01 09 09 02 02 19 04 05 17 17 17 17 10 65   ...............e
          369  +|    480: 76 65 6e 65 69 67 68 74 65 40 18 00 00 00 00 01   veneighte@......
          370  +|    496: 02 03 07 04 01 01 01 03 04 02 05 04 09 01 ff fd   ................
          371  +| end crash-6b48ba69806134.db
          372  +}]} {}
          373  +
          374  +do_catchsql_test 4.1 {
          375  +  INSERT INTO t3 SELECT * FROM t2;
          376  +} {1 {database disk image is malformed}}
          377  +
          378  +
          379  +#-------------------------------------------------------------------------
          380  +reset_db
          381  +do_test 5.0 {
          382  +  sqlite3 db {}
          383  +  db deserialize [decode_hexdb {
          384  +| size 192512 pagesize 4096 filename crash-9ae5502296c949.db
          385  +| page 1 offset 0
          386  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          387  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 2f   .....@  ......./
          388  +|     32: 00 00 00 1b 00 00 00 13 00 00 00 03 00 00 00 04   ................
          389  +|     48: 00 00 00 00 00 00 00 06 00 00 00 01 00 00 00 00   ................
          390  +|     64: 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00   ................
          391  +|     96: 00 00 00 00 0d 00 00 00 04 0e e2 00 0f 96 0f 44   ...............D
          392  +|    112: 0f 10 0e e2 00 00 00 00 00 00 00 00 00 00 00 00   ................
          393  +|   3808: 00 00 2c 04 06 17 15 11 01 41 69 6e 64 65 78 74   ..,......Aindext
          394  +|   3824: 31 78 32 74 31 06 43 52 45 41 54 45 20 49 4e 44   1x2t1.CREATE IND
          395  +|   3840: 45 58 20 74 31 78 32 20 4f 4e 20 74 31 28 62 29   EX t1x2 ON t1(b)
          396  +|   3856: 32 03 06 17 15 11 01 4d 69 6e 64 65 78 74 31 78   2......Mindext1x
          397  +|   3872: 31 74 31 05 43 52 45 41 54 45 20 49 4e 44 45 58   1t1.CREATE INDEX
          398  +|   3888: 20 74 31 78 31 20 4f 4e 20 74 31 28 67 2b 68 2c    t1x1 ON t1(g+h,
          399  +|   3904: 6a 2c 6b 29 50 02 06 17 2b 2b 01 59 74 61 62 6c   j,k)P...++.Ytabl
          400  +|   3920: 65 73 71 6c 69 74 65 5f 73 65 71 75 65 6e 63 65   esqlite_sequence
          401  +|   3936: 73 71 6c 69 74 65 5f 73 65 71 75 65 6e 63 65 04   sqlite_sequence.
          402  +|   3952: 43 52 45 41 54 45 20 54 41 42 4c 45 20 73 71 6c   CREATE TABLE sql
          403  +|   3968: 69 74 65 5f 73 65 71 75 65 6e 63 65 28 6e 61 6d   ite_sequence(nam
          404  +|   3984: 65 2c 73 65 71 29 68 01 07 17 11 11 01 81 3b 74   e,seq)h.......;t
          405  +|   4000: 61 62 6c 65 74 31 74 31 03 43 52 45 41 54 45 20   ablet1t1.CREATE 
          406  +|   4016: 54 41 42 4c 45 20 74 31 28 61 20 49 4e 54 45 47   TABLE t1(a INTEG
          407  +|   4032: 45 52 20 50 52 49 4d 41 52 59 20 4b 45 59 20 41   ER PRIMARY KEY A
          408  +|   4048: 55 54 4f 49 4e 43 52 45 4d 45 4e 54 2c 0a 62 2c   UTOINCREMENT,.b,
          409  +|   4064: 63 2c 64 2c 65 2c 66 2c 67 2c 68 2c 6a 2c 6b 2c   c,d,e,f,g,h,j,k,
          410  +|   4080: 6c 2c 6d 2c 6e 2c 6f 2c 70 2c 71 2c 72 2c 73 29   l,m,n,o,p,q,r,s)
          411  +| page 2 offset 4096
          412  +|      0: 01 00 00 00 00 01 00 00 00 00 01 00 00 00 00 01   ................
          413  +|     16: 00 00 00 00 02 10 00 00 00 05 00 00 00 03 02 00   ................
          414  +|     32: 00 00 00 05 00 00 00 03 02 00 00 00 00 05 00 00   ................
          415  +|     48: 00 03 02 00 00 00 00 05 00 00 00 03 02 00 00 00   ................
          416  +|     64: 00 05 00 00 00 03 02 00 00 00 00 05 00 00 00 03   ................
          417  +|     80: 02 00 00 00 00 05 00 00 00 03 02 00 00 00 00 05   ................
          418  +|     96: 00 00 00 03 02 00 00 00 00 05 00 00 00 03 05 00   ................
          419  +|    112: 00 00 03 03 00 00 00 23 02 00 00 00 00 03 00 00   .......#........
          420  +|    128: 00 23 02 00 00 00 00 03 00 00 00 23 02 00 00 00   .#.........#....
          421  +|    144: 00 03 00 00 00 23 02 00 00 00 00 03 00 00 00 23   .....#.........#
          422  +|    160: 05 00 00 00 06 05 00 00 00 06 02 00 00 00 00 03   ................
          423  +|    176: 00 00 00 06 02 00 00 00 00 03 00 00 00 24 02 00   .............$..
          424  +|    192: 00 00 00 03 00 00 00 24 02 00 00 00 00 03 00 00   .......$........
          425  +|    208: 00 24 02 00 00 00 00 02 00 00 00 00 03 00 00 00   .$..............
          426  +|    224: 24 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   $...............
          427  +| page 3 offset 8192
          428  +|      0: 05 00 00 00 09 0f d0 00 00 00 00 19 0f fb 0f f6   ................
          429  +|     16: 0f f1 0f ec 0f e7 0f e2 0f dc 0f d6 0f d0 0f a0   ................
          430  +|     32: 0f a0 0f a0 0f a0 0f a0 0f a0 0f a0 0f a0 0f a0   ................
          431  +|   1072: 00 97 4c 0a 14 00 ae 7c 00 00 00 00 00 00 00 00   ..L....|........
          432  +|   1088: 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00   ................
          433  +|   4000: 0f ac 00 06 00 00 00 00 00 30 00 00 00 00 00 00   .........0......
          434  +|   4048: 00 00 00 16 81 2a 00 00 00 14 81 16 00 00 00 12   .....*..........
          435  +|   4064: 81 02 00 00 00 10 6e 00 00 00 0e 5a 00 00 00 0c   ......n....Z....
          436  +|   4080: 46 00 00 00 0a 32 00 00 00 08 1e 00 00 00 18 0a   F....2..........
          437  +| page 4 offset 12288
          438  +|      0: 0d 00 00 00 01 0f f7 00 0f f7 00 00 00 00 00 00   ................
          439  +|   4080: 00 00 00 00 00 00 00 07 01 03 11 02 74 31 00 be   ............t1..
          440  +| page 5 offset 16384
          441  +|      0: 0a 0f 7c 00 0a 0f 74 00 0f f9 0f eb 0f dd 0f cf   ..|...t.........
          442  +|     16: 0f c1 0f b3 0f a4 0f 94 0f 84 0f 74 0f 74 0f 74   ...........t.t.t
          443  +|     32: 0f 74 0f 74 0f 74 0f 74 0f 74 0f 74 0f 74 00 00   .t.t.t.t.t.t.t..
          444  +|   3952: 00 00 00 00 07 05 00 00 00 02 00 be 0f 8c 00 08   ................
          445  +|   3968: 00 00 00 00 07 05 00 00 00 02 00 aa 0f 9c 00 08   ................
          446  +|   3984: 00 00 00 00 07 05 00 00 00 02 00 96 0f ac 00 08   ................
          447  +|   4000: 00 00 00 00 07 05 00 00 00 02 00 82 0f ba 00 07   ................
          448  +|   4016: 00 00 00 06 05 00 00 00 01 6e 0f c8 00 07 00 00   .........n......
          449  +|   4032: 00 06 05 00 00 00 01 5a 0f d6 00 07 00 00 00 06   .......Z........
          450  +|   4048: 05 00 00 00 01 46 0f e4 00 07 00 00 00 06 05 00   .....F..........
          451  +|   4064: 00 00 01 32 0f f2 00 07 00 00 00 06 05 00 00 00   ...2............
          452  +|   4080: 01 1e 00 00 00 07 00 00 00 06 05 00 00 00 01 0a   ................
          453  +| page 6 offset 20480
          454  +|      0: 02 00 00 00 01 0e 0d 00 00 00 00 24 0e 0d 0c 1a   ...........$....
          455  +|     16: 06 55 04 66 02 77 00 88 00 00 00 00 00 00 00 00   .U.f.w..........
          456  +|    128: 00 00 00 00 00 00 00 00 97 3d 04 ae 7c 01 00 00   .........=..|...
          457  +|    624: 00 00 00 00 00 00 21 97 3d 04 ae 7c 01 00 00 00   ......!.=..|....
          458  +|   1120: 00 00 00 00 00 20 97 3d 04 ae 7c 01 00 00 00 00   ..... .=..|.....
          459  +|   1616: 00 00 00 00 1f 97 3d 04 ae 7c 01 00 00 00 00 00   ......=..|......
          460  +|   2112: 00 00 00 1e 97 3d 04 ae 7c 01 00 00 00 00 00 00   .....=..|.......
          461  +|   2608: 00 00 1d 97 3d 04 ae 7c 01 00 00 00 00 00 00 00   ....=..|........
          462  +|   3088: 00 00 00 00 00 00 00 00 00 00 00 00 01 f3 00 00   ................
          463  +|   3600: 23 97 3d 04 ae 7c 01 00 00 00 00 00 00 00 00 00   #.=..|..........
          464  +|   4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 26   ...............&
          465  +| page 8 offset 28672
          466  +|      0: 0d 00 00 00 01 04 30 00 04 30 00 00 00 00 00 00   ......0..0......
          467  +|   1072: 97 4d 1e 14 00 ae 7c 00 00 00 00 00 00 00 00 00   .M....|.........
          468  +|   1088: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00   ................
          469  +|   4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03   ................
          470  +| page 10 offset 36864
          471  +|    256: 0d 00 00 00 01 04 30 00 04 30 00 00 00 00 00 00   ......0..0......
          472  +|   1072: 97 4d 32 14 00 ae 7c 00 00 00 00 00 00 00 00 00   .M2...|.........
          473  +|   1088: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00   ................
          474  +|   4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05   ................
          475  +| page 12 offset 45056
          476  +|      0: 0d 00 00 00 01 04 30 00 04 30 00 00 00 00 00 00   ......0..0......
          477  +|   1072: 97 4d 46 14 00 ae 7c 00 00 00 00 00 00 00 00 00   .MF...|.........
          478  +|   1088: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00   ................
          479  +|   4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 07   ................
          480  +| page 14 offset 53248
          481  +|      0: 0d 00 00 00 01 04 30 00 04 30 00 00 00 00 00 00   ......0..0......
          482  +|   1072: 97 4d 5a 14 00 ae 7c 00 00 00 00 00 00 00 00 00   .MZ...|.........
          483  +|   1088: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00   ................
          484  +|   4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09   ................
          485  +| page 16 offset 61440
          486  +|      0: 0d 00 00 00 01 04 30 00 04 30 00 00 00 00 00 00   ......0..0......
          487  +|   1072: 97 4d 6e 14 00 ae 7c 00 00 00 00 00 00 00 00 00   .Mn...|.........
          488  +|   1088: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00   ................
          489  +|   4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0b   ................
          490  +| page 18 offset 69632
          491  +|      0: 0d 00 00 00 01 04 2f 00 04 2f 00 00 00 00 00 00   ....../../......
          492  +|   1056: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 97   ................
          493  +|   1072: 4d 81 02 14 00 ae 7c 00 00 00 00 00 00 00 00 00   M.....|.........
          494  +|   1088: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00   ................
          495  +|   4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0d   ................
          496  +| page 20 offset 77824
          497  +|      0: 0d 00 00 00 01 04 2f 00 04 2f 00 00 00 00 00 00   ....../../......
          498  +|   1056: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 97   ................
          499  +|   1072: 4d 81 16 14 00 ae 7c 00 00 00 00 00 00 00 00 00   M.....|.........
          500  +|   1088: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00   ................
          501  +|   4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f   ................
          502  +| page 22 offset 86016
          503  +|      0: 0d 00 00 00 01 04 2f 00 04 2f 00 00 00 00 00 00   ....../../......
          504  +|   1056: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 97   ................
          505  +|   1072: 4d 81 2a 14 00 ae 7c 00 00 00 00 00 00 00 00 00   M.*...|.........
          506  +|   1088: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00   ................
          507  +|   4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 11   ................
          508  +| page 24 offset 94208
          509  +|      0: 0d 00 00 00 01 04 31 00 04 31 00 00 00 00 00 00   ......1..1......
          510  +|   1072: 00 97 4c 0a 14 00 ae 7c 00 00 00 00 00 00 00 00   ..L....|........
          511  +|   1088: 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00   ................
          512  +| page 25 offset 98304
          513  +|      0: 0d 00 00 00 01 04 2f 00 04 2f 00 00 00 00 00 00   ....../../......
          514  +|   1056: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 97   ................
          515  +|   1072: 4d 81 3e 14 00 ae 7c 00 00 00 00 00 00 00 00 00   M.>...|.........
          516  +|   1088: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00   ................
          517  +|   4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 13   ................
          518  +| page 26 offset 102400
          519  +|   2512: 00 00 00 00 00 00 00 0a 00 00 00 00 00 00 00 00   ................
          520  +| page 27 offset 106496
          521  +|      0: 00 00 00 00 00 00 00 12 00 00 00 07 00 00 00 1d   ................
          522  +|     16: 00 00 00 09 00 00 00 1f 00 00 00 0b 00 00 00 21   ...............!
          523  +|     32: 00 00 00 0d 00 00 00 25 00 00 00 0f 00 00 00 19   .......%........
          524  +|     48: 00 00 00 11 00 00 00 29 00 00 00 13 00 00 00 2b   .......).......+
          525  +|     64: 00 00 00 15 00 00 00 2d 00 00 00 2e 00 00 00 17   .......-........
          526  +| page 28 offset 110592
          527  +|   2512: 00 00 00 00 00 00 00 1e 00 00 00 00 00 00 00 00   ................
          528  +| page 30 offset 118784
          529  +|   2512: 00 00 00 00 00 00 00 32 00 00 00 00 00 00 00 00   .......2........
          530  +| page 32 offset 126976
          531  +|   2512: 00 00 00 00 00 00 00 46 00 00 00 00 00 00 00 00   .......F........
          532  +| page 34 offset 135168
          533  +|   2512: 00 00 00 00 00 00 00 5a 00 00 00 00 00 00 00 00   .......Z........
          534  +| page 35 offset 139264
          535  +|      0: 0a 08 44 00 05 02 77 00 0e 11 0a 33 06 55 02 77   ..D...w....3.U.w
          536  +|     16: 04 66 00 88 00 88 00 88 00 00 00 00 00 00 00 00   .f..............
          537  +|    128: 00 00 00 00 00 00 00 00 04 66 01 ef 00 00 00 00   .........f......
          538  +|    624: 00 00 00 00 00 00 00 97 3d 04 ae 7c 01 00 00 00   ........=..|....
          539  +|   1120: 00 00 00 00 00 20 97 3d 04 ae 7c 01 00 00 00 00   ..... .=..|.....
          540  +|   1616: 00 00 00 00 22 97 3d 04 ae 7c 01 00 00 00 00 00   ......=..|......
          541  +|   2112: 00 00 00 1e 0c 22 01 ef 00 00 00 00 00 00 00 00   ................
          542  +|   2608: 00 00 00 97 3d 04 ae 7c 01 00 00 00 00 00 00 00   ....=..|........
          543  +|   3104: 00 1c 00 00 01 ef 00 00 00 00 00 00 00 00 00 00   ................
          544  +|   3600: 00 97 3d 04 ae 7c 01 00 00 00 00 00 00 00 00 00   ..=..|..........
          545  +|   4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1a   ................
          546  +| page 36 offset 143360
          547  +|      0: 0a 08 44 00 04 02 77 00 06 55 02 77 04 66 0e 11   ..D...w..U.w.f..
          548  +|     16: 00 88 00 88 00 88 0e 11 00 00 00 00 00 00 00 00   ................
          549  +|    128: 00 00 00 00 00 00 00 00 04 76 01 ef 00 00 00 00   .........v......
          550  +|    624: 00 00 00 00 00 00 00 97 3e 04 ae 7c 02 00 00 00   ........>..|....
          551  +|   1120: 00 00 00 00 00 2a 97 3e 04 ae 7c 02 00 00 00 00   .....*.>..|.....
          552  +|   1616: 00 00 00 00 2c 97 3e 04 ae 7c 02 00 00 00 00 00   ....,.>..|......
          553  +|   2112: 00 00 00 28 00 00 05 cd 00 00 00 00 00 00 00 00   ...(............
          554  +|   3600: 00 97 3e 04 ae 7c 02 00 00 00 00 00 00 00 00 00   ..>..|..........
          555  +|   4080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2f   .............../
          556  +| page 38 offset 151552
          557  +|   2512: 00 00 00 00 00 00 00 6e 00 00 00 00 00 00 00 00   .......n........
          558  +| page 40 offset 159744
          559  +|   2512: 00 00 00 00 00 00 00 00 82 00 00 00 00 00 00 00   ................
          560  +| page 42 offset 167936
          561  +|   2512: 00 00 00 00 00 00 00 00 96 00 00 00 00 00 00 00   ................
          562  +| page 44 offset 176128
          563  +|   2512: 00 00 00 00 00 00 00 00 aa 00 00 00 00 00 00 00   ................
          564  +| page 47 offset 188416
          565  +|   2512: 00 00 00 00 00 00 00 00 be 00 00 00 00 00 00 00   ................
          566  +| end crash-9ae5502296c949.db
          567  +}]} {}
          568  +
          569  +do_catchsql_test 5.1 {
          570  +  INSERT INTO t1(b) VALUES(zeroblob(40000));
          571  +} {1 {database disk image is malformed}}
          572  +
          573  +do_catchsql_test 5.2 {
          574  +  DROP INDEX t1x2;
          575  +} {0 {}}
          576  +
          577  +do_catchsql_test 5.3 {
          578  +  INSERT INTO t1(b) VALUES(zeroblob(40000));
          579  +} {1 {database disk image is malformed}}
          580  +
          581  +
   135    582   
   136    583   finish_test

Changes to test/dbfuzz001.test.

   343    343   |     16: 01 e0 01 d4 01 cb 01 c2 00 00 00 00 00 00 00 00   ................
   344    344   |    448: 00 00 07 08 02 17 65 69 67 68 74 07 07 02 17 65   ......eight....e
   345    345   |    464: 69 67 68 74 0a 06 02 07 40 18 00 00 00 00 00 00   ight....@.......
   346    346   |    480: 0a 05 02 07 40 18 00 00 00 00 00 00 03 04 02 01   ....@...........
   347    347   |    496: 04 03 03 02 01 04 03 02 02 01 02 03 01 02 01 02   ................
   348    348   | end x/c02.db
   349    349     }]
   350         -  execsql {
   351         -    DELETE FROM t3 WHERE x IN (SELECT x FROM t4);
   352         -  }
   353    350   } {}
   354    351   
          352  +do_catchsql_test dbfuzz001-120 {
          353  +  PRAGMA integrity_check;
          354  +} {1 {database disk image is malformed}}
          355  +
          356  +do_catchsql_test dbfuzz001-130 {
          357  +  DELETE FROM t3 WHERE x IN (SELECT x FROM t4);
          358  +} {1 {database disk image is malformed}}
          359  +
   355    360   finish_test

Changes to test/dbfuzz2.c.

    39     39   #include <assert.h>
    40     40   #include <stdio.h>
    41     41   #include <stdlib.h>
    42     42   #include <string.h>
    43     43   #include <stdarg.h>
    44     44   #include <ctype.h>
    45     45   #include <stdint.h>
           46  +#include <sys/time.h>
           47  +#include <sys/resource.h>
    46     48   #include "sqlite3.h"
    47     49   
    48     50   /*
    49     51   ** This is the is the SQL that is run against the database.
    50     52   */
    51     53   static const char *azSql[] = {
    52     54     "PRAGMA integrity_check;",
................................................................................
    62     64   };
    63     65   
    64     66   /* Output verbosity level.  0 means complete silence */
    65     67   int eVerbosity = 0;
    66     68   
    67     69   /* True to activate PRAGMA vdbe_debug=on */
    68     70   static int bVdbeDebug = 0;
           71  +
           72  +/* Maximum size of the in-memory database file */
           73  +static sqlite3_int64 szMax = 104857600;
    69     74   
    70     75   /* libFuzzer invokes this routine with fuzzed database files (in aData).
    71     76   ** This routine run SQLite against the malformed database to see if it
    72     77   ** can provoke a failure or malfunction.
    73     78   */
    74     79   int LLVMFuzzerTestOneInput(const uint8_t *aData, size_t nByte){
    75     80     unsigned char *a;
    76     81     sqlite3 *db;
    77     82     int rc;
    78     83     int i;
           84  +  sqlite3_int64 x;
    79     85   
    80     86     if( eVerbosity>=1 ){
    81     87       printf("************** nByte=%d ***************\n", (int)nByte);
    82     88       fflush(stdout);
    83     89     }
    84     90     if( sqlite3_initialize() ) return 0;
    85     91     rc = sqlite3_open(0, &db);
................................................................................
    86     92     if( rc ) return 1;
    87     93     a = sqlite3_malloc64(nByte+1);
    88     94     if( a==0 ) return 1;
    89     95     memcpy(a, aData, nByte);
    90     96     sqlite3_deserialize(db, "main", a, nByte, nByte,
    91     97           SQLITE_DESERIALIZE_RESIZEABLE |
    92     98           SQLITE_DESERIALIZE_FREEONCLOSE);
           99  +  x = szMax;
          100  +  sqlite3_file_control(db, "main", SQLITE_FCNTL_SIZE_LIMIT, &x);
    93    101     if( bVdbeDebug ){
    94    102       sqlite3_exec(db, "PRAGMA vdbe_debug=ON", 0, 0, 0);
    95    103     }
    96    104     for(i=0; i<sizeof(azSql)/sizeof(azSql[0]); i++){
    97    105       if( eVerbosity>=1 ){
    98    106         printf("%s\n", azSql[i]);
    99    107         fflush(stdout);
................................................................................
   144    152           eVerbosity += n;
   145    153           continue;
   146    154         }
   147    155         if( strcmp(z,"vdbe-debug")==0 ){
   148    156           bVdbeDebug = 1;
   149    157           continue;
   150    158         }
          159  +      if( strcmp(z,"max-db-size")==0 ){
          160  +        if( i+1==argc ){
          161  +          fprintf(stderr, "missing argument to %s\n", argv[i]);
          162  +          exit(1);
          163  +        }
          164  +        szMax = strtol(argv[++i], 0, 0);
          165  +        continue;
          166  +      }
          167  +      if( strcmp(z,"max-stack")==0
          168  +       || strcmp(z,"max-data")==0
          169  +       || strcmp(z,"max-as")==0
          170  +      ){
          171  +        struct rlimit x,y;
          172  +        int resource = RLIMIT_STACK;
          173  +        char *zType = "RLIMIT_STACK";
          174  +        if( i+1==argc ){
          175  +          fprintf(stderr, "missing argument to %s\n", argv[i]);
          176  +          exit(1);
          177  +        }
          178  +        if( z[4]=='d' ){
          179  +          resource = RLIMIT_DATA;
          180  +          zType = "RLIMIT_DATA";
          181  +        }
          182  +        if( z[4]=='a' ){
          183  +          resource = RLIMIT_AS;
          184  +          zType = "RLIMIT_AS";
          185  +        }
          186  +        memset(&x,0,sizeof(x));
          187  +        getrlimit(resource, &x);
          188  +        y.rlim_cur = atoi(argv[++i]);
          189  +        y.rlim_max = x.rlim_cur;
          190  +        setrlimit(resource, &y);
          191  +        memset(&y,0,sizeof(y));
          192  +        getrlimit(resource, &y);
          193  +        printf("%s changed from %d to %d\n", 
          194  +               zType, (int)x.rlim_cur, (int)y.rlim_cur);
          195  +        continue;
          196  +      }
   151    197       }
   152    198       argv[j++] = argv[i];
   153    199     }
   154    200     argv[j] = 0;
   155    201     *pArgc = j;
   156    202     return 0;
   157    203   }
................................................................................
   194    240       pIn = readFile(argv[i], &nIn);
   195    241       if( pIn ){
   196    242         LLVMFuzzerTestOneInput((const uint8_t*)pIn, (size_t)nIn);
   197    243         free(pIn);
   198    244       }
   199    245     }
   200    246     if( eVerbosity>0 ){
          247  +    struct rusage x;
   201    248       printf("SQLite %s\n", sqlite3_sourceid());
          249  +    memset(&x, 0, sizeof(x));
          250  +    if( getrusage(RUSAGE_SELF, &x)==0 ){
          251  +      printf("Maximum RSS = %ld KB\n", x.ru_maxrss);
          252  +    }
   202    253     }
   203    254     return 0;
   204    255   }
   205    256   #endif /*STANDALONE*/

Changes to test/fallocate.test.

    66     66       hexio_get_int [hexio_read test.db-journal 16 4]
    67     67     } else {
    68     68       set {} 1024
    69     69     }
    70     70   } {1024}
    71     71   do_test fallocate-1.8 { execsql { COMMIT } } {}
    72     72   
           73  +do_test fallocate-1.8 {
           74  +  set nPg [db one {PRAGMA page_count}]
           75  +  set nFile [expr [file size test.db] / 1024]
           76  +  list [expr $nPg<100] [expr $nFile>100]
           77  +} {1 1}
           78  +
           79  +do_execsql_test fallocate-1.9 {
           80  +  PRAGMA max_page_count = 100;
           81  +} {100}
    73     82   
    74     83   #-------------------------------------------------------------------------
    75     84   # The following tests - fallocate-2.* - test that things work in WAL
    76     85   # mode as well.
    77     86   #
    78     87   set skipwaltests [expr {
    79     88     [permutation]=="journaltest" || [permutation]=="inmemory_journal"

Changes to test/fts3_common.tcl.

    39     39   #     Todo.
    40     40   #
    41     41   #   fts3_doclist TBL TERM WHERE
    42     42   #     Todo.
    43     43   #
    44     44   #
    45     45   #
           46  +
           47  +ifcapable fts3 {
           48  +  sqlite3_fts3_may_be_corrupt 0 
           49  +}
    46     50   
    47     51   #-------------------------------------------------------------------------
    48     52   # USAGE: fts3_build_db_1 SWITCHES N
    49     53   #
    50     54   # Build a sample FTS table in the database opened by database connection 
    51     55   # [db]. The name of the new table is "t1".
    52     56   #

Changes to test/fts3aux2.test.

   136    136   do_execsql_test 1.4.6 {
   137    137     SELECT term, col, documents, occurrences, languageid 
   138    138     FROM terms WHERE term>='e' AND term<'seven' AND languageid=2
   139    139   } {
   140    140     eight * 1 1 2    eight 1 1 1 2 
   141    141     five * 1 1 2     five 0 1 1 2 
   142    142   }
          143  +
          144  +#-------------------------------------------------------------------------
          145  +do_execsql_test 2.0 {
          146  +  CREATE VIRTUAL TABLE ft USING fts3();
          147  +  INSERT INTO ft VALUES('a_234567890123456789');
          148  +  INSERT INTO ft VALUES('b_234567890123456789');
          149  +  INSERT INTO ft VALUES('c_234567890123456789');
          150  +  CREATE VIRTUAL TABLE t2 USING fts4aux(ft);
          151  +}
          152  +
          153  +do_execsql_test 2.1 {
          154  +  SELECT term FROM t2 WHERE term=X'625f323334353637383930313233343536373839';
          155  +}
          156  +
          157  +do_execsql_test 2.2 {
          158  +  SELECT term FROM t2 WHERE term<X'625f003334353637383930313233343536373839';
          159  +} {
          160  +  234567890123456789 234567890123456789 a a b b
          161  +}
          162  +
          163  +do_execsql_test 2.3 {
          164  +  SELECT term FROM t2 WHERE term=X'625f003334353637383930313233343536373839';
          165  +}
          166  +
   143    167   
   144    168   finish_test

Changes to test/fts3corrupt4.test.

    12     12   # focus of this script is testing the FTS3 module.
    13     13   #
    14     14   # $Id: fts3aa.test,v 1.1 2007/08/20 17:38:42 shess Exp $
    15     15   #
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
           19  +source $testdir/fts3_common.tcl
    19     20   set testprefix fts3corrupt4
    20     21   
    21     22   # If SQLITE_ENABLE_FTS3 is defined, omit this file.
    22     23   ifcapable !fts3 {
    23     24     finish_test
    24     25     return
    25     26   }
           27  +
           28  +sqlite3_fts3_may_be_corrupt 1
    26     29   
    27     30   do_execsql_test 1.0 {
    28     31     BEGIN;
    29     32       CREATE VIRTUAL TABLE ft USING fts3;
    30     33       INSERT INTO ft VALUES('aback');
    31     34       INSERT INTO ft VALUES('abaft');
    32     35       INSERT INTO ft VALUES('abandon');
................................................................................
  1429   1432   | end crash-843cb8447eaf14.db
  1430   1433   }]} {}
  1431   1434   
  1432   1435   do_catchsql_test 11.1 {
  1433   1436     SELECT rowid, quote(matchinfo(t1,'pcxybs')) FROM t1 WHERE t1 MATCH 'e*'
  1434   1437   } {1 {database disk image is malformed}}
  1435   1438   
         1439  +#-------------------------------------------------------------------------
         1440  +reset_db
         1441  +do_test 12.0 {
         1442  +  sqlite3 db {}
         1443  +  db deserialize [decode_hexdb {
         1444  +| size 28672 pagesize 4096 filename c81b.db
         1445  +| page 1 offset 0
         1446  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1447  +|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
         1448  +|     32: 00 00 00 02 00 00 00 01 00 00 00 01 00 00 00 04   ................
         1449  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         1450  +|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
         1451  +|     96: 00 2e 30 38 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21   ..08...........!
         1452  +|    112: 0e b9 0d c8 0e 7e 0d a4 0d a4 00 00 00 00 00 00   .....~..........
         1453  +|   3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c   ...........1tabl
         1454  +|   3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42   et2t2.CREATE TAB
         1455  +|   3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01   LE t2(x).3......
         1456  +|   3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72   .5tablet1_segdir
         1457  +|   3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45   t1_segdir.CREATE
         1458  +|   3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69    TABLE 't1_segdi
         1459  +|   3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52   r'(level INTEGER
         1460  +|   3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61   ,idx INTEGER,sta
         1461  +|   3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52   rt_block INTEGER
         1462  +|   3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63   ,leaves_end_bloc
         1463  +|   3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c   k INTEGER,end_bl
         1464  +|   3664: 6f 63 6b 20 49 4e 54 45 47 45 62 2c 72 6f 6f 74   ock INTEGEb,root
         1465  +|   3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45    BLOB,PRIMARY KE
         1466  +|   3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06   Y(level, idx))1.
         1467  +|   3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74   ..E...indexsqlit
         1468  +|   3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73   e_autoindex_t1_s
         1469  +|   3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72   egdir_1t1_segdir
         1470  +|   3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01   .........f...##.
         1471  +|   3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e   ..tablet1_segmen
         1472  +|   3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52   tst1_segments.CR
         1473  +|   3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73   EATE TABLE 't1_s
         1474  +|   3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64   egments'(blockid
         1475  +|   3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59    INTEGER PRIMARY
         1476  +|   3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42    KEY, block BLOB
         1477  +|   3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74   )j...!!...tablet
         1478  +|   3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74   1_contentt1_cont
         1479  +|   3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45   ent.CREATE TABLE
         1480  +|   3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f    't1_content'(do
         1481  +|   3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   cid INTEGER PRIM
         1482  +|   3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20   ARY KEY, 'c0a', 
         1483  +|   3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06   'c1b', 'c2c')8..
         1484  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         1485  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         1486  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33   LE t1 USING fts3
         1487  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00   (a,b,c)...9.....
         1488  +| page 3 offset 8192
         1489  +|      0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74   ....%.H........t
         1490  +|     16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5   .a.N./..........
         1491  +|     32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5   ...t.[.@.$......
         1492  +|     48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb   .......h.O.5....
         1493  +|     64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a   .......x.W.>.$..
         1494  +|     80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00   .H..............
         1495  +|   2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00   .........?%.....
         1496  +|   2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e   .COMPILER=gcc-5.
         1497  +|   2912: 34 2e 30 20 32 30 31 36 30 36 30 39 20 44 45 42   4.0 20160609 DEB
         1498  +|   2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54   UG ENABLE DBSTAT
         1499  +|   2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53    VTAB ENABLE FTS
         1500  +|   2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e   4 ENABLE FTS5 EN
         1501  +|   2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 46 4e 41   ABLE GEOPOLY FNA
         1502  +|   2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45   BLE JSON1 ENABLE
         1503  +|   3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20    MEMSYS5 ENABLE 
         1504  +|   3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59   RTREE MAX MEMORY
         1505  +|   3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c   =50000000 OMIT L
         1506  +|   3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48   OAD EXTENSION TH
         1507  +|   3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 0f 25   READSAFE=0.$...%
         1508  +|   3088: 19 58 54 48 52 45 41 44 53 41 46 45 3d 30 42 49   .XTHREADSAFE=0BI
         1509  +|   3104: 4e 41 52 59 18 23 05 00 0f 25 19 58 54 48 52 45   NARY.#...%.XTHRE
         1510  +|   3120: 41 44 53 41 46 45 3d 30 4e 4f 43 41 53 45 17 22   ADSAFE=0NOCASE..
         1511  +|   3136: 05 00 0f 25 17 58 54 48 52 45 41 44 53 41 46 45   ...%.XTHREADSAFE
         1512  +|   3152: 3d 30 52 54 52 49 4d 1f 21 05 00 0f 33 19 58 4f   =0RTRIM.!...3.XO
         1513  +|   3168: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49   MIT LOAD EXTENSI
         1514  +|   3184: 4f 4e 42 49 4e 41 52 59 1f 20 05 00 0f 33 19 58   ONBINARY. ...3.X
         1515  +|   3200: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53   OMIT LOAD EXTENS
         1516  +|   3216: 49 4f 4e 4e 4f 43 41 53 45 1e 1f 05 00 0f 33 17   IONNOCASE.....3.
         1517  +|   3232: 58 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e   XOMIT LOAD EXTEN
         1518  +|   3248: 53 49 4f 4e 52 54 52 49 4d 1f 1e 05 00 0f 33 19   SIONRTRIM.....3.
         1519  +|   3264: 58 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30   XMAX MEMORY=5000
         1520  +|   3280: 30 30 30 30 42 49 4e 41 52 59 1f 1d 05 00 0f 33   0000BINARY.....3
         1521  +|   3296: 19 58 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30   .XMAX MEMORY=500
         1522  +|   3312: 30 30 30 30 30 4e 4f 43 41 53 45 1e 1c 05 00 0f   00000NOCASE.....
         1523  +|   3328: 33 17 58 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30   3.XMAX MEMORY=50
         1524  +|   3344: 30 30 30 30 30 30 52 54 52 49 4d 18 1b 05 00 0f   000000RTRIM.....
         1525  +|   3360: 25 19 58 45 4e 41 42 4c 45 20 52 54 52 45 45 42   %.XENABLE RTREEB
         1526  +|   3376: 49 4e 41 52 59 18 1a 05 00 0f 25 19 58 45 4e 41   INARY.....%.XENA
         1527  +|   3392: 42 4c 45 20 52 54 52 45 45 4e 4f 43 41 53 45 17   BLE RTREENOCASE.
         1528  +|   3408: 19 05 00 0f 25 17 58 45 4e 41 42 4c 45 20 52 54   ....%.XENABLE RT
         1529  +|   3424: 52 45 45 52 54 52 49 4d 1a 18 05 00 0f 29 19 58   REERTRIM.....).X
         1530  +|   3440: 45 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 42 49   ENABLE MEMSYS5BI
         1531  +|   3456: 4e 41 52 59 1a 17 05 00 0f 29 19 58 45 4e 41 42   NARY.....).XENAB
         1532  +|   3472: 4c 45 20 4d 45 4d 53 59 53 35 4e 4f 43 41 53 45   LE MEMSYS5NOCASE
         1533  +|   3488: 19 16 05 00 0f 29 17 58 45 4e 41 42 4c 45 20 4d   .....).XENABLE M
         1534  +|   3504: 45 4d 53 59 53 35 52 54 52 49 4d 18 15 05 00 0f   EMSYS5RTRIM.....
         1535  +|   3520: 25 19 58 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 42   %.XENABLE JSON1B
         1536  +|   3536: 49 4e 41 52 59 18 14 05 00 0f 25 19 58 45 4e 41   INARY.....%.XENA
         1537  +|   3552: 42 4c 45 20 4a 53 4f 4e 31 4e 4f 43 41 53 45 17   BLE JSON1NOCASE.
         1538  +|   3568: 13 05 00 0f 25 17 58 45 4e 41 42 4c 45 20 4a 53   ....%.XENABLE JS
         1539  +|   3584: 4f 4e 31 52 54 52 49 4d 1a 12 05 00 0f 29 19 58   ON1RTRIM.....).X
         1540  +|   3600: 45 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 42 49   ENABLE GEOPOLYBI
         1541  +|   3616: 4e 41 52 59 1a 11 05 00 0f 29 19 58 45 4e 41 1e   NARY.....).XENA.
         1542  +|   3632: 4c 45 20 47 45 4f 50 4f 4c 59 4e 4f 43 41 53 45   LE GEOPOLYNOCASE
         1543  +|   3648: 19 10 05 00 0f 29 17 58 45 4e 41 42 4c 45 20 47   .....).XENABLE G
         1544  +|   3664: 45 4f 50 4f 4c 59 52 54 52 49 4d 17 0f 05 00 0f   EOPOLYRTRIM.....
         1545  +|   3680: 23 19 58 45 4e 41 42 4c 45 20 46 54 53 35 42 49   #.XENABLE FTS5BI
         1546  +|   3696: 4e 41 52 59 17 0e 05 00 0f 23 19 58 55 4e 41 42   NARY.....#.XUNAB
         1547  +|   3712: 4c 45 20 46 54 53 35 4e 4f 43 41 53 45 16 0d 05   LE FTS5NOCASE...
         1548  +|   3728: 00 0f 23 17 58 45 4e 41 42 4c 45 20 46 54 53 35   ..#.XENABLE FTS5
         1549  +|   3744: 52 54 52 49 4d 17 0c 05 00 0f 23 19 58 45 4e 41   RTRIM.....#.XENA
         1550  +|   3760: 42 4c 45 20 46 54 53 34 42 49 4e 41 52 59 17 0b   BLE FTS4BINARY..
         1551  +|   3776: 05 00 0f 23 19 58 45 4e 41 42 4c 45 20 46 54 53   ...#.XENABLE FTS
         1552  +|   3792: 35 4e 4f 43 40 53 45 16 0a 05 00 0f 23 17 58 45   5NOC@SE.....#.XE
         1553  +|   3808: 4e 41 42 4c 45 20 46 54 53 34 52 54 52 49 4d 1e   NABLE FTS4RTRIM.
         1554  +|   3824: 09 05 00 0f 31 19 58 45 4e 41 42 4c 35 20 44 42   ....1.XENABL5 DB
         1555  +|   3840: 53 54 41 54 20 56 54 41 42 42 49 4e 41 52 59 1e   STAT VTABBINARY.
         1556  +|   3856: 08 05 00 0f 31 19 58 45 4e 41 42 4c 45 20 44 42   ....1.XENABLE DB
         1557  +|   3872: 53 54 41 54 20 56 54 41 42 4e 4f 43 41 53 45 1d   STAT VTABNOCASE.
         1558  +|   3888: 07 05 00 0f 31 17 58 45 4e 41 42 4c 45 20 44 42   ....1.XENABLE DB
         1559  +|   3904: 53 54 41 54 20 56 54 41 42 52 54 52 49 4d 11 06   STAT VTABRTRIM..
         1560  +|   3920: 05 00 0f 17 19 58 44 45 42 55 47 42 49 4e 41 52   .....XDEBUGBINAR
         1561  +|   3936: 59 11 05 05 00 0f 17 19 58 44 45 42 55 47 4e 4f   Y.......XDEBUGNO
         1562  +|   3952: 43 41 53 45 10 04 05 00 0f 17 17 58 44 45 42 55   CASE.......XDEBU
         1563  +|   3968: 47 52 54 52 49 4d 27 03 05 00 0f 43 19 58 43 4f   GRTRIM'....C.XCO
         1564  +|   3984: 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30   MPILER=gcc-5.4.0
         1565  +|   4000: 20 32 30 31 36 30 36 30 39 42 49 4e 41 52 59 27    20160609BINARY'
         1566  +|   4016: 02 05 00 0f 43 19 58 43 4f 4d 50 49 4c 45 52 3d   ....C.XCOMPILER=
         1567  +|   4032: 67 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36   gcc-5.4.0 201606
         1568  +|   4048: 30 39 4e 4f 43 41 53 45 26 01 05 00 0f 43 17 58   09NOCASE&....C.X
         1569  +|   4064: 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34   COMPILER=gcc-5.4
         1570  +|   4080: 2e 30 20 32 30 31 36 30 36 30 39 52 54 52 49 4d   .0 20160609RTRIM
         1571  +| page 4 offset 12288
         1572  +|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
         1573  +| page 5 offset 16384
         1574  +|      0: 0d 00 00 00 03 07 bb 00 0c ad 0b a0 07 bb 00 00   ................
         1575  +|   1968: 00 00 00 00 00 00 00 00 00 00 00 87 62 03 08 08   ............b...
         1576  +|   1984: 01 08 08 17 8f 34 02 30 20 39 38 30 00 01 30 1e   .....4.0 980..0.
         1577  +|   2000: 01 01 01 06 00 01 01 01 06 00 01 01 01 06 00 1f   ................
         1578  +|   2016: 01 01 03 00 01 01 01 03 00 01 01 01 03 00 00 08   ................
         1579  +|   2032: 32 30 31 36 30 36 30 39 0f 01 01 01 07 00 01 01   20160609........
         1580  +|   2048: 01 07 00 01 01 01 07 00 00 01 34 0f 01 01 01 05   ..........4.....
         1581  +|   2064: 00 01 01 01 05 00 01 01 01 05 00 00 01 35 0f 01   .............5..
         1582  +|   2080: 01 01 04 00 01 01 01 04 00 01 01 01 04 00 01 07   ................
         1583  +|   2096: 30 30 30 30 30 30 30 0f 1c 01 01 04 00 01 01 01   0000000.........
         1584  +|   2112: 04 00 01 01 01 04 00 00 06 62 69 6e 61 72 79 3c   .........binary<
         1585  +|   2128: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03   ................
         1586  +|   2144: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01   ................
         1587  +|   2160: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02   ................
         1588  +|   2176: 02 00 03 01 02 02 00 03 01 02 02 00 00 08 63 6f   ..............co
         1589  +|   2192: 6d 70 69 6c 65 72 0f 01 01 01 02 00 01 01 01 02   mpiler..........
         1590  +|   2208: 00 01 01 01 02 00 00 06 64 62 73 74 61 74 0f 07   ........dbstat..
         1591  +|   2224: 01 01 03 00 01 01 01 03 00 01 01 01 03 00 01 04   ................
         1592  +|   2240: 65 62 75 67 0f 04 01 01 02 00 01 01 01 02 00 01   ebug............
         1593  +|   2256: 01 01 02 00 00 03 65 6e 61 05 11 01 01 02 00 03   ......ena.......
         1594  +|   2272: 03 62 6c 35 05 09 01 01 02 00 05 01 65 5a 07 01   .bl5........eZ..
         1595  +|   2288: 01 02 00 01 01 01 02 00 02 01 01 02 00 01 01 01   ................
         1596  +|   2304: 02 00 01 01 01 02 00 01 01 01 02 00 02 01 01 02   ................
         1597  +|   2320: 00 01 01 01 02 00 02 01 01 02 00 01 01 01 02 00   ................
         1598  +|   2336: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01   ................
         1599  +|   2352: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01   ................
         1600  +|   2368: 01 02 00 01 01 01 02 00 01 08 78 74 65 6e 73 69   ..........xtensi
         1601  +|   2384: 6f 6e 0f 1f 01 01 04 00 01 01 01 04 00 01 01 01   on..............
         1602  +|   2400: 04 00 00 04 66 74 73 34 0a 0a 01 01 03 00 02 01   ....fts4........
         1603  +|   2416: 01 03 00 03 01 35 14 0b 01 01 03 00 02 01 01 03   .....5..........
         1604  +|   2432: 00 01 01 01 03 00 01 01 01 03 00 00 03 67 63 63   .............gcc
         1605  +|   2448: 0f 01 01 01 03 00 01 01 01 03 00 01 01 01 03 00   ................
         1606  +|   2464: 01 06 65 6f 70 6f 6c 79 0f 10 01 01 03 00 01 01   ..eopoly........
         1607  +|   2480: 01 04 00 01 01 01 03 00 00 05 6a 73 6f 6e 31 0f   ..........json1.
         1608  +|   2496: 13 01 01 03 00 01 01 01 03 00 01 01 01 03 00 00   ................
         1609  +|   2512: 02 6c 65 05 11 01 01 03 00 01 03 6f 61 64 0f 1f   .le........oad..
         1610  +|   2528: 01 01 03 00 01 01 01 03 00 01 01 01 03 00 00 03   ................
         1611  +|   2544: 6d 61 78 0f 1c 01 01 02 00 01 01 01 02 00 01 01   max.............
         1612  +|   2560: 01 02 00 01 05 65 6d 6f 72 79 0f 1c 01 01 03 00   .....emory......
         1613  +|   2576: 01 01 01 03 00 01 01 01 03 00 03 04 73 79 73 35   ............sys5
         1614  +|   2592: 0f 16 01 01 03 00 01 01 01 03 00 01 01 01 03 00   ................
         1615  +|   2608: 00 03 6e 6f 63 05 0b 01 02 02 00 03 03 61 73 65   ..noc........ase
         1616  +|   2624: 37 02 01 02 02 00 03 01 02 02 00 03 01 02 02 00   7...............
         1617  +|   2640: 06 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03   ................
         1618  +|   2656: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01   ................
         1619  +|   2672: 02 02 00 03 01 02 02 00 00 04 6f 6d 69 74 0f 1f   ..........omit..
         1620  +|   2688: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 00 05   ................
         1621  +|   2704: 72 74 72 65 65 0f 19 01 01 03 00 01 01 01 03 00   rtree...........
         1622  +|   2720: 01 01 01 03 00 03 02 69 6d 3c 01 01 02 02 00 03   .......im<......
         1623  +|   2736: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01   ................
         1624  +|   2752: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02   ................
         1625  +|   2768: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         1626  +|   2784: 00 03 01 02 02 00 00 02 73 65 05 0b 01 02 03 00   ........se......
         1627  +|   2800: 00 0a 74 68 72 65 61 64 73 61 66 65 0f 22 01 01   ..threadsafe....
         1628  +|   2816: 02 00 01 01 01 02 00 01 01 01 02 00 00 06 75 6e   ..............un
         1629  +|   2832: 61 62 6c 65 05 0e 01 01 02 00 00 04 76 74 61 62   able........vtab
         1630  +|   2848: 0f 07 01 01 04 00 01 01 01 04 00 01 01 01 04 00   ................
         1631  +|   2864: 00 01 78 6c 01 02 00 01 02 00 01 02 00 01 02 00   ..xl............
         1632  +|   2880: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01   ................
         1633  +|   2896: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02   ................
         1634  +|   2912: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00   ................
         1635  +|   2928: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01   ................
         1636  +|   2944: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02   ................
         1637  +|   2960: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00   ................
         1638  +|   2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33   ...........0 253
         1639  +|   2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36   ..0.%.....201606
         1640  +|   3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35   09.%....4.%....5
         1641  +|   3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a   .%....0000000.%.
         1642  +|   3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00   ...compiler.%...
         1643  +|   3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75   .dbstat.%....ebu
         1644  +|   3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09   g.%....enable.%.
         1645  +|   3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f   .........xtensio
         1646  +|   3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03   n.%....fts4.%...
         1647  +|   3120: 11 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01   .5.%....gcc.%...
         1648  +|   3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f   .eopoly.%....jso
         1649  +|   3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00   n1.%....load.%..
         1650  +|   3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79   ..max.%....emory
         1651  +|   3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04   .%....sys5.%....
         1652  +|   3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03   omit.%....rtree.
         1653  +|   3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03   %....threadsafe.
         1654  +|   3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01   %....vtab.%...P.
         1655  +|   3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30   ........0 835..0
         1656  +|   3264: 12 00 f6 00 01 06 00 01 06 00 1f 03 00 01 03 00   ................
         1657  +|   3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07   .....20160609...
         1658  +|   3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05   .........4......
         1659  +|   3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04   ......5.........
         1660  +|   3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04   ...0000000......
         1661  +|   3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02   ......binary<...
         1662  +|   3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         1663  +|   3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00   ................
         1664  +|   3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03   ................
         1665  +|   3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69   ...........compi
         1666  +|   3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64   ler............d
         1667  +|   3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01   bstat...........
         1668  +|   3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00   .ebug...........
         1669  +|   3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 01   .enable?........
         1670  +|   3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02 00   ................
         1671  +|   3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 10 01   ................
         1672  +|   3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02   ................
         1673  +|   3536: 00 01 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f   .........xtensio
         1674  +|   3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73   n............fts
         1675  +|   3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d   4............5..
         1676  +|   3584: 03 00 01 03 00 01 03 00 00 03 67 63 63 09 01 03   ..........gcc...
         1677  +|   3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09   .........eopoly.
         1678  +|   3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31   ...........json1
         1679  +|   3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64   ............load
         1680  +|   3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09   ............max.
         1681  +|   3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79   ...........emory
         1682  +|   3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35   ............sys5
         1683  +|   3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61   ............noca
         1684  +|   3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02   se<.............
         1685  +|   3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         1686  +|   3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00   ................
         1687  +|   3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00   ................
         1688  +|   3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00   .omit...........
         1689  +|   3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00   .rtree..........
         1690  +|   3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03   ..im<...........
         1691  +|   3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01   ................
         1692  +|   3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02   ................
         1693  +|   3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         1694  +|   3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02   ...threadsafe...
         1695  +|   3888: 00 01 02 00 02 02 00 00 04 76 74 61 62 09 07 04   .........vtab...
         1696  +|   3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02   .........x......
         1697  +|   3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         1698  +|   3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01   ................
         1699  +|   3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01   ................
         1700  +|   3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01   ................
         1701  +|   3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02   ................
         1702  +|   4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         1703  +|   4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01   ................
         1704  +|   4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01   ................
         1705  +|   4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01   ................
         1706  +|   4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02   ................
         1707  +|   4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         1708  +| page 6 offset 20480
         1709  +|      0: 0a 00 00 00 03 0f ee 00 0f fb 0f f5 0f ee 00 00   ................
         1710  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 06 04   ................
         1711  +|   4080: 08 01 01 02 03 05 04 08 09 01 02 04 04 08 08 09   ................
         1712  +| page 7 offset 24576
         1713  +|      0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 0f d6 0f c7   ................
         1714  +|     16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         1715  +|   4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f   ...........#auto
         1716  +|   4032: 6d 65 72 67 65 3d 35 0c f4 02 23 6d 65 72 67 65   merge=5...#merge
         1717  +|   4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72   =100,8...+integr
         1718  +|   4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity-check....reb
         1719  +|   4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   uild....optimize
         1720  +| end c81b.db
         1721  +}]} {}
         1722  +
         1723  +do_catchsql_test 12.1 {
         1724  +  SELECT rowid, quote(matchinfo(t1,'pcxybspcxybs')) 
         1725  +  FROM t1 WHERE t1 MATCH 'e*e*'
         1726  +} {1 {database disk image is malformed}}
         1727  +
         1728  +#-------------------------------------------------------------------------
         1729  +reset_db
         1730  +do_test 13.0 {
         1731  +  sqlite3 db {}
         1732  +  db deserialize [decode_hexdb {
         1733  +| size 28672 pagesize 4096 filename crash-c666cfde112dee.db
         1734  +| page 1 offset 0
         1735  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1736  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
         1737  +|     32: 00 00 00 02 00 00 00 01 00 00 00 07 00 00 00 04   ................
         1738  +|     48: 00 00 00 00 00 00 00 07 00 00 00 01 00 00 00 00   ................
         1739  +|     96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21   ...............!
         1740  +|    112: 0e b9 0d c8 0e 7e 0d a4 0d a4 00 00 00 00 00 00   .....~..........
         1741  +|   3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c   ...........1tabl
         1742  +|   3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42   et2t2.CREATE TAB
         1743  +|   3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01   LE t2(x).3......
         1744  +|   3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72   .5tablet1_segdir
         1745  +|   3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45   t1_segdir.CREATE
         1746  +|   3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69    TABLE 't1_segdi
         1747  +|   3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52   r'(level INTEGER
         1748  +|   3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61   ,idx INTEGER,sta
         1749  +|   3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52   rt_block INTEGER
         1750  +|   3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63   ,leaves_end_bloc
         1751  +|   3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c   k INTEGER,end_bl
         1752  +|   3664: 6f 63 6b 20 49 4e 54 45 47 45 62 2c 72 6f 6f 74   ock INTEGEb,root
         1753  +|   3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45    BLOB,PRIMARY KE
         1754  +|   3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06   Y(level, idx))1.
         1755  +|   3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74   ..E...indexsqlit
         1756  +|   3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73   e_autoindex_t1_s
         1757  +|   3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72   egdir_1t1_segdir
         1758  +|   3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01   .........f...##.
         1759  +|   3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e   ..tablet1_segmen
         1760  +|   3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52   tst1_segments.CR
         1761  +|   3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73   EATE TABLE 't1_s
         1762  +|   3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64   egments'(blockid
         1763  +|   3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59    INTEGER PRIMARY
         1764  +|   3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42    KEY, block BLOB
         1765  +|   3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74   )j...!!...tablet
         1766  +|   3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74   1_contentt1_cont
         1767  +|   3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45   ent.CREATE TABLE
         1768  +|   3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f    't1_content'(do
         1769  +|   3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   cid INTEGER PRIM
         1770  +|   3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20   ARY KEY, 'c0a', 
         1771  +|   3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06   'c1b', 'c2c')8..
         1772  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         1773  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         1774  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33   LE t1 USING fts3
         1775  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00   (a,b,c)...9.....
         1776  +| page 3 offset 8192
         1777  +|      0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74   ....%.H........t
         1778  +|     16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5   .a.N./..........
         1779  +|     32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5   ...t.[.@.$......
         1780  +|     48: 0d bb 0d a0 0d 84 0d 68 0d 4f 0d 35 0d 1b 0c fb   .......h.O.5....
         1781  +|     64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a   .......x.W.>.$..
         1782  +|     80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00   .H..............
         1783  +|   2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00   .........?%.....
         1784  +|   2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e   .COMPILER=gcc-5.
         1785  +|   2912: 34 23 00 20 32 30 31 36 30 36 30 39 20 44 45 42   4#. 20160609 DEB
         1786  +|   2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54   UG ENABLE DBSTAT
         1787  +|   2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53    VTAB ENABLE FTS
         1788  +|   2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e   4 ENABLE FTS5 EN
         1789  +|   2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41   ABLE GEOPOLY ENA
         1790  +|   2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45   BLE JSON1 ENABLE
         1791  +|   3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20    MEMSYS5 ENABLE 
         1792  +|   3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59   RTREE MAX MEMORY
         1793  +|   3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c   =50000000 OMIT L
         1794  +|   3056: 4f 41 44 20 45 58 54 45 4e 53 49 4f 4e 20 54 48   OAD EXTENSION TH
         1795  +|   3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f   READSAFE=0.$..%.
         1796  +|   3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49   .THREADSAFE=0XBI
         1797  +|   3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41   NARY.#..%..THREA
         1798  +|   3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22   DSAFE=0XNOCASE..
         1799  +|   3136: 05 00 25 0f 17 54 48 52 45 41 44 53 41 46 45 3d   ..%..THREADSAFE=
         1800  +|   3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d   0XRTRIM.!..3..OM
         1801  +|   3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49 4f   IT LOAD EXTENSIO
         1802  +|   3184: 4e 58 42 49 4e 41 52 59 1f 20 05 00 33 0f 19 4f   NXBINARY. ..3..O
         1803  +|   3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49   MIT LOAD EXTENSI
         1804  +|   3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17   ONXNOCASE....3..
         1805  +|   3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53   OMIT LOAD EXTENS
         1806  +|   3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19   IONXRTRIM....3..
         1807  +|   3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30 30   MAX MEMORY=50000
         1808  +|   3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f   000XBINARY....3.
         1809  +|   3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30   .MAX MEMORY=5000
         1810  +|   3312: 30 30 30 30 58 4e 4f 43 41 53 45 1e 1c 05 00 33   0000XNOCASE....3
         1811  +|   3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30   ..MAX MEMORY=500
         1812  +|   3344: 30 30 30 30 30 58 52 54 53 49 4d 18 1b 05 00 25   00000XRTSIM....%
         1813  +|   3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42   ..ENABLE RTREEXB
         1814  +|   3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         1815  +|   3392: 4c 45 20 52 54 52 45 45 58 4e 4f 43 41 53 45 17   LE RTREEXNOCASE.
         1816  +|   3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52   ...%..ENABLE RTR
         1817  +|   3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45   EEXRTRIM....)..E
         1818  +|   3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49   NABLE MEMSYS5XBI
         1819  +|   3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         1820  +|   3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45   E MEMSYS5XNOCASE
         1821  +|   3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45   ....)..ENABLE ME
         1822  +|   3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25   MSYS5XRTRIM....%
         1823  +|   3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42   ..ENABLE JSON1XB
         1824  +|   3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         1825  +|   3552: 4c 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17   LE JSON1XNOCASE.
         1826  +|   3568: 13 05 00 25 0f 17 45 4e 41 52 4c 45 20 4a 53 4f   ...%..ENARLE JSO
         1827  +|   3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45   N1XRTRIM....)..E
         1828  +|   3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49   NABLE GEOPOLYXBI
         1829  +|   3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 1e 4c   NARY....)..ENA.L
         1830  +|   3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45   E GEOPOLYXNOCASE
         1831  +|   3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45   ....)..ENABLE GE
         1832  +|   3664: 4f 50 4f 4c 59 58 52 54 52 49 4d 17 0f 05 00 23   OPOLYXRTRIM....#
         1833  +|   3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49   ..ENABLE FTS5XBI
         1834  +|   3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c   NARY....#..ENABL
         1835  +|   3712: 45 20 46 54 53 35 58 4e 4f 43 41 53 45 16 0d 05   E FTS5XNOCASE...
         1836  +|   3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 59 e5 58   .#..ENABLE FTY.X
         1837  +|   3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42   RTRIM....#..ENAB
         1838  +|   3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b   LE FTS4XBINARY..
         1839  +|   3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 35   ..#..ENABLE FTS5
         1840  +|   3792: 58 4e 4f 43 40 53 45 16 0a 05 00 23 0f 17 45 4e   XNOC@SE....#..EN
         1841  +|   3808: 41 42 4c 45 20 46 54 53 34 58 52 54 52 49 4d 1e   ABLE FTS4XRTRIM.
         1842  +|   3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         1843  +|   3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 52 59 1e   TAT VTABXBINARY.
         1844  +|   3856: 08 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         1845  +|   3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d   TAT VTABXNOCASE.
         1846  +|   3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         1847  +|   3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06   TAT VTABXRTRIM..
         1848  +|   3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52   .....DEBUGXBINAR
         1849  +|   3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f   Y.......DEBUGXNO
         1850  +|   3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47   CASE.......DEBUG
         1851  +|   3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d   XRTRIM'...C..COM
         1852  +|   3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20   PILER=gcc-5.4.0 
         1853  +|   4000: 32 30 31 36 30 36 30 39 58 42 49 4e 41 52 59 27   20160609XBINARY'
         1854  +|   4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67   ...C..COMPILER=g
         1855  +|   4032: 63 63 2d 35 2e 34 2f 30 20 32 30 31 36 30 36 30   cc-5.4/0 2016060
         1856  +|   4048: 39 58 4e 4f 43 41 53 45 26 01 05 00 43 0f 17 43   9XNOCASE&...C..C
         1857  +|   4064: 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e   OMPILER=gcc-5.4.
         1858  +|   4080: 30 20 32 30 31 36 30 36 30 39 58 52 54 52 49 4d   0 20160609XRTRIM
         1859  +| page 4 offset 12288
         1860  +|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
         1861  +| page 5 offset 16384
         1862  +|      0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00   ................
         1863  +|   2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 35 33   ...........0 253
         1864  +|   2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36   ..0.%.....201606
         1865  +|   3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35   09.%....4.%....5
         1866  +|   3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a   .%....0000000.%.
         1867  +|   3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00   ...compiler.%...
         1868  +|   3056: 06 64 62 73 74 61 74 03 25 0a 00 01 04 65 62 75   .dbstat.%....ebu
         1869  +|   3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09   g.%....enable.%.
         1870  +|   3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f   .........xtensio
         1871  +|   3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03   n.%....fts4.%...
         1872  +|   3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01   .5.%....gcc.%...
         1873  +|   3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f   .eopoly.%....jso
         1874  +|   3152: 6e 31 03 25 13 41 00 04 6c 6f 61 64 03 25 1c 00   n1.%.A..load.%..
         1875  +|   3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79   ..max.%....emory
         1876  +|   3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04   .%....sys5.%....
         1877  +|   3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03   omit.%....rtree.
         1878  +|   3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03   %....threadsafe.
         1879  +|   3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01   %....vtab.%...P.
         1880  +|   3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30   ........0 835..0
         1881  +|   3264: 12 01 06 00 01 06 00 01 06 00 1f 03 00 01 03 00   ................
         1882  +|   3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07   .....20160609...
         1883  +|   3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05   .........4......
         1884  +|   3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04   ......5.........
         1885  +|   3328: 00 01 07 30 30 30 30 30 30 30 09 1c 04 00 01 04   ...0000000......
         1886  +|   3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 02 02   ......binary<...
         1887  +|   3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         1888  +|   3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00   ................
         1889  +|   3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03   ................
         1890  +|   3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69   ...........compi
         1891  +|   3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64   ler............d
         1892  +|   3440: 62 73 74 61 74 09 f2 03 00 01 03 00 01 03 00 01   bstat...........
         1893  +|   3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00   .ebug...........
         1894  +|   3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02   .enable?........
         1895  +|   3488: 00 01 02 00 01 02 00 01 02 00 01 02 00 57 02 00   .............W..
         1896  +|   3504: 01 02 00 01 01 00 01 02 00 01 02 00 01 02 10 01   ................
         1897  +|   3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02   ................
         1898  +|   3536: 00 01 02 00 01 02 00 01 08 78 74 64 6e 73 69 6f   .........xtdnsio
         1899  +|   3552: 6e 09 1f 04 00 01 04 00 01 03 00 00 04 66 74 73   n............fts
         1900  +|   3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d   4............5..
         1901  +|   3584: 03 00 01 03 00 01 03 00 00 03 57 63 63 09 01 03   ..........Wcc...
         1902  +|   3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09   .........eopoly.
         1903  +|   3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31   ...........json1
         1904  +|   3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64   ............load
         1905  +|   3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09   ............max.
         1906  +|   3664: 1c 02 00 01 02 00 01 02 00 01 05 65 6d 6f 72 79   ...........emory
         1907  +|   3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35   ............sys5
         1908  +|   3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61   ............noca
         1909  +|   3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02   se<.............
         1910  +|   3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         1911  +|   3744: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00   ................
         1912  +|   3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00   ................
         1913  +|   3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00   .omit...........
         1914  +|   3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00   .rtree..........
         1915  +|   3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03   ..im<...........
         1916  +|   3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01   ................
         1917  +|   3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02   ................
         1918  +|   3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         1919  +|   3872: 00 00 0a 74 68 72 65 61 64 73 61 66 65 09 22 02   ...threadsafe...
         1920  +|   3888: 00 01 02 00 02 02 00 00 04 76 74 61 62 09 07 04   .........vtab...
         1921  +|   3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02   .........x......
         1922  +|   3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         1923  +|   3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01   ................
         1924  +|   3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01   ................
         1925  +|   3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01   ................
         1926  +|   3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02   ................
         1927  +|   4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         1928  +|   4016: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01   ................
         1929  +|   4032: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01   ................
         1930  +|   4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01   ................
         1931  +|   4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02   ................
         1932  +|   4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         1933  +| page 6 offset 20480
         1934  +|      0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00   ................
         1935  +|   4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09   ................
         1936  +| page 7 offset 24576
         1937  +|      0: 0d 00 00 00 05 0f b8 00 0f f4 0f e9 0f d6 0f c7   ................
         1938  +|     16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         1939  +|   4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 75 74 6f   ...........#auto
         1940  +|   4032: 6d 65 72 67 65 3d 35 0d 04 02 23 6d 65 72 67 65   merge=5...#merge
         1941  +|   4048: 3d 31 30 30 2c 38 11 03 02 2b 69 6e 74 65 67 72   =100,8...+integr
         1942  +|   4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity-check....reb
         1943  +|   4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   uild....optimize
         1944  +| end crash-c666cfde112dee.db
         1945  +}]} {}
         1946  +
         1947  +do_catchsql_test 13.1 {
         1948  +  SELECT quote(matchinfo(t1,'pcxybs'))==0 FROM t1 WHERE b MATCH 'e*';
         1949  +} {0 {0 0}}
         1950  +
         1951  +#-------------------------------------------------------------------------
         1952  +reset_db
         1953  +do_test 14.0 {
         1954  +  sqlite3 db {}
         1955  +  db deserialize [decode_hexdb {
         1956  +| size 28672 pagesize 4096 filename crash-f7b636a855e1d2.db
         1957  +| page 1 offset 0
         1958  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         1959  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
         1960  +|     32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04   ................
         1961  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         1962  +|     96: 00 00 00 00 0d 0e ef 00 07 0d 4d 00 0f bd 0f 5f   ..........M...._
         1963  +|    112: 0e f7 0e 06 0e bc 0d a4 0d 4d 00 00 00 00 00 00   .........M......
         1964  +|   3392: 00 00 00 00 00 00 00 00 00 00 00 00 00 55 07 07   .............U..
         1965  +|   3408: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 73 74   ......tablet1_st
         1966  +|   3424: 61 74 74 31 5f 73 74 61 74 07 43 52 45 41 54 45   att1_stat.CREATE
         1967  +|   3440: 20 54 41 42 4c 45 20 27 74 31 5f 73 74 61 74 27    TABLE 't1_stat'
         1968  +|   3456: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
         1969  +|   3472: 41 52 59 20 4b 45 59 2c 20 76 61 6c 75 65 20 42   ARY KEY, value B
         1970  +|   3488: 4c 4f 42 29 60 06 07 17 21 21 01 81 0b 74 61 62   LOB)`...!!...tab
         1971  +|   3504: 6c 65 74 31 5f 64 6f 63 73 69 7a 65 74 31 5f 64   let1_docsizet1_d
         1972  +|   3520: 6f 63 73 69 7a 65 06 43 52 45 41 54 45 20 54 41   ocsize.CREATE TA
         1973  +|   3536: 42 4c 45 20 27 74 31 5f 64 6f 63 73 69 7a 65 27   BLE 't1_docsize'
         1974  +|   3552: 28 64 6f 63 69 64 20 49 4e 54 45 47 45 52 20 50   (docid INTEGER P
         1975  +|   3568: 52 49 4d 41 52 59 20 4b 45 59 2c 20 73 69 7a 65   RIMARY KEY, size
         1976  +|   3584: 20 42 4c 4f 42 29 81 33 04 07 17 1f 1f 01 82 35    BLOB).3.......5
         1977  +|   3600: 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 74 31   tablet1_segdirt1
         1978  +|   3616: 5f 73 65 67 64 69 25 04 43 52 45 41 54 45 20 54   _segdi%.CREATE T
         1979  +|   3632: 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 72 27   ABLE 't1_segdir'
         1980  +|   3648: 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 2c 69   (level INTEGER,i
         1981  +|   3664: 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 72 74   dx INTEGER,start
         1982  +|   3680: 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 2c 6c   _block INTEGER,l
         1983  +|   3696: 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b 20   eaves_end_block 
         1984  +|   3712: 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c 6f 63   INTEGER,end_bloc
         1985  +|   3728: 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 20 42   k INTEGER,root B
         1986  +|   3744: 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 59 28   LOB,PRIMARY KEY(
         1987  +|   3760: 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 05 06 17   level, idx))1...
         1988  +|   3776: 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 65 5f   E...indexsqlite_
         1989  +|   3792: 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 65 67   autoindex_t1_seg
         1990  +|   3808: 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 05 00   dir_1t1_segdir..
         1991  +|   3824: 00 00 08 00 00 00 00 66 03 07 17 23 23 01 81 13   .......f...##...
         1992  +|   3840: 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e 74 73   tablet1_segments
         1993  +|   3856: 74 31 5f 73 65 67 6d 65 6e 74 73 03 43 52 45 41   t1_segments.CREA
         1994  +|   3872: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67   TE TABLE 't1_seg
         1995  +|   3888: 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 20 49   ments'(blockid I
         1996  +|   3904: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b   NTEGER PRIMARY K
         1997  +|   3920: 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 5c   EY, block BLOB).
         1998  +|   3936: 02 07 17 21 21 01 81 03 74 61 62 6c 65 74 31 5f   ...!!...tablet1_
         1999  +|   3952: 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 65 6e   contentt1_conten
         2000  +|   3968: 74 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 27   t.CREATE TABLE '
         2001  +|   3984: 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 63 69   t1_content'(doci
         2002  +|   4000: 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52   d INTEGER PRIMAR
         2003  +|   4016: 59 20 4b 45 59 2c 20 27 63 30 61 27 29 41 01 06   Y KEY, 'c0a')A..
         2004  +|   4032: 17 11 11 08 71 74 61 62 6c 65 74 31 74 31 43 52   ....qtablet1t1CR
         2005  +|   4048: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         2006  +|   4064: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 34   LE t1 USING fts4
         2007  +|   4080: 28 61 2c 70 72 65 66 69 78 3d 27 31 2c 32 27 29   (a,prefix='1,2')
         2008  +| page 2 offset 4096
         2009  +|      0: 0d 00 00 00 08 0e 1f 00 0f c4 0f 7c 0f 34 0f 07   ...........|.4..
         2010  +|     16: 0e c3 0e 97 0e 63 0e 1f 00 00 00 00 00 00 00 00   .....c..........
         2011  +|   3600: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 42   ...............B
         2012  +|   3616: 08 04 00 81 09 73 75 6e 74 20 69 6e 20 63 75 6c   .....sunt in cul
         2013  +|   3632: 70 61 20 71 75 69 20 6f 66 66 69 63 69 61 20 64   pa qui officia d
         2014  +|   3648: 65 73 65 72 75 6e 74 20 6d 6f 6c 6c 69 74 20 61   eserunt mollit a
         2015  +|   3664: 6e 69 6d 20 69 64 20 65 73 74 20 6c 61 62 6f 72   nim id est labor
         2016  +|   3680: 75 6d 2e 32 07 03 01 6b 45 78 63 65 70 74 65 75   um.2...kExcepteu
         2017  +|   3696: 72 20 73 69 6e 74 20 6f 63 63 61 65 63 61 74 20   r sint occaecat 
         2018  +|   3712: 63 75 70 69 64 61 74 61 74 20 6e 6f 6e 20 70 72   cupidatat non pr
         2019  +|   3728: 6f 69 64 65 6e 74 2c 2a 06 03 00 5b 63 69 6c 6c   oident,*...[cill
         2020  +|   3744: 75 6d 20 64 6f 6c 6f 72 65 20 65 75 20 66 75 67   um dolore eu fug
         2021  +|   3760: 69 61 74 20 6e 75 6c 6c 61 20 70 61 72 69 61 74   iat nulla pariat
         2022  +|   3776: 75 72 2e 43 05 04 00 81 09 44 75 69 73 20 61 75   ur.C.....Duis au
         2023  +|   3792: 74 65 20 69 72 75 72 65 20 64 6f 6c 6f 72 20 69   te irure dolor i
         2024  +|   3808: 6e 20 72 65 70 72 65 68 65 6e 64 65 72 69 74 20   n reprehenderit 
         2025  +|   3824: 69 6e 20 76 6f 6c 75 70 74 61 74 65 20 76 65 6c   in voluptate vel
         2026  +|   3840: 69 74 20 65 73 73 65 2b 14 03 00 5d 6e 69 73 69   it esse+...]nisi
         2027  +|   3856: 20 75 74 20 61 6c 69 71 75 69 70 20 65 78 20 65    ut aliquip ex e
         2028  +|   3872: 61 20 63 6f 6d 6d 6f 64 6f 20 63 6f 6e 73 65 71   a commodo conseq
         2029  +|   3888: 75 61 74 2e 46 03 04 00 81 11 55 74 20 65 6e 69   uat.F.....Ut eni
         2030  +|   3904: 6d 20 61 64 20 6d 69 6e 69 6d 20 76 65 6e 69 61   m ad minim venia
         2031  +|   3920: 6d 2c 20 71 75 69 73 20 6e 6f 73 74 72 75 64 20   m, quis nostrud 
         2032  +|   3936: 65 78 65 72 63 69 74 61 74 69 6f 6e 20 75 6c 6c   exercitation ull
         2033  +|   3952: 61 6d 63 6f 20 6c 61 62 6f 72 69 73 46 02 04 00   amco laborisF...
         2034  +|   3968: 81 11 73 65 64 20 64 6f 20 65 69 75 73 6d 6f 64   ..sed do eiusmod
         2035  +|   3984: 20 74 65 6d 70 6f 72 20 69 6e 63 69 64 69 64 75    tempor incididu
         2036  +|   4000: 6e 74 20 75 74 20 6c 61 62 6f 72 65 20 65 74 20   nt ut labore et 
         2037  +|   4016: 64 6f 6c 6f 72 65 20 6d 61 67 6e 61 20 61 6c 69   dolore magna ali
         2038  +|   4032: 71 75 61 2e 3a 01 03 00 7b 4c 6f 72 65 6d 20 69   qua.:....Lorem i
         2039  +|   4048: 70 73 75 6d 20 64 6f 6c 6f 72 20 73 69 74 20 61   psum dolor sit a
         2040  +|   4064: 6d 65 74 2c 20 63 6f 6e 73 65 63 74 65 74 75 72   met, consectetur
         2041  +|   4080: 20 61 64 69 70 69 73 63 69 6e 67 20 65 6c 69 74    adipiscing elit
         2042  +| page 3 offset 8192
         2043  +|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
         2044  +| page 4 offset 12288
         2045  +|      0: 0d 00 00 00 03 0a a6 00 0d 57 0c 4a 0a a6 00 00   .........W.J....
         2046  +|   2720: 00 00 00 00 00 00 83 21 03 08 02 08 08 08 17 86   .......!........
         2047  +|   2736: 30 08 00 30 20 34 30 32 00 02 61 64 06 01 08 00   0..0 402..ad....
         2048  +|   2752: 02 04 00 01 01 6c 06 02 0c 00 02 04 00 01 01 6d   .....l.........m
         2049  +|   2768: 03 01 06 00 01 01 6e 03 08 09 00 01 01 75 03 05   ......n......u..
         2050  +|   2784: 03 00 00 02 63 69 03 06 01 00 01 01 6f 07 01 07   ....ci......o...
         2051  +|   2800: 00 03 07 03 00 01 01 75 06 07 05 00 01 04 00 00   .......u........
         2052  +|   2816: 02 64 65 03 08 07 00 01 01 6f 0d 01 04 00 01 03   .de......o......
         2053  +|   2832: 09 00 03 05 00 01 03 00 01 01 75 03 05 02 00 00   ..........u.....
         2054  +|   2848: 02 65 61 03 04 06 00 01 01 69 03 02 04 00 01 01   .ea......i......
         2055  +|   2864: 6c 03 01 09 00 01 01 6e 03 03 03 00 01 01 73 06   l......n......s.
         2056  +|   2880: 05 0b 00 03 0b 00 01 01 74 03 02 09 00 01 01 75   ........t......u
         2057  +|   2896: 03 06 04 00 01 01 78 09 03 09 00 01 05 00 03 02   ......x.........
         2058  +|   2912: 00 00 02 66 75 03 06 05 00 00 02 69 64 03 08 0a   ...fu......id...
         2059  +|   2928: 00 01 01 6e 0a 02 06 00 03 06 04 00 03 03 00 01   ...n............
         2060  +|   2944: 01 70 03 01 13 00 01 01 72 03 05 04 00 00 02 6c   .p......r......l
         2061  +|   2960: 61 09 02 08 00 01 0b 00 05 0c 00 01 01 6f 03 01   a............o..
         2062  +|   2976: 02 00 00 02 6d 61 03 02 0b 00 01 01 69 03 04 05   ....ma......i...
         2063  +|   2992: 00 01 01 6f 03 08 08 00 00 02 6e 69 03 04 02 00   ...o......ni....
         2064  +|   3008: 01 01 6f 06 03 08 00 04 06 00 01 01 75 03 06 06   ..o.........u...
         2065  +|   3024: 00 00 02 6f 63 03 07 04 00 01 01 66 03 08 06 00   ...oc......f....
         2066  +|   3040: 00 02 70 61 03 06 07 00 01 01 72 03 07 07 00 00   ..pa......r.....
         2067  +|   3056: 02 71 75 06 03 07 00 05 05 00 00 02 72 65 03 05   .qu.........re..
         2068  +|   3072: 07 00 00 02 73 65 03 02 02 00 01 01 69 06 01 05   ....se......i...
         2069  +|   3088: 00 06 03 00 01 01 75 03 08 02 00 00 02 74 65 03   ......u......te.
         2070  +|   3104: 03 05 00 00 02 75 6c 03 03 0a 00 01 01 74 09 02   .....ul......t..
         2071  +|   3120: 07 00 01 02 00 01 03 00 00 02 76 65 06 03 06 00   ..........ve....
         2072  +|   3136: 02 0a 00 01 01 6f 03 05 09 00 82 0a 02 08 02 08   .....o..........
         2073  +|   3152: 08 08 17 84 02 04 00 30 20 32 35 31 00 01 61 13   .......0 251..a.
         2074  +|   3168: 01 06 04 00 01 0c 00 01 04 00 01 04 00 01 03 00   ................
         2075  +|   3184: 03 09 00 00 01 63 10 01 07 00 03 07 03 00 02 02   .....c..........
         2076  +|   3200: 00 01 05 00 01 04 00 00 01 64 11 01 04 00 01 03   .........d......
         2077  +|   3216: 09 00 03 02 05 00 01 03 00 02 07 00 00 01 65 1b   ..............e.
         2078  +|   3232: 01 09 00 01 04 07 00 01 03 08 00 01 05 03 00 01   ................
         2079  +|   3248: 0b 00 01 04 00 01 02 00 01 0b 00 00 01 66 03 06   .............f..
         2080  +|   3264: 05 00 00 01 69 0f 01 03 00 01 06 00 03 04 04 04   ....i...........
         2081  +|   3280: 00 03 03 09 00 00 01 6c 0c 01 02 00 01 08 00 01   .......l........
         2082  +|   3296: 0b 00 05 0c 00 00 01 6d 09 02 0b 00 01 05 00 05   .......m........
         2083  +|   3312: 08 00 00 01 6e 0c 03 08 00 01 02 00 02 06 00 01   ....n...........
         2084  +|   3328: 06 00 00 01 6f 06 07 04 00 01 06 00 00 01 70 06   ....o.........p.
         2085  +|   3344: 06 07 00 01 07 00 00 01 71 06 03 07 00 05 05 00   ........q.......
         2086  +|   3360: 00 01 72 03 05 08 00 00 01 73 0c 01 05 00 01 02   ..r......s......
         2087  +|   3376: 00 05 03 00 01 02 00 00 01 74 03 02 05 00 00 01   .........t......
         2088  +|   3392: 75 0a 02 07 00 01 02 0a 00 01 03 00 00 01 76 07   u.............v.
         2089  +|   3408: 03 06 00 02 09 03 00 85 26 01 08 08 08 08 08 17   ........&.......
         2090  +|   3424: 8a 3e 30 20 36 36 35 00 02 61 64 03 03 04 00 02   .>0 665..ad.....
         2091  +|   3440: 08 69 70 69 73 63 69 6e 67 03 01 08 00 01 05 6c   .ipiscing......l
         2092  +|   3456: 69 71 75 61 03 02 0c 00 05 02 69 70 03 04 04 00   iqua......ip....
         2093  +|   3472: 01 03 6d 65 74 03 01 06 00 01 03 6e 69 6d 03 08   ..met......nim..
         2094  +|   3488: 09 00 01 03 75 74 65 03 05 03 00 00 06 63 69 6c   ....ute......cil
         2095  +|   3504: 6c 75 6d 03 06 02 00 01 06 6f 6d 6d 6f 64 6f 03   lum......ommodo.
         2096  +|   3520: 04 07 00 02 09 6e 73 65 63 74 65 74 75 72 03 01   .....nsectetur..
         2097  +|   3536: 07 00 05 04 71 75 61 74 03 04 08 00 01 04 75 6c   ....quat......ul
         2098  +|   3552: 70 61 03 08 04 00 02 07 70 69 64 61 74 61 74 03   pa......pidatat.
         2099  +|   3568: 07 05 00 00 08 64 65 73 65 72 75 6e 74 03 08 07   .....deserunt...
         2100  +|   3584: 00 01 01 6f 03 02 03 00 02 03 6c 6f 72 06 01 04   ...o......lor...
         2101  +|   3600: 00 04 05 00 05 01 65 06 02 0a 00 04 03 00 01 03   ......e.........
         2102  +|   3616: 75 69 73 03 05 02 00 00 02 65 61 03 04 06 00 01   uis......ea.....
         2103  +|   3632: 06 69 75 73 6d 6f 64 03 02 04 00 01 03 6c 69 74   .iusmod......lit
         2104  +|   3648: 03 01 09 00 01 03 6e 69 6d 03 03 03 00 01 03 73   ......nim......s
         2105  +|   3664: 73 65 03 05 0b 00 02 01 73 03 08 0b 00 01 01 74   se......s......t
         2106  +|   3680: 03 02 09 00 01 01 75 03 06 04 00 01 01 78 03 04   ......u......x..
         2107  +|   3696: 05 00 02 07 63 65 70 74 65 75 72 03 07 02 00 02   ....cepteur.....
         2108  +|   3712: 0a 65 72 63 69 74 61 74 69 6f 6e 03 03 09 00 00   .ercitation.....
         2109  +|   3728: 06 66 75 67 69 61 74 03 06 05 00 00 02 69 64 03   .fugiat......id.
         2110  +|   3744: 08 0a 00 01 01 6e 07 05 06 04 00 03 03 00 02 08   .....n..........
         2111  +|   3760: 63 69 64 69 64 75 6e 74 03 02 06 00 01 04 70 73   cididunt......ps
         2112  +|   3776: 75 6d 03 01 03 00 01 04 72 75 72 65 03 05 04 00   um......rure....
         2113  +|   3792: 00 06 6c 61 62 6f 72 65 03 02 08 00 05 02 69 73   ..labore......is
         2114  +|   3808: 03 03 0b 00 05 02 75 6d 03 08 0c 00 01 04 6f 72   ......um......or
         2115  +|   3824: 65 6d 03 01 02 00 00 05 6d 61 67 6e 61 03 02 0b   em......magna...
         2116  +|   3840: 00 01 04 69 6e 69 6d 03 03 05 00 01 05 6f 6c 6c   ...inim......oll
         2117  +|   3856: 69 74 03 08 08 00 00 04 6e 69 73 69 03 04 02 00   it......nisi....
         2118  +|   3872: 01 02 6f 6e 03 07 06 00 02 05 73 74 72 75 64 03   ..on......strud.
         2119  +|   3888: 03 08 00 01 04 75 6c 6c 61 03 06 06 00 00 08 6f   .....ulla......o
         2120  +|   3904: 63 63 61 65 63 61 74 03 07 04 00 01 06 66 66 69   ccaecat......ffi
         2121  +|   3920: 63 69 61 03 08 06 00 00 08 70 61 72 69 61 74 75   cia......pariatu
         2122  +|   3936: 72 03 06 07 00 01 07 72 6f 69 64 65 6e 74 03 07   r......roident..
         2123  +|   3952: 07 00 00 03 71 75 69 03 08 05 00 03 01 73 03 03   ....qui......s..
         2124  +|   3968: 07 00 00 0d 72 65 70 72 65 68 65 6e 64 65 72 69   ....reprehenderi
         2125  +|   3984: 74 03 05 07 00 00 03 73 65 64 03 02 02 00 01 03   t......sed......
         2126  +|   4000: 69 6e 74 03 07 03 00 02 01 74 03 01 05 00 01 03   int......t......
         2127  +|   4016: 75 6e 74 03 08 02 00 00 06 74 65 6d 70 6f 72 03   unt......tempor.
         2128  +|   4032: 02 05 00 00 07 75 6c 6c 61 6d 63 6f 03 03 0a 00   .....ullamco....
         2129  +|   4048: 01 01 74 09 02 07 00 01 02 00 01 03 00 00 05 76   ..t............v
         2130  +|   4064: 65 6c 69 74 03 05 0a 00 02 04 6e 69 61 6d 03 03   elit......niam..
         2131  +|   4080: 06 00 01 08 6f 6c 75 70 74 61 74 65 03 05 09 00   ....oluptate....
         2132  +| page 5 offset 16384
         2133  +|      0: 0a 00 00 00 03 0f eb 00 0f fb 0f f3 0f eb 00 00   ................
         2134  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 07 04 02 08 01   ................
         2135  +|   4080: 08 00 03 07 04 02 08 01 04 00 02 04 04 08 08 09   ................
         2136  +| page 6 offset 20480
         2137  +|      0: 0d 00 00 00 08 0f d0 00 0f fa 0f f4 0f ee 0f e8   ................
         2138  +|     16: 0f e2 0f dc 0f d6 0f d0 00 00 00 00 00 00 00 00   ................
         2139  +|   4048: 04 08 03 00 0e 0b 04 07 03 00 0e 06 04 06 03 00   ................
         2140  +|   4064: 0e 06 04 05 03 00 0e 0a 04 04 03 00 0e 07 04 03   ................
         2141  +|   4080: 03 00 0e 0a 04 02 03 00 0e 0b 04 01 03 00 0e 08   ................
         2142  +| page 7 offset 24576
         2143  +|      0: 0d 00 00 00 01 0f f7 00 0f f7 00 00 00 00 00 00   ................
         2144  +|   4080: 00 00 00 00 00 00 00 07 00 03 00 14 08 45 b5 03   .............E..
         2145  +| end crash-f7b636a855e1d2.db
         2146  +}]} {}
         2147  +
         2148  +do_execsql_test 14.1 {
         2149  +  WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<10)
         2150  +    INSERT INTO t1(a) SELECT randomblob(3000) FROM c;
         2151  +}
         2152  +
         2153  +do_catchsql_test 14.2 {
         2154  +  INSERT INTO t1(t1) VALUES('optimize');
         2155  +} {1 {database disk image is malformed}}
         2156  +
         2157  +#-------------------------------------------------------------------------
         2158  +reset_db
         2159  +do_execsql_test 15.0 {
         2160  +  CREATE VIRTUAL TABLE t1 USING fts3(a, content="");
         2161  +  INSERT INTO t1_segdir VALUES(0,0,0,0,'0 665',X'000261640303040002086970697363696e670301080001056c6971756103020c00050269700304040001036d65740301060001036e6a6d03080900010375746503050300000663696c6c756d0306020001066f6d6d6f646f0304070002096e736563746574757203010700050471756174030408000104756c7061030804000207706964617461740307050000086465736572756e740308070001016f0302030002036c6f720601040004050005016506020a00040300010375697303050200000265610304060001066975736d6f640302040001036c69740301090001036e696d13030300010373736503050b0002017403080b0001017403020900010175030604000101780304050002076365707465757203070100020a65726369746174696f6e030309000006667567696174030605000002696403080a0001016e070506040003030002086369646964756e740302060001047073756d030103000104727572650305040000066c61626f7265030208000502697303030b000502756d03080c0001046f72656d0301020000056d61676e6103020b000104696e696d0303050001056f6c6c69740308080000046e6973690304020001026f6e0307060002057374727564030308000104756c6c610306060000086f636361656361740307040001066666696369610308060000087061726961747572030607000107726f6964656e740307070000037175690308050003017303030700000d726570726568656e6465726974030507000003736564030202000103696e7403070300020174030105000103756e7403080200000674656d706f72030205000007756c6c616d636f03030a0001017409020700010200010300000576656c697403050a0002046e69616d0303060001086f6c75707461746503050900');
         2162  +}
         2163  +
         2164  +do_execsql_test 15.1 {
         2165  +  SELECT quote(matchinfo(t1, t1 ))==0 FROM t1 WHERE t1 MATCH 'e*';
         2166  +} {0 0 0 0 0 0}
         2167  +
         2168  +#-------------------------------------------------------------------------
         2169  +reset_db
         2170  +do_test 16.0 {
         2171  +  sqlite3 db {}
         2172  +  db deserialize [decode_hexdb {
         2173  +| size 28672 pagesize 4096 filename crash-de7e8cb026385a.db
         2174  +| page 1 offset 0
         2175  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         2176  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
         2177  +|     32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04   ................
         2178  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         2179  +|     96: 00 00 00 00 0d 0e ef 00 07 0d 4d 00 0f bd 0f 5f   ..........M...._
         2180  +|    112: 0e f7 0e 06 0e bc 0d a4 0d 4d 00 00 00 00 00 00   .........M......
         2181  +|   3392: 00 00 00 00 00 00 00 00 00 00 00 00 00 55 07 07   .............U..
         2182  +|   3408: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 73 74   ......tablet1_st
         2183  +|   3424: 61 74 74 31 5f 73 74 61 74 07 43 52 45 41 54 45   att1_stat.CREATE
         2184  +|   3440: 20 54 41 42 4c 45 20 27 74 31 5f 73 74 61 74 27    TABLE 't1_stat'
         2185  +|   3456: 28 69 64 20 49 af 54 45 47 45 52 20 50 52 49 4d   (id I.TEGER PRIM
         2186  +|   3472: 41 52 59 20 4b 45 59 2c 20 76 61 6c 75 65 20 42   ARY KEY, value B
         2187  +|   3488: 4c 4f 42 29 60 06 07 17 21 21 01 81 0b 74 61 62   LOB)`...!!...tab
         2188  +|   3504: 6c 65 74 31 5f 64 6f 63 73 69 7a 65 74 31 5f 64   let1_docsizet1_d
         2189  +|   3520: 6f 63 73 69 7a 65 06 43 52 45 41 54 45 20 54 41   ocsize.CREATE TA
         2190  +|   3536: 42 4c 45 20 27 74 31 5f 64 6f 63 73 69 7a 65 27   BLE 't1_docsize'
         2191  +|   3552: 28 64 6f 63 69 64 20 49 4e 54 45 47 45 52 20 50   (docid INTEGER P
         2192  +|   3568: 52 49 4d 41 52 59 20 4b 45 59 2c 20 73 69 7a 65   RIMARY KEY, size
         2193  +|   3584: 20 42 4c 4f 42 29 81 33 04 07 17 1f 1f 01 82 35    BLOB).3.......5
         2194  +|   3600: 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72 74 31   tablet1_segdirt1
         2195  +|   3616: 5f 73 65 67 64 69 72 04 43 52 45 41 54 45 20 54   _segdir.CREATE T
         2196  +|   3632: 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69 72 27   ABLE 't1_segdir'
         2197  +|   3648: 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52 2c 69   (level INTEGER,i
         2198  +|   3664: 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61 72 74   dx INTEGER,start
         2199  +|   3680: 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52 2c 6c   _block INTEGER,l
         2200  +|   3696: 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63 6b 20   eaves_end_block 
         2201  +|   3712: 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c 6f 63   INTEGER,end_bloc
         2202  +|   3728: 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74 20 42   k INTEGER,root B
         2203  +|   3744: 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45 59 28   LOB,PRIMARY KEY(
         2204  +|   3760: 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 05 06 17   level, idx))1...
         2205  +|   3776: 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74 65 5f   E...indexsqlite_
         2206  +|   3792: 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73 65 67   autoindex_t1_seg
         2207  +|   3808: 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72 05 00   dir_1t1_segdir..
         2208  +|   3824: 00 00 08 00 00 00 00 66 03 07 17 23 23 01 81 13   .......f...##...
         2209  +|   3840: 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e 74 73   tablet1_segments
         2210  +|   3856: 74 31 5f 73 65 67 6d 65 6e 74 73 03 43 52 45 41   t1_segments.CREA
         2211  +|   3872: 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67   TE TABLE 't1_seg
         2212  +|   3888: 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64 20 49   ments'(blockid I
         2213  +|   3904: 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b   NTEGER PRIMARY K
         2214  +|   3920: 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42 29 5c   EY, block BLOB).
         2215  +|   3936: 02 07 17 21 21 01 81 03 74 61 62 6c 65 74 31 5f   ...!!...tablet1_
         2216  +|   3952: 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74 65 6e   contentt1_conten
         2217  +|   3968: 74 02 43 52 45 41 54 45 20 54 41 42 4c 45 20 27   t.CREATE TABLE '
         2218  +|   3984: 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f 63 69   t1_content'(doci
         2219  +|   4000: 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52   d INTEGER PRIMAR
         2220  +|   4016: 59 20 4b 45 59 2c 20 27 63 30 61 27 29 41 01 06   Y KEY, 'c0a')A..
         2221  +|   4032: 17 11 11 08 71 74 61 62 6c 65 74 31 74 31 43 52   ....qtablet1t1CR
         2222  +|   4048: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         2223  +|   4064: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 34   LE t1 USING fts4
         2224  +|   4080: 28 61 2c 70 72 65 66 69 78 3d 27 31 2c 32 27 29   (a,prefix='1,2')
         2225  +| page 2 offset 4096
         2226  +|      0: 0d 00 00 00 08 0e 1f 00 0f c4 0f 7c 0f 34 0f 07   ...........|.4..
         2227  +|     16: 0e c3 0e 97 0e 63 0e 1f 00 00 00 00 00 00 00 00   .....c..........
         2228  +|   3600: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 42   ...............B
         2229  +|   3616: 08 04 00 81 09 73 75 6e 74 20 69 6e 20 63 75 6c   .....sunt in cul
         2230  +|   3632: 70 61 20 71 75 69 20 6f 66 66 69 63 69 61 20 64   pa qui officia d
         2231  +|   3648: 65 73 65 72 75 6e 74 20 6d 6f 6c 6c 69 74 20 61   eserunt mollit a
         2232  +|   3664: 6e 69 6d 20 69 64 20 65 73 74 20 6c 61 62 6f 72   nim id est labor
         2233  +|   3680: 75 6d 2e 32 07 03 00 6b 45 78 63 65 70 74 65 75   um.2...kExcepteu
         2234  +|   3696: 72 20 73 69 6e 74 20 6f 63 63 61 65 63 61 74 20   r sint occaecat 
         2235  +|   3712: 63 75 70 69 64 61 74 61 74 20 6e 6f 6e 20 70 72   cupidatat non pr
         2236  +|   3728: 6f 69 64 65 6e 74 2c 2a 06 03 00 5b 63 69 6c 6c   oident,*...[cill
         2237  +|   3744: 75 6d 20 64 6f 6c 6f 72 65 20 65 75 20 66 75 67   um dolore eu fug
         2238  +|   3760: 69 61 74 20 6e 75 6c 6c 61 20 70 61 72 69 61 74   iat nulla pariat
         2239  +|   3776: 75 72 2e 42 05 04 00 81 09 44 75 69 73 20 61 75   ur.B.....Duis au
         2240  +|   3792: 74 65 20 69 72 75 72 65 21 64 6f 6c 6f 72 20 69   te irure!dolor i
         2241  +|   3808: 6e 20 72 65 70 72 65 68 65 6e 64 65 72 69 74 20   n reprehenderit 
         2242  +|   3824: 69 6e 20 76 6f 6c 75 70 74 61 74 65 20 76 65 6c   in voluptate vel
         2243  +|   3840: 69 74 20 65 73 74 65 2b 04 03 00 5d 6e 69 73 69   it este+...]nisi
         2244  +|   3856: 20 75 74 20 61 6c 69 71 75 69 70 20 65 78 20 65    ut aliquip ex e
         2245  +|   3872: 61 20 63 6f 6d 6d 6f 64 6f 20 63 6f 6e 73 65 71   a commodo conseq
         2246  +|   3888: 75 61 74 2e 46 03 04 00 81 11 55 74 20 65 6e 69   uat.F.....Ut eni
         2247  +|   3904: 6d 20 61 64 20 6d 69 6e 69 6d 20 76 65 6e 69 61   m ad minim venia
         2248  +|   3920: 6d 2c 20 71 75 69 73 20 6e 6f 73 74 72 75 64 20   m, quis nostrud 
         2249  +|   3936: 65 78 65 72 63 69 74 61 74 69 6f 6e 20 75 6c 6c   exercitation ull
         2250  +|   3952: 61 6d 63 6f 20 6c 61 62 6f 72 69 73 46 02 04 00   amco laborisF...
         2251  +|   3968: 81 11 73 65 64 20 64 6f 20 65 69 75 73 6d 6f 64   ..sed do eiusmod
         2252  +|   3984: 20 74 65 6d 70 6f 72 20 69 6e 63 69 64 69 64 75    tempor incididu
         2253  +|   4000: 6e 74 20 75 74 20 6c 61 62 6f 72 65 20 65 74 20   nt ut labore et 
         2254  +|   4016: 64 6f 6c 6f 72 65 20 6d 61 67 6e 61 20 51 6c 69   dolore magna Qli
         2255  +|   4032: 71 75 61 2e 3a 01 03 00 7b 4c 6f 72 65 6d 20 69   qua.:....Lorem i
         2256  +|   4048: 70 73 75 6d 20 64 6f 6c 6f 72 20 73 69 74 e5 61   psum dolor sit.a
         2257  +|   4064: 6d 65 74 2c 20 63 6f 6e 73 65 63 74 65 74 75 72   met, consectetur
         2258  +|   4080: 20 61 64 69 70 69 73 63 69 6e 67 20 65 6c 69 74    adipiscing elit
         2259  +| page 3 offset 8192
         2260  +|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
         2261  +| page 4 offset 12288
         2262  +|      0: 0d 00 00 00 03 0a a6 00 0d 57 0c 4a 0a a6 00 00   .........W.J....
         2263  +|   2720: 00 00 00 00 00 00 83 21 03 08 02 08 08 08 17 86   .......!........
         2264  +|   2736: 30 08 00 30 20 34 30 32 00 02 61 64 06 01 08 00   0..0 402..ad....
         2265  +|   2752: 02 04 00 01 01 6c 06 02 0c 00 02 04 00 01 01 6d   .....l.........m
         2266  +|   2768: 03 01 06 00 01 01 6e 03 08 09 00 01 01 75 03 05   ......n......u..
         2267  +|   2784: 03 00 00 02 63 69 03 06 02 00 01 01 6f 07 01 07   ....ci......o...
         2268  +|   2800: 00 03 07 03 00 01 01 75 06 07 05 00 01 04 00 00   .......u........
         2269  +|   2816: 02 64 65 03 08 07 00 01 01 6f 0d 01 04 00 01 03   .de......o......
         2270  +|   2832: 09 00 03 05 00 01 03 00 01 01 75 03 05 02 00 00   ..........u.....
         2271  +|   2848: 02 65 61 03 04 06 00 01 01 69 03 02 04 00 01 01   .ea......i......
         2272  +|   2864: 6c 03 01 09 00 01 01 6e 03 03 03 00 01 01 73 06   l......n......s.
         2273  +|   2880: 05 0b 00 03 0b 00 01 01 74 03 02 09 00 01 01 75   ........t......u
         2274  +|   2896: 03 06 04 00 01 01 78 09 03 09 00 01 05 00 03 02   ......x.........
         2275  +|   2912: 00 00 02 66 75 03 06 05 00 00 02 69 64 03 08 0a   ...fu......id...
         2276  +|   2928: 00 01 01 6e 0a 02 06 00 03 06 04 00 03 03 00 01   ...n............
         2277  +|   2944: 01 70 03 01 03 00 01 01 72 03 05 04 00 00 02 6c   .p......r......l
         2278  +|   2960: 61 09 02 08 00 01 0b 00 05 0c 00 01 01 6f 03 01   a............o..
         2279  +|   2976: 02 00 00 02 6d 61 03 02 0b 00 01 01 69 03 03 05   ....ma......i...
         2280  +|   2992: 00 01 01 6f 03 08 08 00 00 02 6e 69 03 04 02 00   ...o......ni....
         2281  +|   3008: 01 01 6f 06 03 08 00 04 06 00 01 01 75 03 06 06   ..o.........u...
         2282  +|   3024: 00 00 02 6f 63 03 07 04 00 01 01 66 03 08 06 00   ...oc......f....
         2283  +|   3040: 00 02 70 61 03 06 07 00 01 01 72 03 07 07 00 00   ..pa......r.....
         2284  +|   3056: 02 71 75 06 03 07 00 05 05 00 00 02 72 65 03 05   .qu.........re..
         2285  +|   3072: 07 00 00 02 73 65 03 02 02 00 01 01 69 06 01 05   ....se......i...
         2286  +|   3088: 00 06 03 00 01 01 75 03 08 02 00 00 02 74 65 03   ......u......te.
         2287  +|   3104: 02 05 00 00 02 75 6c 03 03 0a 00 01 01 74 09 02   .....ul......t..
         2288  +|   3120: 07 00 01 02 00 01 03 00 00 02 76 65 06 03 06 00   ..........ve....
         2289  +|   3136: 02 0a 00 01 01 6f 03 05 09 00 82 0a 02 08 12 08   .....o..........
         2290  +|   3152: 08 08 17 84 02 04 00 30 20 32 35 31 00 01 61 23   .......0 251..a#
         2291  +|   3168: 01 06 04 00 01 0c 00 01 04 00 01 04 00 01 03 00   ................
         2292  +|   3184: 03 09 00 00 01 63 10 01 07 00 03 07 03 00 02 02   .....c..........
         2293  +|   3200: 00 01 05 00 01 04 00 00 01 64 11 01 04 00 01 03   .........d......
         2294  +|   3216: 09 00 03 02 05 00 01 13 00 02 07 00 00 01 65 1b   ..............e.
         2295  +|   3232: 01 09 00 01 04 07 00 01 03 08 00 01 05 03 00 01   ................
         2296  +|   3248: 0b 00 01 04 00 01 02 00 01 0b 00 00 01 66 03 06   .............f..
         2297  +|   3264: 05 00 00 01 69 0f 01 03 00 01 06 00 03 04 04 04   ....i...........
         2298  +|   3280: 00 03 03 09 00 00 01 6c 0c 01 02 00 01 08 00 01   .......l........
         2299  +|   3296: 0b 00 05 0c 00 10 01 6d 09 02 0b 00 01 05 00 05   .......m........
         2300  +|   3312: 08 00 00 01 6e 0c 03 08 00 01 02 00 02 06 00 01   ....n...........
         2301  +|   3328: 06 00 00 01 6f 06 07 04 00 01 06 00 00 01 70 06   ....o.........p.
         2302  +|   3344: 06 07 00 01 07 00 00 01 71 06 03 07 00 05 05 00   ........q.......
         2303  +|   3360: 00 01 72 03 05 07 00 00 01 73 0c 01 05 00 01 02   ..r......s......
         2304  +|   3376: 00 05 03 00 01 02 00 00 01 74 03 02 05 00 00 01   .........t......
         2305  +|   3392: 75 0a 02 07 00 01 02 0a 00 01 03 00 00 01 76 07   u.............v.
         2306  +|   3408: 03 06 00 02 09 03 00 85 26 01 08 08 08 08 08 17   ........&.......
         2307  +|   3424: 8a 3e 30 20 36 36 35 00 02 61 64 03 03 04 00 02   .>0 665..ad.....
         2308  +|   3440: 08 69 70 69 73 63 69 6e 67 03 01 08 00 01 05 6c   .ipiscing......l
         2309  +|   3456: 69 71 75 61 03 02 0c 00 05 02 69 70 03 04 04 00   iqua......ip....
         2310  +|   3472: 01 03 6d 65 74 03 01 06 00 01 03 6e 69 6d 03 08   ..met......nim..
         2311  +|   3488: 09 00 01 03 75 74 65 03 05 03 00 00 06 63 69 6c   ....ute......cil
         2312  +|   3504: 6c 75 6d 03 06 02 00 01 06 6f 6d 6d 6f 64 6f 03   lum......ommodo.
         2313  +|   3520: 04 07 00 02 09 6e 73 65 63 74 65 74 75 72 03 01   .....nsectetur..
         2314  +|   3536: 07 00 05 04 71 75 61 74 03 04 08 00 01 04 75 6c   ....quat......ul
         2315  +|   3552: 70 61 03 08 04 00 02 07 70 69 64 61 74 61 74 03   pa......pidatat.
         2316  +|   3568: 07 05 00 00 08 64 65 73 65 72 75 6e 74 03 08 07   .....deserunt...
         2317  +|   3584: 00 01 01 6f 03 02 03 00 02 03 6c 6f 72 06 01 04   ...o......lor...
         2318  +|   3600: 00 04 05 00 05 01 65 06 02 0a 00 04 03 00 01 03   ......e.........
         2319  +|   3616: 75 69 73 03 05 02 00 00 02 65 61 03 04 06 00 01   uis......ea.....
         2320  +|   3632: 06 69 75 73 6d 6f 64 03 02 04 00 01 03 6c 69 74   .iusmod......lit
         2321  +|   3648: 03 01 09 00 01 03 6e 69 6d 03 03 03 00 01 03 73   ......nim......s
         2322  +|   3664: 73 65 03 05 0b 00 02 01 74 03 08 0b 00 01 01 74   se......t......t
         2323  +|   3680: 03 02 09 00 01 01 75 03 06 04 00 01 01 78 03 04   ......u......x..
         2324  +|   3696: 05 00 02 07 63 65 70 74 65 75 72 03 07 02 00 02   ....cepteur.....
         2325  +|   3712: 0a 65 72 63 69 74 61 74 69 6f 6e 03 03 09 00 00   .ercitation.....
         2326  +|   3728: 06 66 75 67 69 61 74 03 06 05 00 00 02 69 64 03   .fugiat......id.
         2327  +|   3744: 08 0a 00 01 01 6e 07 05 06 04 00 03 03 00 02 08   .....n..........
         2328  +|   3760: 63 69 64 69 64 75 7e 74 03 02 06 00 01 04 70 73   cididu~t......ps
         2329  +|   3776: 75 6d 03 01 03 00 01 03 72 75 72 65 03 05 04 00   um......rure....
         2330  +|   3792: 00 06 6c 61 62 6f 72 65 03 02 08 00 05 02 69 73   ..labore......is
         2331  +|   3808: 03 03 0b 00 05 02 75 6d 03 08 0c 00 01 04 6f 72   ......um......or
         2332  +|   3824: 65 6d 03 01 02 00 00 05 6d 61 67 6e 61 03 02 0b   em......magna...
         2333  +|   3840: 00 01 04 69 6e 69 6d 03 03 05 00 01 05 6f 6c 6c   ...inim......oll
         2334  +|   3856: 69 74 03 08 08 00 00 04 6e 69 73 69 03 04 02 00   it......nisi....
         2335  +|   3872: 01 02 6f 6e 03 07 06 00 02 05 73 74 72 75 64 03   ..on......strud.
         2336  +|   3888: 03 08 00 01 04 75 6c 6c 61 03 06 06 00 00 08 6f   .....ulla......o
         2337  +|   3904: 63 63 61 65 63 61 74 03 07 04 00 01 06 66 66 69   ccaecat......ffi
         2338  +|   3920: 63 69 61 03 08 06 00 00 08 70 61 72 69 61 74 75   cia......pariatu
         2339  +|   3936: 72 03 06 07 00 01 07 72 6f 69 64 65 6e 74 03 07   r......roident..
         2340  +|   3952: 07 00 00 03 71 75 69 03 08 05 00 03 01 73 03 03   ....qui......s..
         2341  +|   3968: 07 00 00 0d 72 65 70 72 65 68 65 6e 64 65 72 69   ....reprehenderi
         2342  +|   3984: 74 03 05 07 00 00 03 73 65 64 03 02 02 00 01 03   t......sed......
         2343  +|   4000: 69 6e 74 03 07 03 00 02 01 74 03 01 05 00 01 03   int......t......
         2344  +|   4016: 75 6e 74 03 08 02 00 00 06 74 65 6d 70 6f 72 03   unt......tempor.
         2345  +|   4032: 02 05 00 00 07 75 6c 6c 61 6d 63 6f 03 03 0a 00   .....ullamco....
         2346  +|   4048: 01 01 74 09 02 07 00 01 02 00 01 03 00 00 05 76   ..t............v
         2347  +|   4064: 65 6c 69 74 03 05 0a 00 02 04 6e 69 61 6d 03 03   elit......niam..
         2348  +|   4080: 06 00 01 08 6f 6c 75 70 74 61 74 65 03 05 09 00   ....oluptate....
         2349  +| page 5 offset 16384
         2350  +|      0: 0a 00 00 00 03 0f eb 00 0f fb 0f f3 0f eb 00 00   ................
         2351  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 07 04 02 08 01   ................
         2352  +|   4080: 08 00 03 07 04 02 08 03 a4 00 02 04 04 08 08 09   ................
         2353  +| page 6 offset 20480
         2354  +|      0: 0d 00 00 00 08 0f d0 00 0f fa 0f f4 0f ee 0f e8   ................
         2355  +|     16: 0f e2 0f dc 0f d6 0f d0 00 00 00 00 00 00 00 00   ................
         2356  +|   4048: 04 08 03 00 0e 0b 04 07 03 00 0e 06 04 06 03 00   ................
         2357  +|   4064: 0e 06 04 05 03 00 0e 0a 04 04 03 00 0e 07 04 03   ................
         2358  +|   4080: 03 00 0e 0a 04 02 03 00 0e 0b 04 01 03 00 0e 08   ................
         2359  +| page 7 offset 24576
         2360  +|      0: 0d 00 00 00 01 0f f7 00 0f f7 00 00 00 00 00 00   ................
         2361  +|   4080: 00 00 00 00 00 00 00 07 00 03 00 14 08 45 b5 03   .............E..
         2362  +| end crash-de7e8cb026385a.db
         2363  +}]} {}
         2364  +
         2365  +do_catchsql_test 16.1 {
         2366  +  INSERT INTO t1(t1) VALUES('optimize');
         2367  +} {0 {}}
         2368  +
         2369  +#-------------------------------------------------------------------------
         2370  +reset_db
         2371  +do_test 17.0 {
         2372  +  sqlite3 db {}
         2373  +  db deserialize [decode_hexdb {
         2374  +.open --hexdb
         2375  +| size 28672 pagesize 4096 filename crash-f15972acf5bc1c.db
         2376  +| page 1 offset 0
         2377  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         2378  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
         2379  +|     32: 00 00 00 02 00 00 00 01 00 00 00 07 00 00 00 04   ................
         2380  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
         2381  +|     96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21   ...............!
         2382  +|    112: 0e b9 0d c8 0e 7e 0d a4 0d a4 00 00 00 00 00 00   .....~..........
         2383  +|   3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c   ...........1tabl
         2384  +|   3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42   et2t2.CREATE TAB
         2385  +|   3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01   LE t2(x).3......
         2386  +|   3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72   .5tablet1_segdir
         2387  +|   3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45   t1_segdir.CREATE
         2388  +|   3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69    TABLE 't1_segdi
         2389  +|   3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 52   r'(level INTEGER
         2390  +|   3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61   ,idx INTEGER,sta
         2391  +|   3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52   rt_block INTEGER
         2392  +|   3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63   ,leaves_end_bloc
         2393  +|   3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c   k INTEGER,end_bl
         2394  +|   3664: 6f 63 6b 20 49 4e 54 45 47 45 52 2c 72 6f 6f 74   ock INTEGER,root
         2395  +|   3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45    BLOB,PRIMARY KE
         2396  +|   3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06   Y(level, idx))1.
         2397  +|   3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74   ..E...indexsqlit
         2398  +|   3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73   e_autoindex_t1_s
         2399  +|   3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72   egdir_1t1_segdir
         2400  +|   3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01   .........f...##.
         2401  +|   3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 67 6d 65 6e   ..tablet1_segmen
         2402  +|   3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52   tst1_segments.CR
         2403  +|   3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73   EATE TABLE 't1_s
         2404  +|   3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64   egments'(blockid
         2405  +|   3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59    INTEGER PRIMARY
         2406  +|   3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42    KEY, block BLOB
         2407  +|   3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74   )j...!!...tablet
         2408  +|   3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74   1_contentt1_cont
         2409  +|   3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45   ent.CREATE TABLE
         2410  +|   3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f    't1_content'(do
         2411  +|   3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   cid INTEGER PRIM
         2412  +|   3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20   ARY KEY, 'c0a', 
         2413  +|   3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06   'c1b', 'c2c')8..
         2414  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         2415  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         2416  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33   LE t1 USING fts3
         2417  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 39 00 00 00 00 00   (a,b,c)...9.....
         2418  +| page 3 offset 8192
         2419  +|      0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74   ....%.H........t
         2420  +|     16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5   .a.N./..........
         2421  +|     32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 0d d5   ...t.[.@.$......
         2422  +|     48: 0d bb 0d a0 0d 84 03 28 0d 4f 0d 35 0d 1b 0c fb   .......(.O.5....
         2423  +|     64: 0c da 0c b9 0c 99 0c 78 0c 57 0c 3e 0c 24 0c 0a   .......x.W.>.$..
         2424  +|     80: 0b 48 00 00 00 00 00 00 00 00 00 00 00 00 00 00   .H..............
         2425  +|   2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 72 7f 00   .........?%..r..
         2426  +