/ Check-in [1e8fcb3f]
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:Add cases to fuzz.test. Some tests in this file fail at the moment. (CVS 3973)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1e8fcb3fbed7beb8bb1370953ecf3d4b9db01ede
User & Date: danielk1977 2007-05-10 17:32:48
Context
2007-05-10
17:38
Simplify failing case in fuzz.test. (CVS 3974) check-in: a54c7499 user: danielk1977 tags: trunk
17:32
Add cases to fuzz.test. Some tests in this file fail at the moment. (CVS 3973) check-in: 1e8fcb3f user: danielk1977 tags: trunk
17:23
Add some UTF-8 test infrastructure. Treat NaN as NULL. The printf routines print infinity as "Inf" not as "NaN". Ticket #2345. (CVS 3972) check-in: ffe615a7 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.613 2007/05/10 17:23:12 drh Exp $
           46  +** $Id: vdbe.c,v 1.614 2007/05/10 17:32:48 danielk1977 Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include "os.h"
    50     50   #include <ctype.h>
    51     51   #include <math.h>
    52     52   #include "vdbeInt.h"
    53     53   
................................................................................
   914    914     int i;
   915    915     Mem ts;
   916    916   
   917    917     ts = *pFrom;
   918    918     Deephemeralize(pTos);
   919    919     for(i=0; i<pOp->p1; i++, pFrom++){
   920    920       Deephemeralize(&pFrom[1]);
   921         -    assert( (pFrom->flags & MEM_Ephem)==0 );
          921  +    assert( (pFrom[1].flags & MEM_Ephem)==0 );
   922    922       *pFrom = pFrom[1];
   923    923       if( pFrom->flags & MEM_Short ){
   924    924         assert( pFrom->flags & (MEM_Str|MEM_Blob) );
   925    925         assert( pFrom->z==pFrom[1].zShort );
   926    926         pFrom->z = pFrom->zShort;
   927    927       }
   928    928     }
................................................................................
  2270   2270     for(pRec=pData0; pRec<=pTos; pRec++){
  2271   2271       int len;
  2272   2272       if( zAffinity ){
  2273   2273         applyAffinity(pRec, zAffinity[pRec-pData0], encoding);
  2274   2274       }
  2275   2275       if( pRec->flags&MEM_Null ){
  2276   2276         containsNull = 1;
         2277  +    }
         2278  +    if( pRec->flags&MEM_Zero && pRec->n>0 ){
         2279  +      sqlite3VdbeMemExpandBlob(pRec);
  2277   2280       }
  2278   2281       serial_type = sqlite3VdbeSerialType(pRec, file_format);
  2279   2282       len = sqlite3VdbeSerialTypeLen(serial_type);
  2280   2283       nData += len;
  2281   2284       nHdr += sqlite3VarintLen(serial_type);
  2282   2285       if( pRec->flags & MEM_Zero ){
  2283   2286         /* Only pure zero-filled BLOBs can be input to this Opcode.
  2284   2287         ** We do not allow blobs with a prefix and a zero-filled tail. */
  2285         -      assert( pRec->n==0 );
  2286   2288         nZero += pRec->u.i;
  2287   2289       }else if( len ){
  2288   2290         nZero = 0;
  2289   2291       }
  2290   2292     }
  2291   2293   
  2292   2294     /* If we have to append a varint rowid to this record, set pRowid

Changes to src/vdbeapi.c.

   494    494   
   495    495   /**************************** sqlite3_column_  *******************************
   496    496   ** The following routines are used to access elements of the current row
   497    497   ** in the result set.
   498    498   */
   499    499   const void *sqlite3_column_blob(sqlite3_stmt *pStmt, int i){
   500    500     const void *val;
   501         -  sqlite3MallocDisallow();
   502    501     val = sqlite3_value_blob( columnMem(pStmt,i) );
   503         -  sqlite3MallocAllow();
   504    502     return val;
   505    503   }
   506    504   int sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){
   507    505     int val = sqlite3_value_bytes( columnMem(pStmt,i) );
   508    506     columnMallocFailure(pStmt);
   509    507     return val;
   510    508   }

Changes to test/all.test.

     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file runs all tests.
    12     12   #
    13         -# $Id: all.test,v 1.41 2007/05/08 15:59:06 danielk1977 Exp $
           13  +# $Id: all.test,v 1.42 2007/05/10 17:32:48 danielk1977 Exp $
    14     14   
    15     15   set testdir [file dirname $argv0]
    16     16   source $testdir/tester.tcl
    17     17   rename finish_test really_finish_test
    18     18   proc finish_test {} {
    19     19     memleak_check
    20     20   }
................................................................................
    56     56     crash2.test
    57     57     autovacuum_crash.test
    58     58     quick.test
    59     59     malloc.test
    60     60     misuse.test
    61     61     memleak.test
    62     62     sqllimits1.test
           63  +  fuzz.test
    63     64   }
    64     65   
    65     66   # Files to include in the test.  If this list is empty then everything
    66     67   # that is not in the EXCLUDE list is run.
    67     68   #
    68     69   set INCLUDE {
    69     70   }

Changes to test/fuzz.test.

     8      8   #    May you find forgiveness for yourself and forgive others.
     9      9   #    May you share freely, never taking more than you give.
    10     10   #
    11     11   #***********************************************************************
    12     12   # This file implements regression tests for SQLite library.  The
    13     13   # focus of this file is testing the SELECT statement.
    14     14   #
    15         -# $Id: fuzz.test,v 1.1 2007/05/10 15:37:53 danielk1977 Exp $
           15  +# $Id: fuzz.test,v 1.2 2007/05/10 17:32:48 danielk1977 Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   proc fuzz {TemplateList} {
    21     21     set n [llength $TemplateList]
    22     22     set i [expr {int(rand()*$n)}]
    23     23     return [subst -novar [lindex $TemplateList $i]]
    24     24   }
    25     25   
    26         -proc Value {} {
           26  +# Returns a string representing an SQL literal.
           27  +#
           28  +proc Literal {} {
    27     29     set TemplateList {
    28     30       456 0 -456 1 -1 
    29     31       2147483648 2147483647 2147483649 -2147483647 -2147483648 -2147483649
    30     32       'The' 'first' 'experiments' 'in' 'hardware' 'fault' 'injection'
    31     33       zeroblob(1000)
    32     34       NULL
    33     35       56.1 -56.1
................................................................................
    46     48     fuzz $TemplateList
    47     49   }
    48     50   
    49     51   set ::ExprDepth 0
    50     52   proc Expr {} {
    51     53     incr ::ExprDepth
    52     54   
    53         -  set TemplateList {[Value]}
           55  +  set TemplateList {[Literal]}
    54     56     if {$::ExprDepth < 100} {
    55     57       lappend TemplateList \
    56     58         {[Expr] [BinaryOp] [Expr]}   \
    57         -      {[UnaryOp] [Expr]}           \
    58         -      {([Select])}                 \
    59         -      {[Value]}                    
           59  +      {[UnaryOp] [Expr]}
    60     60     }
    61     61     if {$::SelectDepth < 10} {
    62         -    lappend TemplateList {([Select])}
           62  +    lappend TemplateList {([Select 1])}
    63     63     } 
    64     64     set res [fuzz $TemplateList]
    65     65     incr ::ExprDepth -1
    66     66     return $res
    67     67   }
           68  +
           69  +set ::TableList [list]
           70  +proc Table {} {
           71  +  set TemplateList [concat sqlite_master $::TableList]
           72  +  fuzz $TemplateList
           73  +}
    68     74   
    69     75   set ::SelectDepth 0
    70         -proc Select {} {
           76  +proc Select {{isExpr 0}} {
    71     77     incr ::SelectDepth
    72     78     set TemplateList {
    73     79         {SELECT [Expr]}
    74     80     }
           81  +  if {$::SelectDepth < 5} {
           82  +    lappend TemplateList \
           83  +        {SELECT [Expr] FROM ([Select])}                \
           84  +        {SELECT [Expr] FROM [Table]}                  
           85  +
           86  +    if {0 == $isExpr} {
           87  +      lappend TemplateList                                         \
           88  +          {SELECT [Expr], [Expr] FROM ([Select]) ORDER BY [Expr]}  \
           89  +          {SELECT * FROM ([Select]) ORDER BY [Expr]}               \
           90  +    }
           91  +  } 
    75     92     set res [fuzz $TemplateList]
    76     93     incr ::SelectDepth -1
    77     94     set res
    78     95   }
    79     96   
           97  +########################################################################
           98  +
           99  +#----------------------------------------------------------------
          100  +# These tests caused errors that were first caught by the tests
          101  +# in this file. They are still here.
    80    102   do_test fuzz-1.1 {
    81    103     execsql {
    82    104       SELECT 'abc' LIKE X'ABCD';
    83    105     }
    84    106   } {0}
    85    107   do_test fuzz-1.2 {
    86    108     execsql {
................................................................................
    93    115     }
    94    116   } {0}
    95    117   do_test fuzz-1.4 {
    96    118     execsql {
    97    119       SELECT (- -21) % NOT (456 LIKE zeroblob(10));
    98    120     }
    99    121   } {0}
          122  +do_test fuzz-1.5 {
          123  +  execsql {
          124  +    SELECT (SELECT (
          125  +        SELECT (SELECT -2147483648) FROM (SELECT 1) ORDER BY 1
          126  +    ))
          127  +  }
          128  +} {-2147483648}
          129  +do_test fuzz-1.6 {
          130  +  execsql {
          131  +    SELECT 'abc', zeroblob(1) FROM (SELECT 1) ORDER BY 1
          132  +  }
          133  +} [execsql {SELECT 'abc', zeroblob(1)}]
          134  +
          135  +do_test fuzz-1.7 {
          136  +  execsql {
          137  +SELECT + (SELECT (SELECT 'fault' / + -2147483648 % - 123456789.1234567899 * (SELECT 'experiments' OR NOT 'first' / 'hardware' FROM (SELECT 2147483647, + (SELECT 'injection') FROM (SELECT 2147483649) ORDER BY + NULL AND (SELECT 'hardware') GLOB 2147483648))) FROM (SELECT * FROM (SELECT (SELECT (SELECT + (SELECT 456 * -2147483648)) LIKE (SELECT (SELECT (SELECT 'fault') - -56.1)) AND -2147483648) FROM (SELECT * FROM (SELECT 2147483648) ORDER BY (SELECT 56.1))) ORDER BY zeroblob(1))
          138  +  }
          139  +} {}
   100    140   
   101         -do_test fuzz-2.1 {
   102         -  for {set ii 0} {$ii < 2000} {incr ii} {
          141  +#----------------------------------------------------------------
          142  +# Test some fuzzily generated expressions.
          143  +#
          144  +for {set ii 0} {$ii < 2000} {incr ii} {
          145  +  do_test fuzz-2.1.$ii {
   103    146       set ::expr [Expr]
   104         -    execsql "SELECT $::expr"
          147  +    set rc [catch {execsql "SELECT $::expr"} msg]
          148  +    set e [expr {
          149  +      $rc == 0 || 
          150  +      $msg eq "parser stack overflow" ||
          151  +      0 == [string first "ORDER BY column number" $msg]
          152  +    }]
          153  +    if {$e == 0} {
          154  +      puts ""
          155  +      puts "SELECT $::expr"
          156  +      puts $msg
          157  +    }
          158  +    set e
          159  +  } {1}
          160  +} 
          161  +
          162  +do_test fuzz-3.1 {
          163  +  execsql {
          164  +    CREATE TABLE abc(a, b, c);
          165  +    CREATE TABLE def(d, e, f);
          166  +    CREATE TABLE ghi(g, h, i);
   105    167     }
   106         -  set a ""
   107    168   } {}
          169  +set ::TableList [list abc def ghi]
          170  +
          171  +#----------------------------------------------------------------
          172  +# Test some fuzzily generated SELECT statements.
          173  +#
          174  +for {set ii 0} {$ii < 2000} {incr ii} {
          175  +  do_test fuzz-2.2.$ii {
          176  +    set ::select [Select]
          177  +    set rc [catch {execsql $::select} msg]
          178  +    set e [expr {$rc == 0 || $msg eq "parser stack overflow"}]
          179  +    set e [expr {
          180  +      $rc == 0 || 
          181  +      $msg eq "parser stack overflow" ||
          182  +      0 == [string first "ORDER BY column number" $msg]
          183  +    }]
          184  +    if {$e == 0} {
          185  +      puts ""
          186  +      puts $::select
          187  +      puts $msg
          188  +    }
          189  +    set e
          190  +  } {1}
          191  +} 
   108    192   
   109    193   finish_test
   110    194