]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix an assert() that could fail when operating on a database with a corrupt schema.
authordrh <drh@noemail.net>
Thu, 18 Jun 2020 13:16:19 +0000 (13:16 +0000)
committerdrh <drh@noemail.net>
Thu, 18 Jun 2020 13:16:19 +0000 (13:16 +0000)
FossilOrigin-Name: b69b9c0628feac9f1ecc53e4411377168ee0ecc82dc2d80de4270d37b218022c

manifest
manifest.uuid
src/btree.c
test/corruptL.test

index 922e290d179de5c320d5892e4c0629f0214c85ae..8e271b49e333b11c502b691bc6794395ada2666b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,12 +1,13 @@
 B dafd2466a10f68acbe129010216f017a5fcfc048ffbc0da806d04f04e58cfcbb
-C Fix\san\sassert()\sin\sfts3\sthat\scould\sfail\swhen\sprocessing\sa\scorrupt\srecord.
-D 2020-06-17T17:27:42.376
+C Fix\san\sassert()\sthat\scould\sfail\swhen\soperating\son\sa\sdatabase\swith\sa\scorrupt\sschema.
+D 2020-06-18T13:16:19.987
 F ext/fts3/fts3.c 2e97a41c7b543602b06f2653e45a80040471e75faebe08cc8cc2a875e08c4573
-F src/btree.c fabc215bd1ebab0e48108e95e0f50531da9883156b95888f479f6c696db032ad
+F src/btree.c 70129047b9bdd55526c5508debfe62b781f7aca266bb1e5dae0a2781775ca314
 F src/expr.c 96cf4c2996a8ff3fe2281d9f3042ec5431ab2cbd793aa30881d992918b473487
 F src/select.c bbd52d8405f0fdf70fe6643726467e39baa7402a0ab94ca0d509a28dfc689bcf
 F src/sqliteInt.h 04a6d2745c4f4849f5b8f898345e3548fe1df5aa910cc24f757ec69c9749478e
 F src/vdbe.c 907af2a69df180eb2127eb888db7d456a32e137a12786de4f977cf06a74b35a2
+F test/corruptL.test 16564fa7961fcce242945177c9bdaa5cb5dc85d6248612dbe4b927d059eb6014
 F test/fts3corrupt2.test e318f0676e5e78d5a4b702637e2bb25265954c08a1b1e4aaf93c7880bb0c67d0
 F test/fts3corrupt4.test 4664c72bb49400b6f3d86627760129ee7962e4834869909c55037ff21ccd36b8
 F test/fuzzdata8.db 9ce2e5f0d7e5e61d5f8f0817346b2a3db2aeebbaff20d04043521623ea0558be
@@ -15,8 +16,8 @@ F test/select3.test c49fbb758903f3718e2de5aa4655eda4838131cbea24a86db908f8b6889a
 F test/selectA.test 68de52409e45a3313d00b8461b48bef4fb729faf36ade9067a994eae55cc86f4
 F test/whereG.test 9363b2a97d914cb1b81aff5069ef0cf2a071a67e2b604eac6fe9c0114017d9aa
 F test/window1.test 9d7f4990e5b36d95af93b189da4aa75216c6690ce95cced3c8b6d3234be51c2c
-P d55b8e7993997e6bd75396479c822947a1254b62c28c4bbb71b4ff4f1410a802
-Q +4adc0a1b0d84c2df6d6bf0d5d9d3fa9f7d048af8d232c4beb77518727890f212
-R f100ce1d1dd24c443d6f37be5e50d635
+P ea71fb7fabcce71af05af14a8eaba3693f6bc859a18ab9f107eaac51260853fe
+Q +4a340c9bc7d939efc947e3b17ca79314482f74368b15567dd089d40e4270890e
+R 2bbc117557c880d77e67f268ff4a1068
 U drh
-Z 89cb383605bae91c0693bc8d72810923
+Z 23b708055b70b0a6f1504899749a13d8
index abd4f26a33cbd71ea80f01a03d5966dee9134899..0ffe7652e001cc6cdc79f17e316c548daa77ac55 100644 (file)
@@ -1 +1 @@
-ea71fb7fabcce71af05af14a8eaba3693f6bc859a18ab9f107eaac51260853fe
\ No newline at end of file
+b69b9c0628feac9f1ecc53e4411377168ee0ecc82dc2d80de4270d37b218022c
\ No newline at end of file
index 6ec97f2edd8ce4e31ebaa6ee9235e93f597de3b1..91675c7540a1b1a4fa7a6e829a597840178be6c8 100644 (file)
@@ -200,16 +200,18 @@ static int hasSharedCacheTableLock(
   ** table.  */
   if( isIndex ){
     HashElem *p;
+    int bSeen = 0;
     for(p=sqliteHashFirst(&pSchema->idxHash); p; p=sqliteHashNext(p)){
       Index *pIdx = (Index *)sqliteHashData(p);
       if( pIdx->tnum==(int)iRoot ){
-        if( iTab ){
+        if( bSeen ){
           /* Two or more indexes share the same root page.  There must
           ** be imposter tables.  So just return true.  The assert is not
           ** useful in that case. */
           return 1;
         }
         iTab = pIdx->pTable->tnum;
+        bSeen = 1;
       }
     }
   }else{
index 67d308abca541e0dc4ffe985d7aeee8fdb1eef25..3c26f1d215618e9177c715ebaec384f545e83cd7 100644 (file)
@@ -1182,5 +1182,89 @@ do_catchsql_test 14.2 {
   ALTER TABLE t1 RENAME TO alkjalkjdfiiiwuer987lkjwer82mx97sf98788s9789s; 
 } {1 {database disk image is malformed}}
 
+#-------------------------------------------------------------------------
+reset_db
+do_test 15.0 {
+  sqlite3 db {}
+  db deserialize [decode_hexdb {
+| size 28672 pagesize 4096 filename crash-3afa1ca9e9c1bd.db
+| page 1 offset 0
+|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
+|     16: 10 00 01 01 00 40 20 20 00 00 00 00 00 00 00 07   .....@  ........
+|     32: 00 00 00 00 00 00 00 00 00 00 00 06 00 00 00 04   ................
+|     48: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00   ................
+|     96: 00 00 00 00 0d 00 00 00 06 0e 88 00 0f b8 0f 6d   ...............m
+|    112: 0f 3a 0f 0b 0e d5 0e 88 01 00 00 00 00 00 00 00   .:..............
+|   3712: 00 00 00 00 00 00 00 00 4b 06 06 17 25 25 01 5b   ........K...%%.[
+|   3728: 74 61 62 6c 65 73 71 6c 69 74 65 5f 73 74 61 74   tablesqlite_stat
+|   3744: 31 73 71 6c 69 74 65 5f 73 74 61 74 31 07 43 52   1sqlite_stat1.CR
+|   3760: 45 41 54 45 20 54 41 42 4c 45 20 73 71 6c 69 74   EATE TABLE sqlit
+|   3776: 65 5f 73 74 61 74 31 28 74 62 6c 2c 69 64 78 2c   e_stat1(tbl,idx,
+|   3792: 73 74 61 74 29 34 05 06 17 13 11 01 53 69 6e 64   stat)4......Sind
+|   3808: 65 78 63 31 63 63 31 06 43 52 45 41 54 45 20 55   exc1cc1.CREATE U
+|   3824: 4e 49 51 55 45 20 49 4e 44 45 58 20 63 31 63 20   NIQUE INDEX c1c 
+|   3840: 4f 4e 20 63 31 28 63 2c 20 62 29 2d 04 06 17 13   ON c1(c, b)-....
+|   3856: 11 01 45 69 6e 64 65 78 63 31 64 63 31 05 43 52   ..Eindexc1dc1.CR
+|   3872: 45 41 54 45 20 49 4e 44 45 58 20 63 31 64 20 4f   EATE INDEX c1d O
+|   3888: 4e 20 63 31 28 64 2c 20 62 29 31 03 06 17 13 11   N c1(d, b)1.....
+|   3904: 01 4d 69 6e 64 65 78 62 31 63 62 31 05 43 52 45   .Mindexb1cb1.CRE
+|   3920: 41 54 45 20 55 4e 49 51 55 45 20 49 4e 44 45 58   ATE UNIQUE INDEX
+|   3936: 20 62 31 63 20 4f 4e 20 62 31 28 63 29 49 02 06    b1c ON b1(c)I..
+|   3952: 17 11 11 0f 7f 74 61 62 6c 65 63 31 63 31 03 43   .....tablec1c1.C
+|   3968: 52 45 41 54 45 20 54 41 42 4c 45 20 63 31 28 61   REATE TABLE c1(a
+|   3984: 20 49 4e 54 20 50 52 49 4d 41 52 59 20 4b 45 59    INT PRIMARY KEY
+|   4000: 2c 20 62 2c 20 63 2c 20 64 29 20 57 49 54 48 4f   , b, c, d) WITHO
+|   4016: 55 54 20 52 4f 57 49 44 46 01 06 17 11 11 01 79   UT ROWIDF......y
+|   4032: 74 61 62 6c 65 62 31 62 31 02 43 52 45 41 54 45   tableb1b1.CREATE
+|   4048: 20 54 41 42 4c 45 20 62 31 28 61 20 49 4e 54 20    TABLE b1(a INT 
+|   4064: 50 52 49 4d 41 52 59 20 4b 45 59 2c 20 62 2c 20   PRIMARY KEY, b, 
+|   4080: 63 29 20 57 49 54 48 4f 55 54 20 52 4f 57 49 44   c) WITHOUT ROWID
+| page 2 offset 4096
+|      0: 0a 00 00 00 07 0f ca 00 0f fa 0f f2 0f ea 0f e2   ................
+|     16: 0f da 00 00 00 01 00 00 00 00 00 00 00 00 00 00   ................
+|   4032: 00 00 00 00 00 00 00 00 00 00 07 04 01 0f 01 06   ................
+|   4048: 67 07 07 04 01 0f 01 06 66 06 07 04 01 0f 01 05   g.......f.......
+|   4064: 65 05 07 04 01 0f 01 04 64 04 07 04 01 0f 01 03   e.......d.......
+|   4080: 63 03 07 04 01 0f 01 02 62 0f 05 04 09 0f 09 61   c.......b......a
+| page 3 offset 8192
+|      0: 0a 00 00 00 07 0f bd 00 0f f9 0f ef 0f e5 0f db   ................
+|     16: 0f d1 0f c7 0f bd 00 00 00 00 01 00 00 00 00 00   ................
+|   4016: 00 00 00 00 00 00 00 00 00 00 00 00 00 09 05 01   ................
+|   4032: 0f 01 01 07 61 07 07 09 05 01 0f 01 01 06 61 06   ....a.........a.
+|   4048: 06 09 05 01 0f 01 01 05 61 05 05 09 05 01 0f 01   ........a.......
+|   4064: 01 04 61 04 04 09 05 01 0f 01 01 03 61 03 03 09   ..a.........a...
+|   4080: 05 01 0f 01 01 02 61 0f 02 06 05 09 0f 09 09 61   ......a........a
+| page 4 offset 12288
+|      0: 0a 00 00 00 07 0f d8 00 0f fc 0f f0 0f ea 0f e4   ................
+|     16: 0f de 0f d8 0f f6 00 00 00 00 00 00 00 00 00 00   ................
+|   4048: 00 00 00 00 00 00 00 00 05 03 01 01 07 07 05 03   ................
+|   4064: 01 01 06 06 05 03 01 01 05 05 05 03 01 01 04 04   ................
+|   4080: 05 03 01 01 03 03 05 03 01 01 0f 02 03 03 09 09   ................
+| page 5 offset 16384
+|      0: 0a 00 00 00 07 0f ca 00 0f fa 0f f2 0f ea 0f 00   ................
+|   4032: 00 00 00 00 00 00 00 00 00 00 07 04 01 0f 01 07   ................
+|   4048: 61 07 07 04 01 0f 01 06 61 06 07 04 01 0f 01 05   a.......a.......
+|   4064: 61 05 07 04 01 1f 01 04 61 04 07 04 01 0f 01 03   a.......a.......
+|   4080: 61 03 07 04 01 0f 01 02 61 02 05 04 09 0f 09 61   a.......a......a
+| page 6 offset 20480
+|      0: 0a 00 00 00 07 0f ca 00 0f fa 0f ea 0f e2 00 00   ................
+|   4032: 00 00 00 00 00 00 00 00 00 00 07 04 01 0f 01 07   ................
+|   4048: 61 07 07 04 01 0f 01 06 61 06 07 04 01 0f 01 05   a.......a.......
+|   4064: 61 05 07 04 01 0f 01 04 61 04 07 04 01 0f 01 03   a.......a.......
+|   4080: 61 03 07 04 01 0f 01 0f 61 02 05 04 09 0f 09 61   a.......a......a
+| page 7 offset 24576
+|      0: 0d 00 00 00 05 0f 1c 00 0f f0 0f e0 0f d3 0f c5   ................
+|     16: 0f b8 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
+|   4016: 00 00 00 00 00 00 00 00 0b 05 04 11 11 13 62 31   ..............b1
+|   4032: 62 31 37 20 31 0c 04 04 11 13 13 62 31 62 31 63   b17 1......b1b1c
+|   4048: 37 20 31 0b 03 04 11 11 13 63 31 63 31 37 20 31   7 1......c1c17 1
+|   4064: 0e 02 04 11 13 07 63 31 63 31 64 37 20 31 20 31   ......c1c1d7 1 1
+|   4080: 0e 01 04 11 13 17 63 31 63 31 63 37 20 31 00 00   ......c1c1c7 1..
+| end crash-3afa1ca9e9c1bd.db
+}]} {}
+
+do_execsql_test 15.1 {
+  UPDATE c1 SET c= NOT EXISTS(SELECT 1 FROM c1 ORDER BY (SELECT 1 FROM c1 ORDER BY a)) +10 WHERE d BETWEEN 4 AND 7;
+} {}
 finish_test