From 624edacf6a0a08f7538d7593f146287f62c959be Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 17 Apr 2017 16:07:25 +0000 Subject: [PATCH] Further improvements to test coverage in fts3. FossilOrigin-Name: 352413eed469802665e7d2c17b7fe6e3a0b0b2209ce45bdc85fd4243cec50ea6 --- ext/fts3/fts3.c | 13 +++-- manifest | 23 ++++---- manifest.uuid | 2 +- test/fts3aa.test | 1 - test/fts3corrupt3.test | 23 ++++++++ test/fts3fault2.test | 18 ++++++ test/fts3misc.test | 124 +++++++++++++++++++++++++++++++++++++++++ test/permutations.test | 1 + 8 files changed, 187 insertions(+), 18 deletions(-) create mode 100644 test/fts3misc.test diff --git a/ext/fts3/fts3.c b/ext/fts3/fts3.c index 40ce6ec27a..9cafd8e591 100644 --- a/ext/fts3/fts3.c +++ b/ext/fts3/fts3.c @@ -372,8 +372,8 @@ int sqlite3Fts3GetVarint(const char *pBuf, sqlite_int64 *v){ } /* -** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to a -** 32-bit integer before it is returned. +** Similar to sqlite3Fts3GetVarint(), except that the output is truncated to +** a non-negative 32-bit integer before it is returned. */ int sqlite3Fts3GetVarint32(const char *p, int *pi){ u32 a; @@ -389,7 +389,9 @@ int sqlite3Fts3GetVarint32(const char *p, int *pi){ GETVARINT_STEP(a, p, 14, 0x3FFF, 0x200000, *pi, 3); GETVARINT_STEP(a, p, 21, 0x1FFFFF, 0x10000000, *pi, 4); a = (a & 0x0FFFFFFF ); - *pi = (int)(a | ((u32)(*p & 0x0F) << 28)); + *pi = (int)(a | ((u32)(*p & 0x07) << 28)); + assert( 0==(a & 0x80000000) ); + assert( *pi>=0 ); return 5; } @@ -1847,7 +1849,8 @@ static int fts3ScanInteriorNode( isFirstTerm = 0; zCsr += fts3GetVarint32(zCsr, &nSuffix); - if( nPrefix<0 || nSuffix<0 || &zCsr[nSuffix]>zEnd ){ + assert( nPrefix>=0 && nSuffix>=0 ); + if( &zCsr[nSuffix]>zEnd ){ rc = FTS_CORRUPT_VTAB; goto finish_scan; } @@ -2657,7 +2660,7 @@ int sqlite3Fts3FirstFilter( fts3ColumnlistCopy(0, &p); } - while( p