/ Check-in [8af0caeb]
Login

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

Overview
Comment:Early detection of too many columns in an index avoid a possible 16-bit signed integer overflow.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8af0caeb6d1e55f66ad2f12af94845dccfe1d0420faf326f5917fc07f8aa6050
User & Date: drh 2019-03-31 21:09:33
Context
2019-04-01
03:07
Fix harmless compiler warnings seen with MSVC. check-in: 6cf8b18e user: mistachkin tags: trunk
2019-03-31
21:09
Early detection of too many columns in an index avoid a possible 16-bit signed integer overflow. check-in: 8af0caeb user: drh tags: trunk
18:17
Add some missing VdbeCoverage() macros. check-in: d03b6113 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

  3261   3261       pList = sqlite3ExprListAppend(pParse, 0,
  3262   3262                 sqlite3ExprAlloc(db, TK_ID, &prevCol, 0));
  3263   3263       if( pList==0 ) goto exit_create_index;
  3264   3264       assert( pList->nExpr==1 );
  3265   3265       sqlite3ExprListSetSortOrder(pList, sortOrder);
  3266   3266     }else{
  3267   3267       sqlite3ExprListCheckLength(pParse, pList, "index");
         3268  +    if( pParse->nErr ) goto exit_create_index;
  3268   3269     }
  3269   3270   
  3270   3271     /* Figure out how many bytes of space are required to store explicitly
  3271   3272     ** specified collation sequence names.
  3272   3273     */
  3273   3274     for(i=0; i<pList->nExpr; i++){
  3274   3275       Expr *pExpr = pList->a[i].pExpr;
................................................................................
  3279   3280     }
  3280   3281   
  3281   3282     /* 
  3282   3283     ** Allocate the index structure. 
  3283   3284     */
  3284   3285     nName = sqlite3Strlen30(zName);
  3285   3286     nExtraCol = pPk ? pPk->nKeyCol : 1;
         3287  +  assert( pList->nExpr + nExtraCol <= 32767 /* Fits in i16 */ );
  3286   3288     pIndex = sqlite3AllocateIndexObject(db, pList->nExpr + nExtraCol,
  3287   3289                                         nName + nExtra + 1, &zExtra);
  3288   3290     if( db->mallocFailed ){
  3289   3291       goto exit_create_index;
  3290   3292     }
  3291   3293     assert( EIGHT_BYTE_ALIGNMENT(pIndex->aiRowLogEst) );
  3292   3294     assert( EIGHT_BYTE_ALIGNMENT(pIndex->azColl) );

Changes to test/createtab.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing that it is OK to create new tables
    13     13   # and indices while creating existing tables and indices.
    14     14   #
    15         -# $Id: createtab.test,v 1.3 2007/09/12 17:01:45 danielk1977 Exp $
    16     15   
    17     16   set testdir [file dirname $argv0]
    18     17   source $testdir/tester.tcl
    19     18   
    20     19   ifcapable autovacuum {
    21     20     set upperBound 2
    22     21   } else {
................................................................................
   138    137       execsql {
   139    138         SELECT name FROM sqlite_master WHERE type='table' ORDER BY 1
   140    139       }
   141    140     } {t1 t2 t3 t4}
   142    141     integrity_check createtab-$av.40
   143    142   
   144    143   }
          144  +
          145  +# 2019-03-31 Ensure that a proper error is returned for an index
          146  +# with too many columns.
          147  +#
          148  +do_test createtab-3.1 {
          149  +  db eval {DROP TABLE IF EXISTS t1;}
          150  +  set sql "CREATE TABLE t1(x,UNIQUE(x[string repeat ,x 100000]))"
          151  +  catchsql $sql
          152  +} {1 {too many columns in index}}
   145    153     
   146    154   finish_test