/ Check-in [a70958cd]
Login

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

Overview
Comment:Fix an assert() in vdbemem.c that could fire if the database was corrupt.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:a70958cd7d5cf750c293537856918e5789013b70f6a827f724d83559b38629c8
User & Date: dan 2019-01-23 20:31:56
Context
2019-01-24
04:44
Remove an unreachable branch. check-in: 4c976f17 user: drh tags: trunk
2019-01-23
20:31
Fix an assert() in vdbemem.c that could fire if the database was corrupt. check-in: a70958cd user: dan tags: trunk
19:50
Fix a problem with renaming a table within a schema that contains a composite query that uses a column alias as an ORDER BY term. check-in: 2ca6b8f8 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbemem.c.

   239    239   ** and MEM_Blob values may be discarded, MEM_Int, MEM_Real, and MEM_Null
   240    240   ** values are preserved.
   241    241   **
   242    242   ** Return SQLITE_OK on success or an error code (probably SQLITE_NOMEM)
   243    243   ** if unable to complete the resizing.
   244    244   */
   245    245   int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){
   246         -  assert( szNew>0 );
          246  +  assert( CORRUPT_DB || szNew>0 );
   247    247     assert( (pMem->flags & MEM_Dyn)==0 || pMem->szMalloc==0 );
   248    248     if( pMem->szMalloc<szNew ){
   249    249       return sqlite3VdbeMemGrow(pMem, szNew, 0);
   250    250     }
   251    251     assert( (pMem->flags & MEM_Dyn)==0 );
   252    252     pMem->z = pMem->zMalloc;
   253    253     pMem->flags &= (MEM_Null|MEM_Int|MEM_Real);

Changes to test/corruptL.test.

   128    128   do_catchsql_test 1.2 {
   129    129     SELECT sum(s+length(b)) FROM t1 WHERE a IN (110,10,150) AND q IS NULL;
   130    130   } {1 {no such table: t1}}
   131    131   
   132    132   do_catchsql_test 1.3 {
   133    133     REINDEX t1;
   134    134   } {1 {unable to identify the object to be reindexed}}
          135  +
          136  +#-------------------------------------------------------------------------
          137  +reset_db
          138  +do_test 2.0 {
          139  +  sqlite3 db {}
          140  +  db deserialize [decode_hexdb {
          141  +| size 20480 pagesize 4096 filename crash.txt.db
          142  +| page 1 offset 0
          143  +|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
          144  +|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 05   .....@  ........
          145  +|     32: 00 00 00 00 00 00 00 00 00 00 00 05 00 00 00 04   ................
          146  +|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
          147  +|     96: 00 00 00 00 0d 00 00 00 05 0e 55 00 0f 74 0f 3c   ..........U..t.<
          148  +|    112: 0e f9 0e d1 0e 55 00 00 00 00 00 00 00 00 00 00   .....U..........
          149  +|   3664: 00 00 00 00 00 7a 05 07 15 11 11 08 81 63 76 69   .....z.......cvi
          150  +|   3680: 65 77 76 31 76 31 43 52 45 41 54 45 20 56 49 45   ewv1v1CREATE VIE
          151  +|   3696: 57 20 76 31 28 78 2c 79 29 20 41 53 0a 53 45 4c   W v1(x,y) AS.SEL
          152  +|   3712: 45 43 54 20 74 31 2e 62 2c 74 32 2e 62 20 46 52   ECT t1.b,t2.b FR
          153  +|   3728: 4f 4d 20 74 31 2c 74 32 20 57 48 45 52 45 20 74   OM t1,t2 WHERE t
          154  +|   3744: 31 2e 61 3d 74 32 2e 61 20 47 52 4f 55 50 20 42   1.a=t2.a GROUP B
          155  +|   3760: 59 20 31 20 48 41 56 49 4e 47 20 74 32 2e 63 20   Y 1 HAVING t2.c 
          156  +|   3776: 4e 4f 54 20 4e 55 4c 4c 0a 4c 49 4d 49 54 20 31   NOT NULL.LIMIT 1
          157  +|   3792: 30 26 04 06 17 11 11 01 39 74 61 62 6c 65 74 32   0&......9tablet2
          158  +|   3808: 74 32 05 43 52 45 41 54 45 20 54 41 42 4c 45 20   t2.CREATE TABLE 
          159  +|   3824: 74 32 28 61 2c 62 2c 63 29 41 03 06 17 15 11 01   t2(a,b,c)A......
          160  +|   3840: 6b 69 6e 64 65 78 74 31 78 31 74 31 04 43 52 45   kindext1x1t1.CRE
          161  +|   3856: 41 54 45 20 49 4e 44 45 58 20 73 31 78 31 20 4f   ATE INDEX s1x1 O
          162  +|   3872: 4e 20 74 31 28 64 29 20 57 48 45 52 45 20 65 65   N t1(d) WHERE ee
          163  +|   3888: 20 49 53 20 4e 4f 54 20 4e 55 4c 4c 36 02 06 17    IS NOT NULL6...
          164  +|   3904: 17 11 01 53 69 6e 64 65 78 74 31 61 62 63 74 31   ...Sindext1abct1
          165  +|   3920: 03 43 52 45 41 54 45 20 49 4e 44 45 58 20 74 31   .CREATE INDEX t1
          166  +|   3936: 61 62 63 20 4f 4e 20 74 31 28 61 2c 62 2c 63 2b   abc ON t1(a,b,c+
          167  +|   3952: 64 2b 65 29 81 09 01 07 17 11 11 01 81 7d 74 61   d+e)..........ta
          168  +|   3968: 62 6c 65 74 31 74 31 02 43 52 45 41 54 45 20 54   blet1t1.CREATE T
          169  +|   3984: 41 42 4c 45 20 74 31 28 61 2c 62 2c 63 2c 64 2c   ABLE t1(a,b,c,d,
          170  +|   4000: 65 2c 66 2c 67 2c 68 2c 6a 2c 6a 6a 2c 6a 6a 6a   e,f,g,h,j,jj,jjj
          171  +|   4016: 2c 6b 2c 61 61 2c 62 62 2c 63 63 2c 64 64 2c 65   ,k,aa,bb,cc,dd,e
          172  +|   4032: 65 20 44 45 46 41 55 4c 54 20 33 2e 31 34 2c 0a   e DEFAULT 3.14,.
          173  +|   4048: 66 66 20 44 45 46 41 55 4c 54 28 27 68 69 63 63   ff DEFAULT('hicc
          174  +|   4064: 75 70 27 29 2c 67 67 20 4e 4f 54 20 4e 55 4c 4c   up'),gg NOT NULL
          175  +|   4080: 20 44 45 46 41 55 4c 54 28 66 61 6c 73 65 29 29    DEFAULT(false))
          176  +| page 2 offset 4096
          177  +|      0: 0d 00 00 00 0a 0e 7b 00 0f dc 0f b6 0f 8f 0f 68   ...............h
          178  +|     16: 0f 41 0f 1a 0e f3 0e cb 0e a3 0e 7b 00 00 00 00   .A..............
          179  +|   3696: 00 00 00 00 00 00 00 00 00 00 00 26 0a 14 01 01   ...........&....
          180  +|   3712: 02 08 00 00 00 00 00 00 00 00 00 00 00 00 07 19   ................
          181  +|   3728: 08 09 5a 00 b4 40 09 1e b8 51 eb 85 1f 68 69 63   ..Z..@...Q...hic
          182  +|   3744: 63 75 70 26 09 14 01 01 02 08 00 00 00 00 00 00   cup&............
          183  +|   3760: 00 00 00 00 00 00 07 19 08 08 50 00 a0 40 09 1e   ..........P..@..
          184  +|   3776: b8 51 eb 85 1f 68 69 63 63 75 70 26 08 14 01 01   .Q...hiccup&....
          185  +|   3792: 02 08 00 00 00 00 00 00 00 00 00 00 00 00 07 19   ................
          186  +|   3808: 08 07 46 00 8c 40 09 1e b8 51 eb 85 1f 68 69 63   ..F..@...Q...hic
          187  +|   3824: 63 75 70 25 07 14 01 01 01 08 00 00 00 00 00 00   cup%............
          188  +|   3840: 00 00 00 00 00 00 07 b9 08 06 3c 78 40 09 1e b8   ..........<x@...
          189  +|   3856: 51 eb 85 1f 68 69 63 63 75 70 25 06 14 01 00 01   Q...hiccup%.....
          190  +|   3872: 08 00 00 00 00 00 00 00 00 00 00 00 00 07 19 08   ................
          191  +|   3888: 05 32 64 40 09 1e b8 51 eb 85 1f 68 69 63 63 75   .2d@...Q...hiccu
          192  +|   3904: 70 25 05 14 01 01 01 08 00 00 00 00 00 00 00 00   p%..............
          193  +|   3920: 00 00 00 00 07 19 08 04 28 50 40 09 1e b8 51 eb   ........(P@...Q.
          194  +|   3936: 85 1f 68 69 63 63 75 70 25 04 14 01 01 01 08 00   ..hiccup%.......
          195  +|   3952: 00 00 00 00 00 00 00 00 00 00 00 07 19 08 03 1e   ................
          196  +|   3968: 3c 40 09 1e b8 51 eb 85 1f 68 69 63 63 75 70 25   <@...Q...hiccup%
          197  +|   3984: 03 14 01 01 01 08 00 00 00 00 00 00 00 00 00 00   ................
          198  +|   4000: 00 00 07 19 08 02 14 28 40 09 1e b8 51 eb 85 1f   .......(@...Q...
          199  +|   4016: 68 69 63 63 75 70 24 02 14 09 01 01 08 00 00 00   hiccup$.........
          200  +|   4032: 00 00 00 00 00 00 00 00 00 07 19 08 0a 14 40 09   ..............@.
          201  +|   4048: 1e b8 51 eb 85 1f 68 69 63 63 75 70 22 01 14 08   ..Q...hiccup....
          202  +|   4064: 08 08 07 ff ff ff ff ff ff 00 00 00 00 00 00 07   ................
          203  +|   4080: 19 08 40 09 1e b8 51 eb 85 1f 68 69 63 63 75 70   ..@...Q...hiccup
          204  +| page 3 offset 8192
          205  +|      0: 0a 00 00 00 0a 0f aa 00 0f fa 0f f2 0f e9 0f e0   ................
          206  +|     16: 0f d7 0f ce 0f c5 0f bc 0e b3 0f aa 00 00 00 00   ................
          207  +|   4000: 00 00 00 00 00 00 00 00 00 00 08 05 01 01 00 01   ................
          208  +|   4016: 09 5a 0a 08 05 01 01 00 01 08 50 09 08 05 01 01   .Z........P.....
          209  +|   4032: 00 01 07 46 08 08 05 01 01 00 01 06 3c 07 08 05   ...F........<...
          210  +|   4048: 01 01 00 01 05 32 06 08 05 01 01 00 01 04 28 05   .....2........(.
          211  +|   4064: 08 05 01 01 00 01 03 1e 04 08 05 01 01 00 01 02   ................
          212  +|   4080: 14 03 07 05 09 01 00 01 0a 02 05 05 08 08 00 09   ................
          213  +| page 4 offset 12288
          214  +|      0: 0a 00 00 00 0a 0f cf 00 0f fc 0f f7 0f f2 0f ed   ................
          215  +|     16: 0f e8 0f e3 0f de 0f d9 0f d4 0f cf 00 00 00 00   ................
          216  +|   4032: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04   ................
          217  +|   4048: 03 08 01 0a 04 03 08 01 09 04 03 08 01 08 04 03   ................
          218  +|   4064: 08 01 07 04 03 08 01 06 04 03 08 01 05 04 03 08   ................
          219  +|   4080: 01 04 04 03 08 01 13 04 03 08 01 02 03 03 08 09   ................
          220  +| page 5 offset 16384
          221  +|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
          222  +| end crash.txt.db
          223  +}]} {}
          224  +
          225  +do_execsql_test 2.1 {
          226  +  INSERT INTO t1(b) VALUES(X'a0fee3669f9fddefc5cba913e4225d4b6ce2b04f26b87fad3ee6f9b7d90a1ea62a169bf41e5d32707a6ca5c3d05e4bde05c9d89eaaa8c50e74333d2e9fcd7dfe95528a3a016aac1102d825c5cd70cf99d8a88e0ea7f798d4334386518b7ad359beb168b93aba059a2a3bd93112d65b44c12b9904ea786b204d80531cdf0504bf9b203dbe927061974caf7b9f30cbc3397b61f802e732012a6663d41c3607d6f1c0dbcfd489adac05ca500c0b04439d894cd93a840159225ef73b627e178b9f84b3ffe66cf22a963a8368813ff7961fc47f573211ccec95e0220dcbb3bf429f4a50ba54d7a53784ac51bfef346e6ac8ae0d0e7c3175946e62ba2b');
          227  +}
          228  +
          229  +do_catchsql_test 2.2 {
          230  +  SELECT b,c FROM t1 ORDER BY a;
          231  +} {1 {database disk image is malformed}}
   135    232   
   136    233   finish_test