From: drh Date: Sun, 30 Jul 2017 20:30:36 +0000 (+0000) Subject: Correctly handle an "INTEGER PRIMARY KEY UNIQUE" column in a WITHOUT ROWID X-Git-Tag: version-3.20.0~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=76b198139c47ca263080f68428e980718b2b412c;p=thirdparty%2Fsqlite.git Correctly handle an "INTEGER PRIMARY KEY UNIQUE" column in a WITHOUT ROWID table. This is a fix for ticket [bc115541132dad136] cherry-picked from [5216bfb73f1a49bdd]. FossilOrigin-Name: 5c8cb1ff5da872fb5ab3f77f678b9df3b68525433f6d5d918f2911a5622bdd14 --- diff --git a/manifest b/manifest index 134b3591dd..256c4f777d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\spunctuation\stypo\sin\sthe\sdocumentation\sfor\ssqlite3_step().\s\sNo\schanges\sto\ncode. -D 2017-07-28T12:20:39.570 +C Correctly\shandle\san\s"INTEGER\sPRIMARY\sKEY\sUNIQUE"\scolumn\sin\sa\sWITHOUT\sROWID\ntable.\s\sThis\sis\sa\sfix\sfor\sticket\s[bc115541132dad136]\scherry-picked\sfrom\n[5216bfb73f1a49bdd]. +D 2017-07-30T20:30:36.264 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 74108007d286232fb4290464ee5452fa860c26215f8caa0e6c7cbf69a6fafe8f +F src/build.c c3837ad57cea1351cd824a646836d2bb678f264ae160d691b632d495c8be2f5b F src/callback.c 8e14b60d1ed1c87c02cb5f121ecda99224f2aea6524a77ee6f72c9b5c7110f84 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,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P d891a2a00a34b6726624c66273f0f3388da9de6a771771c94b6e8a970dd9cdb9 -R 9ec3bbe0ae2e859fe828a8508fe2f59a +P c965b757bb5faed20d44d442e673cdad40dd12726f4f968105636501a021e41c +Q +5216bfb73f1a49bdd879d470de139bf46a212474eaf6f38ad2390536d66a2afd +R 79592fa95afa9126178bbce2b79db007 U drh -Z e4a89ba161849293c6b16a25df952da7 +Z f693467a5eb5af0544217307e1418286 diff --git a/manifest.uuid b/manifest.uuid index 1979866866..45219cb6be 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c965b757bb5faed20d44d442e673cdad40dd12726f4f968105636501a021e41c \ No newline at end of file +5c8cb1ff5da872fb5ab3f77f678b9df3b68525433f6d5d918f2911a5622bdd14 \ No newline at end of file diff --git a/src/build.c b/src/build.c index cc05bdfb90..f5e572eab5 100644 --- a/src/build.c +++ b/src/build.c @@ -1738,15 +1738,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 @@ -1766,6 +1757,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; diff --git a/test/without_rowid1.test b/test/without_rowid1.test index 0c77773abb..c7899cfb39 100644 --- a/test/without_rowid1.test +++ b/test/without_rowid1.test @@ -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