]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Correctly handle an "INTEGER PRIMARY KEY UNIQUE" column in a WITHOUT ROWID
authordrh <drh@noemail.net>
Sun, 30 Jul 2017 18:40:52 +0000 (18:40 +0000)
committerdrh <drh@noemail.net>
Sun, 30 Jul 2017 18:40:52 +0000 (18:40 +0000)
table.  This is a fix for ticket [bc115541132dad136], a problem discovered
by OSSFuzz.

FossilOrigin-Name: 5216bfb73f1a49bdd879d470de139bf46a212474eaf6f38ad2390536d66a2afd

manifest
manifest.uuid
src/build.c
test/without_rowid1.test

index 2a591e1217b20f2ffe3729fe073322ec40d8e073..62d342089fedf0edea928f187c2523af8ead0dca 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Update\sTcl\sversion\sused\sby\sthe\sTclKit\sbatch\stool\sfor\sMSVC.
-D 2017-07-28T22:22:15.250
+C Correctly\shandle\san\s"INTEGER\sPRIMARY\sKEY\sUNIQUE"\scolumn\sin\sa\sWITHOUT\sROWID\ntable.\s\sThis\sis\sa\sfix\sfor\sticket\s[bc115541132dad136],\sa\sproblem\sdiscovered\nby\sOSSFuzz.
+D 2017-07-30T18:40:52.132
 F Makefile.in d9873c9925917cca9990ee24be17eb9613a668012c85a343aef7e5536ae266e8
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc 02b469e9dcd5b7ee63fc1fb05babc174260ee4cfa4e0ef2e48c3c6801567a016
@@ -398,7 +398,7 @@ F src/btmutex.c 0e9ce2d56159b89b9bc8e197e023ee11e39ff8ca
 F src/btree.c f55ea8f456d103328d61076be40fa39acbfea05eaa4eccfed275532a63c867c4
 F src/btree.h 3edc5329bc59534d2d15b4f069a9f54b779a7e51289e98fa481ae3c0e526a5ca
 F src/btreeInt.h 97700795edf8a43245720414798b7b29d8e465aef46bf301ffacd431910c0da1
-F src/build.c 66f3ae9eacddd19caa09c64fdce825e652f007d1b3d632bc231954fb7942b867
+F src/build.c f65f86520aa877853125565e42c59c5c49851a4733392931777fb1aace4aedfd
 F src/callback.c 930648a084a3adc741c6471adfbdc50ba47ba3542421cb80a26f259f467de65e
 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
 F src/ctime.c 928954802b1397d9fb1378c7eb702c94b4735bbab1d5793e21b6a77734f56a1b
@@ -1535,7 +1535,7 @@ F test/with1.test 732e3ef398dcecb609839cd5ef0cb63beb2a9eff31420f3b745fc55b9e85b6
 F test/with2.test 2b40da883658eb74ad8ad06afabe11a408e7fb87
 F test/with3.test e71604a0e53cba82bc04c703987cb1d6751ec0b6
 F test/withM.test 693b61765f2b387b5e3e24a4536e2e82de15ff64
-F test/without_rowid1.test 1a7b9bd51b899928d327052df9741d2fe8dbe701
+F test/without_rowid1.test 06b7215130882d6a072233820dd364c874c4fd69221e8fc756ec471009192874
 F test/without_rowid2.test af260339f79d13cb220288b67cd287fbcf81ad99
 F test/without_rowid3.test 2724c787a51a5dce09d078453a758117b4b728f1
 F test/without_rowid4.test 4e08bcbaee0399f35d58b5581881e7a6243d458a
@@ -1637,7 +1637,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 3286e1a07b0693049a07f0865bf93749c461ea8f6d1175ec2d1642886673d8ac
-R fa880debd22b5643c43c3f5ac12562f1
-U mistachkin
-Z 2ba3113508e5372bd91f947e270302b1
+P bcec155e0d6c6b17ae09d5a366c080723d01ff40dbc1a0ad0bb669a91db1b850
+R ef51b40dfe561fead55e0d7326def69b
+U drh
+Z cbc21ed1f3f9e538b2bc83c6e8eaa497
index cd8f4e864337fbc3bde52d6d849e8a66baa9d1cb..096f15d137ad7159aa8857f50a1f3c4d302ec15d 100644 (file)
@@ -1 +1 @@
-bcec155e0d6c6b17ae09d5a366c080723d01ff40dbc1a0ad0bb669a91db1b850
\ No newline at end of file
+5216bfb73f1a49bdd879d470de139bf46a212474eaf6f38ad2390536d66a2afd
\ No newline at end of file
index 35f5f5c368dcf215b128dbd86b927e3011be709b..8eab3823c1a24fbc7657a0e73751082e14db53d4 100644 (file)
@@ -1739,15 +1739,6 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
   }else{
     pPk = sqlite3PrimaryKeyIndex(pTab);
 
-    /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
-    ** table entry. This is only required if currently generating VDBE
-    ** code for a CREATE TABLE (not when parsing one as part of reading
-    ** a database schema).  */
-    if( v ){
-      assert( db->init.busy==0 );
-      sqlite3VdbeChangeOpcode(v, pPk->tnum, OP_Goto);
-    }
-
     /*
     ** Remove all redundant columns from the PRIMARY KEY.  For example, change
     ** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)".  Later
@@ -1767,6 +1758,15 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
   if( !db->init.imposterTable ) pPk->uniqNotNull = 1;
   nPk = pPk->nKeyCol;
 
+  /* Bypass the creation of the PRIMARY KEY btree and the sqlite_master
+  ** table entry. This is only required if currently generating VDBE
+  ** code for a CREATE TABLE (not when parsing one as part of reading
+  ** a database schema).  */
+  if( v && pPk->tnum>0 ){
+    assert( db->init.busy==0 );
+    sqlite3VdbeChangeOpcode(v, pPk->tnum, OP_Goto);
+  }
+
   /* The root page of the PRIMARY KEY is the table root page */
   pPk->tnum = pTab->tnum;
 
index 0c77773abb3e7812fb19c5f8ff76c8a91c835f6b..c7899cfb39e2033f4a22089f80b661c36460b083 100644 (file)
@@ -328,5 +328,19 @@ do_catchsql_test 7.3 {
   ) WITHOUT ROWID;
 } {1 {no such column: rowid}}
 
+# 2017-07-30: OSSFuzz discovered that an extra entry was being
+# added in the sqlite_master table for an "INTEGER PRIMARY KEY UNIQUE"
+# WITHOUT ROWID table.  Make sure this has now been fixed.
+#
+db close
+sqlite3 db :memory:
+do_execsql_test 8.1 {
+  CREATE TABLE t1(x INTEGER PRIMARY KEY UNIQUE, b) WITHOUT ROWID;
+  CREATE INDEX t1x ON t1(x);
+  INSERT INTO t1(x,b) VALUES('funny','buffalo');
+  SELECT type, name, '|' FROM sqlite_master;
+} {table t1 | index t1x |}
+
+
   
 finish_test