/ Check-in [fb17fea4]
Login

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

Overview
Comment:Catch another case of a corrupted structure record in fts5.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:fb17fea4b9779fbd3adb6ff9500da83a6ca4fa7cba379aa70074e4328814a7f2
User & Date: dan 2018-12-22 19:54:17
Context
2018-12-22
20:32
Improve the coverage of wal.c provided by the "coverage-wal" test permutation. check-in: 62314851 user: dan tags: trunk
19:54
Catch another case of a corrupted structure record in fts5. check-in: fb17fea4 user: dan tags: trunk
19:09
Change a faulty assert() in fts5 that could fail on a corrupt db to an if() statement. check-in: 1daaba9f user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5_index.c.

   882    882         }else{
   883    883           i += fts5GetVarint32(&pData[i], pLvl->nMerge);
   884    884           i += fts5GetVarint32(&pData[i], nTotal);
   885    885           if( nTotal<pLvl->nMerge ) rc = FTS5_CORRUPT;
   886    886           pLvl->aSeg = (Fts5StructureSegment*)sqlite3Fts5MallocZero(&rc, 
   887    887               nTotal * sizeof(Fts5StructureSegment)
   888    888           );
          889  +        nSegment -= nTotal;
   889    890         }
   890    891   
   891    892         if( rc==SQLITE_OK ){
   892    893           pLvl->nSeg = nTotal;
   893    894           for(iSeg=0; iSeg<nTotal; iSeg++){
   894    895             if( i>=nData ){
   895    896               rc = FTS5_CORRUPT;
................................................................................
   897    898             }
   898    899             i += fts5GetVarint32(&pData[i], pLvl->aSeg[iSeg].iSegid);
   899    900             i += fts5GetVarint32(&pData[i], pLvl->aSeg[iSeg].pgnoFirst);
   900    901             i += fts5GetVarint32(&pData[i], pLvl->aSeg[iSeg].pgnoLast);
   901    902           }
   902    903         }
   903    904       }
          905  +    if( nSegment!=0 && rc==SQLITE_OK ) rc = FTS5_CORRUPT;
          906  +
   904    907       if( rc!=SQLITE_OK ){
   905    908         fts5StructureRelease(pRet);
   906    909         pRet = 0;
   907    910       }
   908    911     }
   909    912   
   910    913     *ppOut = pRet;

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

   684    684   do_catchsql_test 11.1 {
   685    685     SELECT * FROM t1 WHERE t1 MATCH 'abandon';
   686    686   } {1 {vtable constructor failed: t1}}
   687    687   
   688    688   do_catchsql_test 11.2 {
   689    689     INSERT INTO t1(t1, rank) VALUES('merge', 500);
   690    690   } {1 {vtable constructor failed: t1}}
          691  +
          692  +#-------------------------------------------------------------------------
          693  +#
          694  +reset_db
          695  +do_test 13.0 {
          696  +  sqlite3 db {}
          697  +  db deserialize [decode_hexdb {
          698  +| size 28672 pagesize 4096 filename c13.db
          699  +| page 1 offset 0
          700  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          701  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
          702  +|     32: 00 00 00 00 00 00 00 00 00 00 00 07 00 00 00 04   ................
          703  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
          704  +|     96: 00 00 00 00 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ...............m
          705  +|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
          706  +|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
          707  +|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
          708  +|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
          709  +|   3584: 62 6c 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   blet1_configt1_c
          710  +|   3600: 6f 6e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   onfig.CREATE TAB
          711  +|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
          712  +|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
          713  +|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
          714  +|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
          715  +|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
          716  +|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
          717  +|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
          718  +|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
          719  +|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
          720  +|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 65   !.wtablet1_conte
          721  +|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
          722  +|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
          723  +|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
          724  +|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
          725  +|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
          726  +|   3856: 74 31 5f 69 64 78 74 31 5f 69 64 78 03 43 52 45   t1_idxt1_idx.CRE
          727  +|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 4f 69 64   ATE TABLE 't1Oid
          728  +|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
          729  +|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
          730  +|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
          731  +|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
          732  +|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
          733  +|   3968: 74 61 74 31 5f 64 61 74 61 02 43 52 45 41 54 45   tat1_data.CREATE
          734  +|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
          735  +|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
          736  +|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
          737  +|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
          738  +|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
          739  +|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
          740  +|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
          741  +| page 2 offset 4096
          742  +|      0: 0d 00 00 00 03 0f bd 00 0f e8 0f ef 0f bd 00 00   ................
          743  +|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 24 84 80   .............$..
          744  +|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
          745  +|   4048: 63 6b 01 02 02 04 02 66 74 02 02 02 04 04 6e 64   ck.....ft.....nd
          746  +|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 03 03 0f   on..............
          747  +|   4080: 0a 03 00 24 00 eb 00 00 00 01 01 01 00 01 01 01   ...$............
          748  +| page 3 offset 8192
          749  +|      0: 01 0a 00 00 00 01 0f fa 00 0f fa 00 00 00 00 00   ................
          750  +|   4080: 00 00 00 00 00 00 00 00 00 00 05 04 09 0c 01 02   ................
          751  +| page 4 offset 12288
          752  +|      0: 0d 00 00 00 03 0f e0 00 0f f6 0f ec 0f e0 00 00   ................
          753  +|   4064: 0a 03 03 00 1b 61 62 61 6e 64 6f 6e 08 02 03 00   .....abandon....
          754  +|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 61 63 6b   .abaft.....aback
          755  +| page 5 offset 16384
          756  +|      0: 0d 00 00 00 03 0f ee 00 0f fa 0f f2 0f ee 00 00   ................
          757  +|   4064: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 03   ................
          758  +|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 00 0e 01   ................
          759  +| page 6 offset 20480
          760  +|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
          761  +|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
          762  +| page 7 offset 24576
          763  +|      0: 0d 00 00 00 03 0f d6 00 0f f4 0f e1 0f d6 00 00   ................
          764  +|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
          765  +|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
          766  +|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
          767  +| end c13.db
          768  +SELECT * FROM t1 WHERE t1 MATCH 'abandon';
          769  +}]} {}
          770  +
          771  +do_catchsql_test 14.1 {
          772  +  SELECT * FROM t1 WHERE t1 MATCH 'abandon'; 
          773  +} {1 {vtable constructor failed: t1}}
   691    774   
   692    775   sqlite3_fts5_may_be_corrupt 0
   693    776   finish_test
   694    777