/ Check-in [edb095a9]
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 two assert() statements in fts5 that are only true if the database is not corrupt.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: edb095a9a679c8c702abd0a487e55ed4b09110b54bcd7d5275020576f2713a39
User & Date: dan 2019-04-06 15:38:46
Context
2019-04-07
18:04
Fix a faulty assert() in the sqlite3VdbeMemExpandBlob() routine. check-in: df58774e user: drh tags: trunk
2019-04-06
15:38
Fix two assert() statements in fts5 that are only true if the database is not corrupt. check-in: edb095a9 user: dan tags: trunk
2019-04-05
21:17
Remove some stale references to the addopcodes.tcl script from documentation. check-in: c0381b0b user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ext/fts5/fts5_index.c.

2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
  if( p1->pLeaf==0 ){           /* If p1 is at EOF */
    iRes = i2;
  }else if( p2->pLeaf==0 ){     /* If p2 is at EOF */
    iRes = i1;
  }else{
    int res = fts5BufferCompare(&p1->term, &p2->term);
    if( res==0 ){
      assert( i2>i1 );
      assert( i2!=0 );
      pRes->bTermEq = 1;
      if( p1->iRowid==p2->iRowid ){
        p1->bDel = p2->bDel;
        return i2;
      }
      res = ((p1->iRowid > p2->iRowid)==pIter->bRev) ? -1 : +1;
    }







|
|







2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
  if( p1->pLeaf==0 ){           /* If p1 is at EOF */
    iRes = i2;
  }else if( p2->pLeaf==0 ){     /* If p2 is at EOF */
    iRes = i1;
  }else{
    int res = fts5BufferCompare(&p1->term, &p2->term);
    if( res==0 ){
      assert_nc( i2>i1 );
      assert_nc( i2!=0 );
      pRes->bTermEq = 1;
      if( p1->iRowid==p2->iRowid ){
        p1->bDel = p2->bDel;
        return i2;
      }
      res = ((p1->iRowid > p2->iRowid)==pIter->bRev) ? -1 : +1;
    }

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

7994
7995
7996
7997
7998
7999
8000
8001























































































































8002
8003
8004
| end crash-2acc487d09f033.db
}]} {}

do_catchsql_test 56.1 {
  INSERT INTO t1(b) VALUES(randomblob(250));
  INSERT INTO t1(b) VALUES(randomblob(250));
} {1 {database disk image is malformed}}
























































































































sqlite3_fts5_may_be_corrupt 0
finish_test









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
| end crash-2acc487d09f033.db
}]} {}

do_catchsql_test 56.1 {
  INSERT INTO t1(b) VALUES(randomblob(250));
  INSERT INTO t1(b) VALUES(randomblob(250));
} {1 {database disk image is malformed}}

#-------------------------------------------------------------------------
reset_db
do_test 57.0 {
  sqlite3 db {}
  db deserialize [decode_hexdb {
| size 28672 pagesize 4096 filename x.db
| page 1 offset 0
|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
|     16: 10 00 01 01 00 40 20 20 00 00 00 01 00 00 00 07   .....@  ........
|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01   ................
|     96: 00 2e 34 20 0d 00 00 00 07 0d d2 00 0f c4 0f 6d   ..4 ...........m
|    112: 0f 02 0e ab 0e 4e 0d f6 0d d2 00 00 00 00 00 00   .....N..........
|   3536: 00 00 22 07 06 17 11 11 01 31 74 61 62 6c 65 74   .........1tablet
|   3552: 32 74 32 07 43 52 45 41 54 45 20 54 41 42 4c 45   2t2.CREATE TABLE
|   3568: 20 74 32 28 78 29 56 06 06 17 1f 1f 01 7d 74 61    t2(x)V.......ta
|   3584: 61 6b 65 74 31 5f 63 6f 6e 66 69 67 74 31 5f 63   aket1_configt1_c
|   3600: 6f 7e 66 69 67 06 43 52 45 41 54 45 20 54 41 42   o~fig.CREATE TAB
|   3616: 4c 45 20 27 74 31 5f 63 6f 6e 66 69 67 27 28 6b   LE 't1_config'(k
|   3632: 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 76 29    PRIMARY KEY, v)
|   3648: 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44 5b 05    WITHOUT ROWID[.
|   3664: 07 17 21 21 01 81 01 74 61 62 6c 65 74 31 5f 64   ..!!...tablet1_d
|   3680: 6f 63 73 69 7a 65 74 31 5f 64 6f 63 73 69 7a 65   ocsizet1_docsize
|   3696: 05 43 52 45 41 54 45 20 54 41 42 4c 45 20 27 74   .CREATE TABLE 't
|   3712: 31 5f 64 6f 63 73 69 7a 65 27 28 69 64 20 49 4e   1_docsize'(id IN
|   3728: 54 45 47 45 52 20 50 52 49 4d 41 52 59 20 4b 45   TEGER PRIMARY KE
|   3744: 59 2c 20 73 7a 20 42 4c 4f 42 29 55 04 06 17 21   Y, sz BLOB)U...!
|   3760: 21 01 77 74 61 62 6c 65 74 31 5f 63 6f 6e 74 1d   !.wtablet1_cont.
|   3776: 6e 74 74 31 5f 63 6f 6e 74 65 6e 74 04 43 52 45   ntt1_content.CRE
|   3792: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 63 6f   ATE TABLE 't1_co
|   3808: 6e 74 65 6e 74 27 28 69 64 20 49 4e 54 45 47 45   ntent'(id INTEGE
|   3824: 52 20 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 63   R PRIMARY KEY, c
|   3840: 30 29 69 03 07 17 19 19 01 81 2d 74 61 62 6c 65   0)i.......-table
|   3856: 74 31 5f 69 64 78 74 31 5f 59 64 78 03 43 52 45   t1_idxt1_Ydx.CRE
|   3872: 41 54 45 20 54 41 42 4c 45 20 27 74 31 5f 69 64   ATE TABLE 't1_id
|   3888: 78 27 28 73 65 67 69 64 2c 20 74 65 72 6d 2c 20   x'(segid, term, 
|   3904: 70 67 6e 6f 2c 20 50 52 49 4d 41 52 59 20 4b 45   pgno, PRIMARY KE
|   3920: 59 28 73 65 67 69 64 2c 20 74 65 72 6d 29 29 20   Y(segid, term)) 
|   3936: 57 49 54 48 4f 55 54 20 52 4f 57 49 44 55 02 07   WITHOUT ROWIDU..
|   3952: 17 1b 1b 01 81 01 74 61 62 6c 65 74 31 5f 64 61   ......tablet1_da
|   3968: 74 61 74 31 5f 64 61 64 61 02 43 52 45 41 54 45   tat1_dada.CREATE
|   3984: 20 54 41 42 4c 45 20 27 74 31 5f 64 61 74 61 27    TABLE 't1_data'
|   4000: 28 69 64 20 49 4e 54 45 47 45 52 20 50 52 49 4d   (id INTEGER PRIM
|   4016: 41 52 59 20 4b 45 59 2c 20 62 6c 6f 63 6b 20 42   ARY KEY, block B
|   4032: 4c 4f 42 29 3a 01 06 17 11 11 08 63 74 61 62 6c   LOB):......ctabl
|   4048: 65 74 31 74 31 43 52 45 41 54 45 20 56 49 52 54   et1t1CREATE VIRT
|   4064: 55 41 4c 20 54 41 42 4c 45 20 74 31 20 55 53 49   UAL TABLE t1 USI
|   4080: 4e 47 20 66 74 73 35 28 63 6f 6e 74 65 6e 74 29   NG fts5(content)
| page 2 offset 4096
|      0: 0d 0e b4 00 06 0e 35 00 0f e8 0e 35 0f bd 0f 4e   ......5....5...N
|     16: 0e cb 0e 4f 00 00 00 00 00 00 00 00 00 00 00 00   ...O............
|   3632: 00 00 00 00 00 18 0a 03 00 36 00 00 00 00 01 04   .........6......
|   3648: 04 00 04 01 01 01 02 01 01 03 01 01 04 01 01 5e   ...............^
|   3664: 90 80 80 80 80 01 04 00 81 40 00 00 00 51 06 30   .........@...Q.0
|   3680: 61 62 61 63 6b 01 01 04 04 6e 64 6f 6e 01 01 02   aback....ndon...
|   3696: 04 63 69 76 65 01 01 02 04 6c 70 68 61 01 01 02   .cive....lpha...
|   3712: 03 74 6f 6d 01 01 01 06 62 61 63 6b 75 70 01 01   .tom....backup..
|   3728: 02 05 6f 6f 6d 65 72 01 01 01 06 63 68 61 6e 6e   ..oomer....chann
|   3744: 65 01 01 01 04 74 65 73 74 01 01 04 09 08 08 08   e....test.......
|   3760: 07 0a 09 0a 0f 3a 00 17 30 00 00 00 00 01 03 03   .....:..0.......
|   3776: 00 03 01 01 01 02 01 01 03 01 01 68 8c 80 80 80   ...........h....
|   3792: 80 01 04 00 81 54 00 00 00 5b 06 30 61 62 61 63   .....T...[.0abac
|   3808: 6b 02 02 07 04 04 6e 64 6f 6e 02 02 05 02 04 63   k.....ndon.....c
|   3824: 69 76 65 02 02 0b 02 04 6c 70 68 61 02 04 02 0a   ive.....lpha....
|   3840: 02 03 74 6f 6d 02 02 09 01 06 62 61 63 6b 75 70   ..tom.....backup
|   3856: 02 02 04 02 05 6f 6f 6d 65 72 02 02 08 01 06 63   .....oomer.....c
|   3872: 68 61 6e 6e 65 02 02 03 01 04 74 65 73 74 02 02   hanne.....test..
|   3888: 06 04 0a 09 09 0a 08 0b 0a 0b 0f ef 00 14 2a 00   ..............*.
|   3904: 00 00 00 01 02 02 00 02 01 01 01 02 01 01 68 88   ..............h.
|   3920: 80 80 80 80 01 04 00 81 54 00 00 00 5b 06 30 61   ........T...[.0a
|   3936: 62 61 63 6b 01 02 07 04 04 6e 64 6f 6e 01 02 05   back.....ndon...
|   3952: 02 04 63 69 76 65 01 02 0b 02 04 6c 70 68 61 01   ..cive.....lpha.
|   3968: 04 02 0a 02 03 74 6f 6d 01 02 09 01 06 62 61 63   .....tom.....bac
|   3984: 6b 75 70 01 02 04 02 05 6f 6f 6d 65 72 01 02 08   kup.....oomer...
|   4000: 01 06 63 68 61 6e 6e 65 01 02 03 01 04 74 65 73   ..channe.....tes
|   4016: 74 01 02 06 04 0a 09 09 0a 08 0b 0a 0b 24 84 80   t............$..
|   4032: 80 80 80 01 03 00 4e 00 00 00 1e 06 30 61 62 61   ......N.....0aba
|   4048: 63 6b 01 02 02 05 42 66 74 02 02 02 04 04 6e 64   ck....Bft.....nd
|   4064: 6f 6e 03 02 02 04 0a 07 05 01 03 00 10 04 0d 00   on..............
|   4080: 00 00 11 24 00 00 00 00 01 01 01 00 01 01 01 01   ...$............
| page 3 offset 8192
|      0: 0a 00 00 00 04 0f e5 00 00 00 0f f3 0f ec 0f e5   ................
|   4064: 00 00 00 00 00 06 04 01 0c 01 04 02 06 04 01 0c   ................
|   4080: 01 03 02 06 04 01 0c 01 02 02 05 04 09 0d 01 02   ................
| page 4 offset 12288
|      0: 0d 0e bc 00 04 0e 78 00 00 00 00 00 00 00 0e 78   ......x........x
|     16: 0e 78 00 00 00 00 00 00 00 00 00 00 00 00 00 00   .x..............
|   3696: 00 00 00 00 00 00 00 00 42 02 04 00 81 09 61 6c   ........B.....al
|   3712: 70 68 61 20 63 68 61 6e 6e 65 20 62 61 63 6b 75   pha channe backu
|   3728: 70 20 61 62 61 6e 64 6f 6e 20 74 65 73 74 20 61   p abandon test a
|   3744: 62 61 63 6b 20 62 6f 6f 6d 65 72 20 61 74 6f 6d   back boomer atom
|   3760: 20 61 6c 70 68 61 20 61 63 69 76 65 00 00 00 44    alpha acive...D
|   3776: 81 09 61 6c 70 68 61 20 63 68 61 6e 6e 65 20 62   ..alpha channe b
|   3792: 61 63 6b 75 70 20 61 62 61 6e 64 6f 6e 20 74 65   ackup abandon te
|   3808: 73 74 20 61 62 61 63 6b 20 62 6f 6f 6d 65 72 20   st aback boomer 
|   3824: 61 74 6f 6d 20 61 6c 70 68 61 20 61 63 69 76 65   atom alpha acive
|   4064: 0a 03 03 00 1b 61 4e 61 6e 64 6f 6e 08 02 03 00   .....aNandon....
|   4080: 17 61 62 61 66 74 08 01 03 00 17 61 62 71 63 6b   .abaft.....abqck
| page 5 offset 16384
|      0: 0d 0f e8 00 04 0f e2 00 00 00 00 00 00 00 0f e2   ................
|     16: 0f e2 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
|   4064: 00 00 04 02 03 00 0e 0a 00 00 00 06 0e 0a 04 03   ................
|   4080: 03 00 0e 01 04 02 03 00 0e 01 04 01 03 10 0e 01   ................
| page 6 offset 20480
|      0: 0a 00 00 00 01 0f f4 00 0f f4 00 00 00 00 00 00   ................
|   4080: 00 00 00 00 0b 03 1b 01 76 65 72 73 69 6f 6e 04   ........version.
| page 7 offset 24576
|      0: 0d 00 00 00 03 0f d6 00 0f f4 00 00 00 00 00 00   ................
|   4048: 00 00 00 00 00 00 09 03 02 1b 72 65 62 75 69 6c   ..........rebuil
|   4064: 64 11 02 02 2b 69 6e 74 65 67 72 69 74 79 2d 63   d...+integrity-c
|   4080: 68 65 63 6b 0a 01 02 1d 6f 70 74 69 6d 69 7a 65   heck....optimize
| end x.db
}]} {}

do_catchsql_test 57.1 {
  INSERT INTO t1(t1) VALUES('optimize')
} {1 {database disk image is malformed}}


sqlite3_fts5_may_be_corrupt 0
finish_test