/ Check-in [1660d773]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Fix a buffer overread that could in fts3 when dealing with corrupt records.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 1660d7733eb443ab085ddef7666b998a1c75ac81cc54a9620960a8d3b377e28e
User & Date: dan 2019-05-22 14:22:44
Context
2019-05-22
14:35
New dbsqlfuzz find added to test/fuzzdata8.db. check-in: 42af7c81 user: drh tags: trunk
14:22
Fix a buffer overread that could in fts3 when dealing with corrupt records. check-in: 1660d773 user: dan tags: trunk
2019-05-21
17:04
Combine the implementations of the key and hexkey pragmas into a single case. Have both pragmas return "ok" if they are implemented. check-in: b3692c40 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3_write.c.

  2615   2615       if( iCol==iCurrent ){
  2616   2616         nList = (int)(p - pList);
  2617   2617         break;
  2618   2618       }
  2619   2619   
  2620   2620       nList -= (int)(p - pList);
  2621   2621       pList = p;
  2622         -    if( nList==0 ){
         2622  +    if( nList<=0 ){
  2623   2623         break;
  2624   2624       }
  2625   2625       p = &pList[1];
  2626   2626       p += fts3GetVarint32(p, &iCurrent);
  2627   2627     }
  2628   2628   
  2629         -  if( bZero && &pList[nList]!=pEnd ){
         2629  +  if( bZero && (pEnd - &pList[nList])>0){
  2630   2630       memset(&pList[nList], 0, pEnd - &pList[nList]);
  2631   2631     }
  2632   2632     *ppList = pList;
  2633   2633     *pnList = nList;
  2634   2634   }
  2635   2635   
  2636   2636   /*

Changes to test/fts3corrupt4.test.

  1942   1942   |   4064: 69 74 79 2d 63 68 65 63 6b 09 02 02 1b 72 65 62   ity-check....reb
  1943   1943   |   4080: 75 69 6c 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   uild....optimize
  1944   1944   | end crash-c666cfde112dee.db
  1945   1945   }]} {}
  1946   1946   
  1947   1947   do_catchsql_test 13.1 {
  1948   1948     SELECT quote(matchinfo(t1,'pcxybs'))==0 FROM t1 WHERE b MATCH 'e*';
  1949         -} {0 {0 0}}
         1949  +} {0 {}}
  1950   1950   
  1951   1951   #-------------------------------------------------------------------------
  1952   1952   reset_db
  1953   1953   do_test 14.0 {
  1954   1954     sqlite3 db {}
  1955   1955     db deserialize [decode_hexdb {
  1956   1956   | size 28672 pagesize 4096 filename crash-f7b636a855e1d2.db
................................................................................
  2822   2822   |     16: 2d 63 68 65 63 6b 09 02 02 1b 72 65 62 75 69 6c   -check....rebuil
  2823   2823   |     32: 64 0a 01 02 1d 6f 70 74 69 6d 69 7a 65 00 00 00   d....optimize...
  2824   2824   | end crash-4ce32d0608aff1.db
  2825   2825   }]} {}
  2826   2826   
  2827   2827   do_catchsql_test 18.1 {
  2828   2828     SELECT quote(matchinfo(t1,'pcxybs'))==0 FROM t1 WHERE b MATCH 'e*';
  2829         -} {0 0}
         2829  +} {0 {}}
  2830   2830   
  2831   2831   #-------------------------------------------------------------------------
  2832   2832   reset_db
  2833   2833   do_test 19.0 {
  2834   2834     sqlite3 db {}
  2835   2835     db deserialize [decode_hexdb {
  2836   2836   | size 28672 pagesize 4096 filename crash-526ea445f41c02.db
................................................................................
  4396   4396       INSERT INTO t1( a ) SELECT randomblob(3000) FROM t2 ;
  4397   4397   } {0 {}}
  4398   4398   
  4399   4399   do_catchsql_test 25.6 {
  4400   4400     INSERT INTO t1(t1) SELECT x FROM t2;
  4401   4401     INSERT INTO t1(t1) SELECT x FROM t2;
  4402   4402   } {1 {database disk image is malformed}}
         4403  +
         4404  +#-------------------------------------------------------------------------
         4405  +reset_db
         4406  +do_test 26.0 {
         4407  +  sqlite3 db {}
         4408  +  db deserialize [decode_hexdb {
         4409  +.open --hexdb
         4410  +| size 28672 pagesize 4096 filename crash-26682721375870.db
         4411  +| page 1 offset 0
         4412  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
         4413  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 00   .....@  ........
         4414  +|     96: 00 00 00 00 0d 0e b1 00 06 0d a4 00 0f 8d 0f 21   ...............!
         4415  +|    112: 0e b9 0d c8 0e 7e 0d a4 00 00 00 00 00 00 00 00   .....~..........
         4416  +|   3488: 00 00 00 00 22 07 06 17 11 11 01 31 74 61 62 6c   ...........1tabl
         4417  +|   3504: 65 74 32 74 32 07 43 52 45 41 54 45 20 54 41 42   et2t2.CREATE TAB
         4418  +|   3520: 4c 45 20 74 32 28 78 29 81 33 05 07 17 1f 1f 01   LE t2(x).3......
         4419  +|   3536: 82 35 74 61 62 6c 65 74 31 5f 73 65 67 64 69 72   .5tablet1_segdir
         4420  +|   3552: 74 31 5f 73 65 67 64 69 72 05 43 52 45 41 54 45   t1_segdir.CREATE
         4421  +|   3568: 20 54 41 42 4c 45 20 27 74 31 5f 73 65 67 64 69    TABLE 't1_segdi
         4422  +|   3584: 72 27 28 6c 65 76 65 6c 20 49 4e 54 45 47 45 51   r'(level INTEGEQ
         4423  +|   3600: 2c 69 64 78 20 49 4e 54 45 47 45 52 2c 73 74 61   ,idx INTEGER,sta
         4424  +|   3616: 72 74 5f 62 6c 6f 63 6b 20 49 4e 54 45 47 45 52   rt_block INTEGER
         4425  +|   3632: 2c 6c 65 61 76 65 73 5f 65 6e 64 5f 62 6c 6f 63   ,leaves_end_bloc
         4426  +|   3648: 6b 20 49 4e 54 45 47 45 52 2c 65 6e 64 5f 62 6c   k INTEGER,end_bl
         4427  +|   3664: 6f 63 6b 20 49 4e 54 45 47 45 62 2c 72 6f 6f 74   ock INTEGEb,root
         4428  +|   3680: 20 42 4c 4f 42 2c 50 52 49 4d 41 52 59 20 4b 45    BLOB,PRIMARY KE
         4429  +|   3696: 59 28 6c 65 76 65 6c 2c 20 69 64 78 29 29 31 06   Y(level, idx))1.
         4430  +|   3712: 06 17 45 1f 01 00 69 6e 64 65 78 73 71 6c 69 74   ..E...indexsqlit
         4431  +|   3728: 65 5f 61 75 74 6f 69 6e 64 65 78 5f 74 31 5f 73   e_autoindex_t1_s
         4432  +|   3744: 65 67 64 69 72 5f 31 74 31 5f 73 65 67 64 69 72   egdir_1t1_segdir
         4433  +|   3760: 06 0f c7 00 08 00 00 00 00 66 04 07 17 23 23 01   .........f...##.
         4434  +|   3776: 81 13 74 61 62 6c 65 74 31 5f 73 65 66 6d 65 6e   ..tablet1_sefmen
         4435  +|   3792: 74 73 74 31 5f 73 65 67 6d 65 6e 74 73 04 43 52   tst1_segments.CR
         4436  +|   3808: 45 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 73   EATE TABLE 't1_s
         4437  +|   3824: 65 67 6d 65 6e 74 73 27 28 62 6c 6f 63 6b 69 64   egments'(blockid
         4438  +|   3840: 20 49 4e 54 45 47 45 52 20 50 52 49 4d 41 52 59    INTEGER PRIMARY
         4439  +|   3856: 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42 4c 4f 42    KEY, block BLOB
         4440  +|   3872: 29 6a 03 07 17 21 21 01 81 1f 74 61 62 6c 65 74   )j...!!...tablet
         4441  +|   3888: 31 5f 63 6f 6e 74 65 6e 74 74 31 5f 63 6f 6e 74   1_contentt1_cont
         4442  +|   3904: 65 6e 74 03 43 52 45 41 54 45 20 54 41 42 4c 45   ent.CREATE TABLE
         4443  +|   3920: 20 27 74 31 5f 63 6f 6e 74 65 6e 74 27 28 64 6f    't1_content'(do
         4444  +|   3936: 63 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   cid INTEGER PRIM
         4445  +|   3952: 41 52 59 20 4b 45 59 2c 20 27 63 30 61 27 2c 20   ARY KEY, 'c0a', 
         4446  +|   3968: 27 63 31 62 27 2c 20 27 63 32 63 27 29 38 02 06   'c1b', 'c2c')8..
         4447  +|   3984: 17 11 11 08 5f 74 61 62 6c 65 74 31 74 31 43 52   ...._tablet1t1CR
         4448  +|   4000: 45 41 54 45 20 56 49 52 54 55 41 4c 20 54 41 42   EATE VIRTUAL TAB
         4449  +|   4016: 4c 45 20 74 31 20 55 53 49 4e 47 20 66 74 73 33   LE t1 USING fts3
         4450  +|   4032: 28 61 2c 62 2c 63 29 00 00 00 00 00 00 00 00 00   (a,b,c).........
         4451  +| page 3 offset 8192
         4452  +|      0: 0d 00 00 00 25 0b 48 00 0f d8 0f af 0f 86 0f 74   ....%.H........t
         4453  +|     16: 0f 61 0f 4e 0f 2f 0f 0f 0e ef 0e d7 0e be 0e a5   .a.N./..........
         4454  +|     32: 0e 8d 0e 74 0e 5b 0e 40 0e 24 0e 08 0d ef 00 00   ...t.[.@.$......
         4455  +|   2880: 00 00 00 00 00 00 00 00 81 3f 25 06 00 82 7f 00   .........?%.....
         4456  +|   2896: 00 43 4f 4d 50 49 4c 45 52 3d 67 63 63 2d 35 2e   .COMPILER=gcc-5.
         4457  +|   2912: 34 23 00 20 32 2f 31 36 30 36 30 39 20 44 45 42   4#. 2/160609 DEB
         4458  +|   2928: 55 47 20 45 4e 41 42 4c 45 20 44 42 53 54 41 54   UG ENABLE DBSTAT
         4459  +|   2944: 20 56 54 41 42 20 45 4e 41 42 4c 45 20 46 54 53    VTAB ENABLE FTS
         4460  +|   2960: 34 20 45 4e 41 42 4c 45 20 46 54 53 35 20 45 4e   4 ENABLE FTS5 EN
         4461  +|   2976: 41 42 4c 45 20 47 45 4f 50 4f 4c 59 20 45 4e 41   ABLE GEOPOLY ENA
         4462  +|   2992: 42 4c 45 20 4a 53 4f 4e 31 20 45 4e 41 42 4c 45   BLE JSON1 ENABLE
         4463  +|   3008: 20 4d 45 4d 53 59 53 35 20 45 4e 41 42 4c 45 20    MEMSYS5 ENABLE 
         4464  +|   3024: 52 54 52 45 45 20 4d 41 58 20 4d 45 4d 4f 52 59   RTREE MAX MEMORY
         4465  +|   3040: 3d 35 30 30 30 30 30 30 30 20 4f 4d 49 54 20 4c   =50000000 OMIT L
         4466  +|   3056: 4f 41 44 20 45 58 54 45 4e 53 59 4f 4e 20 54 48   OAD EXTENSYON TH
         4467  +|   3072: 52 45 41 44 53 41 46 45 3d 30 18 24 05 00 25 0f   READSAFE=0.$..%.
         4468  +|   3088: 19 54 48 52 45 41 44 53 41 46 45 3d 30 58 42 49   .THREADSAFE=0XBI
         4469  +|   3104: 4e 41 52 59 18 23 05 00 25 0f 19 54 48 52 45 41   NARY.#..%..THREA
         4470  +|   3120: 44 53 41 46 45 3d 30 58 4e 4f 43 41 53 45 17 22   DSAFE=0XNOCASE..
         4471  +|   3136: 05 00 25 0f 17 54 38 52 45 41 44 53 41 46 45 3d   ..%..T8READSAFE=
         4472  +|   3152: 30 58 52 54 52 49 4d 1f 21 05 00 33 0f 19 4f 4d   0XRTRIM.!..3..OM
         4473  +|   3168: 49 54 20 4c 4f 41 44 20 45 58 54 45 fc 53 49 4f   IT LOAD EXTE.SIO
         4474  +|   3184: 4e 68 42 49 4e 4a c2 59 1f 20 05 00 33 0f 19 4f   NhBINJ.Y. ..3..O
         4475  +|   3200: 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53 49   MIT LOAD EXTENSI
         4476  +|   3216: 4f 4e 58 4e 4f 43 41 53 45 1e 1f 05 00 33 0f 17   ONXNOCASE....3..
         4477  +|   3232: 4f 4d 49 54 20 4c 4f 41 44 20 45 58 54 45 4e 53   OMIT LOAD EXTENS
         4478  +|   3248: 49 4f 4e 58 52 54 52 49 4d 1f 1e 05 00 33 0f 19   IONXRTRIM....3..
         4479  +|   3264: 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 2f 30 30   MAX MEMORY=50/00
         4480  +|   3280: 30 30 30 58 42 49 4e 41 52 59 1f 1d 05 00 33 0f   000XBINARY....3.
         4481  +|   3296: 19 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30 30   .MAX MEMORY=5000
         4482  +|   3312: 30 30 30 30 48 4e 4f 43 41 53 45 1e 1c 05 00 33   0000HNOCASE....3
         4483  +|   3328: 0f 17 4d 41 58 20 4d 45 4d 4f 52 59 3d 35 30 30   ..MAX MEMORY=500
         4484  +|   3344: 30 30 30 30 30 58 52 54 52 49 4d 18 1b 05 00 25   00000XRTRIM....%
         4485  +|   3360: 0f 19 45 4e 41 42 4c 45 20 52 54 52 45 45 58 42   ..ENABLE RTREEXB
         4486  +|   3376: 49 4e 41 52 59 18 1a 05 00 25 0f 19 45 4e 41 42   INARY....%..ENAB
         4487  +|   3392: 4c 45 20 52 54 52 45 45 58 4e 4f 53 41 53 45 17   LE RTREEXNOSASE.
         4488  +|   3408: 19 05 00 25 0f 17 45 4e 41 42 4c 45 20 52 54 52   ...%..ENABLE RTR
         4489  +|   3424: 45 45 58 52 54 52 49 4d 1a 18 05 00 29 0f 19 45   EEXRTRIM....)..E
         4490  +|   3440: 4e 41 42 4c 45 20 4d 45 4d 53 59 53 35 58 42 49   NABLE MEMSYS5XBI
         4491  +|   3456: 4e 41 52 59 1a 17 05 00 29 0f 19 45 4e 41 42 4c   NARY....)..ENABL
         4492  +|   3472: 45 20 4d 45 4d 53 59 53 35 58 4e 4f 43 41 53 45   E MEMSYS5XNOCASE
         4493  +|   3488: 19 16 05 00 29 0f 17 45 4e 41 42 4c 45 20 4d 45   ....)..ENABLE ME
         4494  +|   3504: 4d 53 59 53 35 58 52 54 52 49 4d 18 15 05 00 25   MSYS5XRTRIM....%
         4495  +|   3520: 0f 19 45 4e 41 42 4c 45 20 4a 53 4f 4e 31 58 42   ..ENABLE JSON1XB
         4496  +|   3536: 49 4e 41 52 59 18 14 05 00 25 0f 19 45 4e 42 42   INARY....%..ENBB
         4497  +|   3552: 4d 45 20 4a 53 4f 4e 31 58 4e 4f 43 41 53 45 17   ME JSON1XNOCASE.
         4498  +|   3568: 13 05 00 25 0f 17 45 4e 41 42 4c 45 20 4a 53 4f   ...%..ENABLE JSO
         4499  +|   3584: 4e 31 58 52 54 52 49 4d 1a 12 05 00 29 0f 19 45   N1XRTRIM....)..E
         4500  +|   3600: 4e 41 42 4c 45 20 47 45 4f 50 4f 4c 59 58 42 49   NABLE GEOPOLYXBI
         4501  +|   3616: 4e 41 52 59 1a 11 05 00 29 0f 19 45 4e 41 1e 4c   NARY....)..ENA.L
         4502  +|   3632: 45 20 47 45 4f 50 4f 4c 59 58 4e 4f 43 41 53 45   E GEOPOLYXNOCASE
         4503  +|   3648: 19 10 05 00 29 0f 17 45 4e 41 42 4c 45 20 47 45   ....)..ENABLE GE
         4504  +|   3664: 4f 50 4f 4c 59 58 62 54 52 49 4d 17 0f 05 00 23   OPOLYXbTRIM....#
         4505  +|   3680: 0f 19 45 4e 41 42 4c 45 20 46 54 53 35 58 42 49   ..ENABLE FTS5XBI
         4506  +|   3696: 4e 41 52 59 17 0e 05 00 23 0f 19 45 4e 41 42 4c   NARY....#..ENABL
         4507  +|   3712: 45 20 46 54 fc 35 58 4e 4f 43 41 53 45 16 0d 05   E FT.5XNOCASE...
         4508  +|   3728: 00 23 0f 17 45 4e 41 42 4c 45 20 46 54 53 35 58   .#..ENABLE FTS5X
         4509  +|   3744: 52 54 52 49 4d 17 0c 05 00 23 0f 19 45 4e 41 42   RTRIM....#..ENAB
         4510  +|   3760: 4c 45 20 46 54 53 34 58 42 49 4e 41 52 59 17 0b   LE FTS4XBINARY..
         4511  +|   3776: 05 00 23 0f 19 45 4e 41 42 4c 45 20 46 54 53 35   ..#..ENABLE FTS5
         4512  +|   3792: 58 4e 4f 43 40 53 45 16 0a 05 00 23 0f 17 45 4e   XNOC@SE....#..EN
         4513  +|   3808: 41 42 4c 45 20 56 54 53 34 58 52 54 52 49 4d 1e   ABLE VTS4XRTRIM.
         4514  +|   3824: 09 05 00 31 0f 19 45 4e 41 42 4c 45 20 44 42 53   ...1..ENABLE DBS
         4515  +|   3840: 54 41 54 20 56 54 41 42 58 42 49 4e 41 b3 58 1e   TAT VTABXBINA.X.
         4516  +|   3856: 08 05 00 31 0f 19 45 4e 40 42 4c 45 20 44 42 53   ...1..EN@BLE DBS
         4517  +|   3872: 54 41 54 20 56 54 41 42 58 4e 4f 43 41 53 45 1d   TAT VTABXNOCASE.
         4518  +|   3888: 07 05 00 31 0f 17 45 4e 41 42 4c 45 20 45 42 53   ...1..ENABLE EBS
         4519  +|   3904: 54 41 54 20 56 54 41 42 58 52 54 52 49 4d 11 06   TAT VTABXRTRIM..
         4520  +|   3920: 05 00 17 0f 19 44 45 42 55 47 58 42 49 4e 41 52   .....DEBUGXBINAR
         4521  +|   3936: 59 11 05 05 00 17 0f 19 44 45 42 55 47 58 4e 4f   Y.......DEBUGXNO
         4522  +|   3952: 43 41 53 45 10 04 05 00 17 0f 17 44 45 42 55 47   CASE.......DEBUG
         4523  +|   3968: 58 52 54 52 49 4d 27 03 05 00 43 0f 19 43 4f 4d   XRTRIM'...C..COM
         4524  +|   3984: 50 49 4c 45 52 3d 67 63 63 2d 35 2e 34 2e 30 20   PILER=gcc-5.4.0 
         4525  +|   4000: 32 30 31 36 30 36 30 39 58 4b 19 4e 41 52 59 27   20160609XK.NARY'
         4526  +|   4016: 02 05 00 43 0f 19 43 4f 4d 50 49 4c 45 52 3d 67   ...C..COMPILER=g
         4527  +|   4032: 63 63 2d 35 2e 34 2e 30 20 32 30 31 36 30 36 30   cc-5.4.0 2016060
         4528  +| page 5 offset 16384
         4529  +|      0: 0d 00 00 00 02 0b a0 00 0c ad 0b a0 00 00 00 00   ................
         4530  +|   2976: 82 0a 02 08 08 09 08 08 17 84 06 30 20 32 34 33   ...........0 243
         4531  +|   2992: 00 01 30 04 25 06 1b 00 00 08 32 30 31 36 30 36   ..0.%.....201606
         4532  +|   3008: 30 39 03 25 07 00 00 01 34 03 25 05 00 00 01 35   09.%....4.%....5
         4533  +|   3024: 03 25 04 00 01 07 30 30 30 30 30 30 30 03 25 1a   .%....0000000.%.
         4534  +|   3040: 00 00 08 63 6f 6d 70 69 6c 65 72 03 25 02 00 00   ...compiler.%...
         4535  +|   3056: 06 64 62 73 74 51 74 03 25 0a 00 01 04 65 62 75   .dbstQt.%....ebu
         4536  +|   3072: 67 03 25 08 00 00 06 65 6e 61 62 6c 65 09 25 09   g.%....enable.%.
         4537  +|   3088: 05 04 04 04 04 04 00 01 08 78 74 65 6e 73 69 6f   .........xtensio
         4538  +|   3104: 6e 03 25 1d 00 00 04 66 74 73 34 03 25 0d 00 03   n.%....fts4.%...
         4539  +|   3120: 01 35 03 25 0f 00 00 03 67 63 63 03 25 03 00 01   .5.%....gcc.%...
         4540  +|   3136: 06 65 6f 70 6f 6c 79 03 25 11 00 00 05 6a 73 6f   .eopoly.%....jso
         4541  +|   3152: 6e 31 03 25 13 00 00 04 6c 6f 61 64 03 25 1c 00   n1.%....load.%..
         4542  +|   3168: 00 03 6d 61 78 03 25 18 00 01 05 65 6d 6f 72 79   ..max.%....emory
         4543  +|   3184: 03 25 19 00 03 04 73 79 73 35 03 25 15 00 00 04   .%....sys5.%....
         4544  +|   3200: 6f 6d 69 74 03 25 1b 00 00 05 72 74 72 65 65 03   omit.%....rtree.
         4545  +|   3216: 25 17 00 00 0a 74 68 72 65 61 64 73 61 66 65 03   %....threadsafe.
         4546  +|   3232: 25 1e 00 00 04 76 74 61 62 03 25 0b 00 86 50 01   %....vtab.%...P.
         4547  +|   3248: 08 08 08 08 08 17 8d 12 30 20 38 33 35 00 01 30   ........0 835..0
         4548  +|   3264: 12 01 06 00 01 06 00 01 06 00 1e f3 00 01 03 00   ................
         4549  +|   3280: 01 03 00 00 08 32 30 31 36 30 36 30 39 09 01 07   .....20160609...
         4550  +|   3296: 00 01 07 00 01 07 00 00 01 34 09 01 05 00 01 05   .........4......
         4551  +|   3312: 00 01 05 00 00 01 35 09 01 04 00 01 04 00 01 04   ......5.........
         4552  +|   3328: 00 01 07 30 30 30 30 2f 30 30 09 1c 04 00 01 04   ...0000/00......
         4553  +|   3344: 00 01 04 00 00 06 62 69 6e 61 72 79 3c 03 01 02   ......binary<...
         4554  +|   3360: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         4555  +|   3376: 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00   ................
         4556  +|   3392: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03   ................
         4557  +|   3408: 01 02 02 00 03 01 02 02 00 00 08 63 6f 6d 70 69   ...........compi
         4558  +|   3424: 6c 65 72 09 01 02 00 01 02 00 01 02 00 00 06 64   ler............d
         4559  +|   3440: 62 73 74 61 74 09 07 03 00 01 03 00 01 03 00 01   bstat...........
         4560  +|   3456: 04 65 62 75 67 09 04 02 00 01 02 00 01 02 00 00   .ebug...........
         4561  +|   3472: 06 65 6e 61 62 6c 65 3f 07 02 00 01 02 00 01 02   .enable?........
         4562  +|   3488: 00 01 02 00 01 02 00 01 01 f0 01 02 00 57 02 00   .............W..
         4563  +|   3504: 01 02 00 01 02 00 01 02 00 01 02 00 01 02 10 01   ................
         4564  +|   3520: 02 00 01 02 00 01 02 00 01 02 00 01 02 00 01 02   ................
         4565  +|   3536: 00 00 02 00 01 02 00 01 08 78 74 65 6e 73 69 6f   .........xtensio
         4566  +|   3552: 6e 09 1f 04 00 01 04 00 01 04 00 00 04 66 74 73   n............fts
         4567  +|   3568: 34 09 0a 03 00 01 03 00 01 03 00 03 01 35 09 0d   4............5..
         4568  +|   3584: 03 00 01 03 00 a9 03 00 00 03 67 63 63 09 01 03   ..........gcc...
         4569  +|   3600: 00 01 03 00 01 03 00 01 06 65 6f 70 6f 6c 79 09   .........eopoly.
         4570  +|   3616: 10 03 00 01 03 00 01 03 00 00 05 6a 73 6f 6e 31   ...........json1
         4571  +|   3632: 09 13 03 00 01 03 00 01 03 00 00 04 6c 6f 61 64   ............load
         4572  +|   3648: 09 1f 03 00 01 03 00 01 03 00 00 03 6d 61 78 09   ............max.
         4573  +|   3664: 1c 02 0b 31 02 00 01 02 00 01 05 65 6d 6f 72 79   ...1.......emory
         4574  +|   3680: 09 1c 03 00 01 03 00 01 03 00 03 04 73 79 73 35   ............sys5
         4575  +|   3696: 09 16 03 00 01 03 00 01 03 00 00 06 6e 6f 63 61   ............noca
         4576  +|   3712: 73 65 3c 02 01 02 02 00 03 01 02 02 00 03 01 02   se<.............
         4577  +|   3728: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         4578  +|   3744: 00 03 01 02 02 00 f3 01 02 02 00 03 01 02 02 00   ................
         4579  +|   3760: 03 01 02 02 00 03 01 02 02 00 03 01 02 02 00 00   ................
         4580  +|   3776: 04 6f 6d 69 74 09 1f 02 00 01 02 00 01 02 00 00   .omit...........
         4581  +|   3792: 05 72 74 72 65 65 09 19 03 00 01 03 00 01 03 00   .rtree..........
         4582  +|   3808: 03 02 69 6d 3c 01 01 02 02 00 03 01 02 02 00 03   ..im<...........
         4583  +|   3824: 01 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01   ................
         4584  +|   3840: 02 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02   ................
         4585  +|   3856: 02 00 03 01 02 02 00 03 01 02 02 00 03 01 02 02   ................
         4586  +|   3872: 00 00 0a 74 68 72 65 61 64 63 61 66 65 09 22 02   ...threadcafe...
         4587  +|   3888: 00 01 02 00 02 02 00 00 04 76 74 61 62 09 07 04   .........vtab...
         4588  +|   3904: 00 01 04 00 01 04 00 00 01 78 b4 01 01 01 01 02   .........x......
         4589  +|   3920: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         4590  +|   3936: 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01   ................
         4591  +|   3952: 01 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01   ................
         4592  +|   3968: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01   ................
         4593  +|   3984: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02   ................
         4594  +|   4000: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         4595  +|   4016: 01 01 01 02 00 01 01 01 02 00 01 00 01 02 00 01   ................
         4596  +|   4032: 01 01 02 00 01 01 00 e2 00 01 01 01 02 00 01 01   ................
         4597  +|   4048: 01 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01   ................
         4598  +|   4064: 02 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02   ................
         4599  +|   4080: 00 01 01 01 02 00 01 01 01 02 00 01 01 01 02 00   ................
         4600  +| page 6 offset 20480
         4601  +|      0: 0a 00 00 00 02 0f f5 00 0f fb 0f f5 00 00 00 00   ................
         4602  +|   4080: 00 00 00 00 00 05 04 08 09 01 02 04 04 08 08 09   ................
         4603  +| page 7 offset 24576
         4604  +|      0: 0d 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
         4605  +|   4016: 00 00 00 00 00 00 00 00 0d 05 02 23 61 00 00 00   ...........#a...
         4606  +| end crash-26682721375870.db
         4607  +}]} {}
         4608  +
         4609  +do_execsql_test 26.1 {
         4610  +  SELECT count(*) FROM (
         4611  +    SELECT t1, (t1) FROM t1 WHERE b MATCH 'x'
         4612  +  )
         4613  +} 34
  4403   4614    
  4404   4615   finish_test
  4405   4616   

Added test/fts3corrupt5.test.

            1  +# 2019 May 22
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#*************************************************************************
           11  +#
           12  +#
           13  +
           14  +set testdir [file dirname $argv0]
           15  +source $testdir/tester.tcl
           16  +source $testdir/fts3_common.tcl
           17  +set testprefix fts3corrupt5
           18  +
           19  +# If SQLITE_ENABLE_FTS3 is defined, omit this file.
           20  +ifcapable !fts3 {
           21  +  finish_test
           22  +  return
           23  +}
           24  +
           25  +sqlite3_fts3_may_be_corrupt 1
           26  +
           27  +do_execsql_test 1.0 {
           28  +  BEGIN;
           29  +    CREATE VIRTUAL TABLE ft USING fts3(a, b, c);
           30  +    INSERT INTO ft VALUES('one', 'one', 'one');
           31  +  COMMIT;
           32  +}
           33  +
           34  +do_execsql_test 1.1 {
           35  +  SELECT * FROM ft WHERE ft MATCH 'b:one'
           36  +} {one one one}
           37  +
           38  +do_execsql_test 1.2 {
           39  +  SELECT quote(root) FROM ft_segdir;
           40  +} {X'00036F6E6509010201010201020200'}
           41  +
           42  +breakpoint
           43  +foreach {tn val q bCorrupt} {
           44  +  1 X'00036F6E650901'                   'b:one'  1
           45  +  2 X'00036F6E6509010201010201FFFFFF'   'c:one'  1
           46  +  3 X'00036F6E6501'                     'b:one'  1
           47  +  4 X'00036F6E650101'                   'b:one'  1
           48  +  5 X'00036F6E650100'                   'b:one'  0
           49  +} {
           50  +  do_execsql_test 1.3.$tn.1 "UPDATE ft_segdir SET root = $val"
           51  +
           52  +  set res {0 {}}
           53  +  if {$bCorrupt} { set res {1 {database disk image is malformed}}}
           54  +  do_catchsql_test 1.3.$tn.2 {
           55  +    SELECT * FROM ft WHERE ft MATCH $q
           56  +  } $res
           57  +}
           58  +
           59  +finish_test
           60  +