/ Check-in [dfac6082]
Login

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

Overview
Comment:Fix bug in fts2 handling of OR queries. When one doclist ends before the other, the code potentially tries to read past the end of the doclist. http://www.sqlite.org/cvstrac/tktview?tn=2309 (CVS 3862)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: dfac6082e8ffc52a85c4906107a7fc0e1aa9df82
User & Date: shess 2007-04-19 18:36:32
Context
2007-04-20
12:22
Remove the ARRAYSIZE macro from where.c to avoid a name conflict with microsoft header files. Ticket #2311 (CVS 3863) check-in: 9389a15f user: drh tags: trunk
2007-04-19
18:36
Fix bug in fts2 handling of OR queries. When one doclist ends before the other, the code potentially tries to read past the end of the doclist. http://www.sqlite.org/cvstrac/tktview?tn=2309 (CVS 3862) check-in: dfac6082 user: shess tags: trunk
14:48
Better fix than (3860) for the same problem. (3860) could leave file-handles open in some circumstances. (CVS 3861) check-in: 5ad64533 user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to ext/fts2/fts2.c.

  1370   1370     }
  1371   1371   
  1372   1372     dlrInit(&left, DL_DOCIDS, pLeft, nLeft);
  1373   1373     dlrInit(&right, DL_DOCIDS, pRight, nRight);
  1374   1374     dlwInit(&writer, DL_DOCIDS, pOut);
  1375   1375   
  1376   1376     while( !dlrAtEnd(&left) || !dlrAtEnd(&right) ){
  1377         -    if( dlrAtEnd(&right) || dlrDocid(&left)<dlrDocid(&right) ){
         1377  +    if( dlrAtEnd(&right) ){
         1378  +      dlwAdd(&writer, dlrDocid(&left));
         1379  +      dlrStep(&left);
         1380  +    }else if( dlrAtEnd(&left) ){
         1381  +      dlwAdd(&writer, dlrDocid(&right));
         1382  +      dlrStep(&right);
         1383  +    }else if( dlrDocid(&left)<dlrDocid(&right) ){
  1378   1384         dlwAdd(&writer, dlrDocid(&left));
  1379   1385         dlrStep(&left);
  1380         -    }else if( dlrAtEnd(&left) || dlrDocid(&right)<dlrDocid(&left) ){
         1386  +    }else if( dlrDocid(&right)<dlrDocid(&left) ){
  1381   1387         dlwAdd(&writer, dlrDocid(&right));
  1382   1388         dlrStep(&right);
  1383   1389       }else{
  1384   1390         dlwAdd(&writer, dlrDocid(&left));
  1385   1391         dlrStep(&left);
  1386   1392         dlrStep(&right);
  1387   1393       }

Changes to test/fts2g.test.

     3      3   # The author disclaims copyright to this source code.
     4      4   #
     5      5   #*************************************************************************
     6      6   # This file implements regression tests for SQLite library.  The focus
     7      7   # of this script is testing handling of edge cases for various doclist
     8      8   # merging functions in the FTS2 module query logic.
     9      9   #
    10         -# $Id: fts2g.test,v 1.1 2006/10/25 20:27:40 shess Exp $
           10  +# $Id: fts2g.test,v 1.2 2007/04/19 18:36:32 shess Exp $
    11     11   #
    12     12   
    13     13   set testdir [file dirname $argv0]
    14     14   source $testdir/tester.tcl
    15     15   
    16     16   # If SQLITE_ENABLE_FTS2 is defined, omit this file.
    17     17   ifcapable !fts2 {
................................................................................
    18     18     finish_test
    19     19     return
    20     20   }
    21     21   
    22     22   db eval {
    23     23     CREATE VIRTUAL TABLE t1 USING fts2(content);
    24     24     INSERT INTO t1 (rowid, content) VALUES(1, 'this is a test');
           25  +  INSERT INTO t1 (rowid, content) VALUES(2, 'also a test');
    25     26   }
    26     27   
    27     28   # No hits at all.  Returns empty doclists from termSelect().
    28     29   do_test fts2g-1.1 {
    29     30     execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'something'}
    30     31   } {}
    31     32   
................................................................................
    69     70     execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'this something'}
    70     71   } {}
    71     72   
    72     73   # No support for all-except queries.
    73     74   do_test fts2g-1.10 {
    74     75     catchsql {SELECT rowid FROM t1 WHERE t1 MATCH '-this -something'}
    75     76   } {1 {SQL logic error or missing database}}
           77  +
           78  +# Test that docListOrMerge() correctly handles reaching the end of one
           79  +# doclist before it reaches the end of the other.
           80  +do_test fts2g-1.11 {
           81  +  execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'this OR also'}
           82  +} {1 2}
           83  +do_test fts2g-1.12 {
           84  +  execsql {SELECT rowid FROM t1 WHERE t1 MATCH 'also OR this'}
           85  +} {1 2}
    76     86   
    77     87   finish_test