/ Check-in [72ac7318]
Login

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

Overview
Comment:Fix an off-by-one in the code for limiting the depth of FTS expression trees.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 72ac73189c3577740a77d2ea2fc7118391c0703f
User & Date: dan 2013-04-29 17:12:06
Context
2013-04-29
18:07
Improve the error message issued when an FTS query exceeds the maximum allowable tree depth. check-in: f480b1fe user: dan tags: trunk
17:12
Fix an off-by-one in the code for limiting the depth of FTS expression trees. check-in: 72ac7318 user: dan tags: trunk
09:17
Fix mmap1.test so that it passes on windows as well as unix. check-in: 52417eac user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/fts3/fts3_expr.c.

   751    751   /*
   752    752   ** Return SQLITE_ERROR if the maximum depth of the expression tree passed 
   753    753   ** as the only argument is more than nMaxDepth.
   754    754   */
   755    755   static int fts3ExprCheckDepth(Fts3Expr *p, int nMaxDepth){
   756    756     int rc = SQLITE_OK;
   757    757     if( p ){
   758         -    if( nMaxDepth==0 ){ 
          758  +    if( nMaxDepth<0 ){ 
   759    759         rc = SQLITE_ERROR;
   760    760       }else{
   761    761         rc = fts3ExprCheckDepth(p->pLeft, nMaxDepth-1);
   762    762         if( rc==SQLITE_OK ){
   763    763           rc = fts3ExprCheckDepth(p->pRight, nMaxDepth-1);
   764    764         }
   765    765       }

Changes to test/fts3expr3.test.

   145    145     do_test 3.$i {
   146    146       test_fts3expr2 "[random_and_query $i 1] OR [random_and_query $i 1]"
   147    147     } [list OR [balanced_and_tree $i] [balanced_and_tree $i]]
   148    148   }
   149    149   
   150    150   # Try trees of AND nodes with leaves that are themselves trees of OR nodes.
   151    151   #
   152         -for {set i 2} {$i < 32} {incr i} {
          152  +for {set i 2} {$i < 64} {incr i 4} {
   153    153     do_test 3.$i {
   154    154       test_fts3expr2 [random_andor_query $i]
   155    155     } [balanced_andor_tree $i]
   156    156   }
   157    157   
   158    158   # These exceed the depth limit. 
   159    159   #
   160         -for {set i 33} {$i < 40} {incr i} {
          160  +for {set i 65} {$i < 70} {incr i} {
   161    161     do_test 3.$i {
   162    162       list [catch {test_fts3expr2 [random_andor_query $i]} msg] $msg
   163    163     } {1 {Error parsing expression}}
   164    164   }
   165    165   
   166    166   # This also exceeds the depth limit. 
   167    167   #
   168         -do_test 4.1 {
          168  +
          169  +do_test 4.1.1 {
   169    170     set q "1"
   170    171     for {set i 2} {$i < 5000} {incr i} {
   171    172       append q " AND $i"
   172    173     }
   173    174     list [catch {test_fts3expr2 $q} msg] $msg
   174    175   } {1 {Error parsing expression}}
          176  +do_test 4.1.2 {
          177  +  set q "1"
          178  +  for {set i 2} {$i < 4000} {incr i} {
          179  +    append q " AND $i"
          180  +  }
          181  +  catch {test_fts3expr2 $q}
          182  +} {0}
   175    183   
   176    184   proc create_toggle_tree {nDepth} {
   177    185     if {$nDepth == 0} { return xxx }
   178    186     set nNew [expr $nDepth-1]
   179    187     if {$nDepth % 2} {
   180    188       return "([create_toggle_tree $nNew]) OR ([create_toggle_tree $nNew])"
   181    189     }