From: drh Date: Mon, 31 Jul 2017 12:19:40 +0000 (+0000) Subject: Correctly handle an "INTEGER PRIMARY KEY UNIQUE" column in a WITHOUT ROWID X-Git-Tag: version-3.19.4~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d811aaac92b661dc988c21f365283df3c9262930;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 check-in [5216bfb73f1a49bdd8] FossilOrigin-Name: 322a2ede6dae04a8e7e07fe0d99040f38f025fa142bd0493025ad6d65c2aaf6d --- diff --git a/manifest b/manifest index e48f5145c7..ecf32ef85d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Increase\sthe\sversion\snumber\sto\s3.19.4 -D 2017-07-31T12:07:52.249 +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\ncheck-in\s[5216bfb73f1a49bdd8] +D 2017-07-31T12:19:40.621 F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 8eeb80162074004e906b53d7340a12a14c471a83743aab975947e95ce061efcc @@ -349,7 +349,7 @@ F src/btmutex.c 0e9ce2d56159b89b9bc8e197e023ee11e39ff8ca F src/btree.c de57bf3f205082eb4ad8c923af7ecd1d10c4f15656f6a38038a3bd9b8ac3fc2a F src/btree.h 80f518c0788be6cec8d9f8e13bd8e380df299d2b5e4ac340dc887b0642647cfc F src/btreeInt.h a392d353104b4add58b4a59cb185f5d5693dde832c565b77d8d4c343ed98f610 -F src/build.c 4026a9c554b233e50c5e9ad46963e676cf54dd2306d952aa1eaa07a1bc9ce14f +F src/build.c ce2ee94ac2a056414c5ebb005910500dce2f119fc65a101b401074a253ffa144 F src/callback.c 2e76147783386374bf01b227f752c81ec872d730 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e F src/ctime.c 47d91a25ad8f199a71a5b1b7b169d6dd0d6e98c5719eca801568798743d1161c @@ -1480,7 +1480,7 @@ F test/with1.test cef099a491eac9874f2c28bd2dc86394fb3e47b3 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 @@ -1580,7 +1580,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 24c9cd460051781f7e6417b7e205274319258f061ae1191a6c5ff5af615439c9 -R 09acb00a9d7b7d8c183679387523a2cd +P b77f297d38426a4d6da6d957f652d215f11327c09ed0f1d7e26306918dfa70ea +Q +5216bfb73f1a49bdd879d470de139bf46a212474eaf6f38ad2390536d66a2afd +R eb07fcc768c6f4ff6ae20a5819466310 U drh -Z ea3844bfc66744f4803ecf14d2918808 +Z 75dcf6651c63dcff0accc15625ce1b08 diff --git a/manifest.uuid b/manifest.uuid index e55199d631..dc654207b4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b77f297d38426a4d6da6d957f652d215f11327c09ed0f1d7e26306918dfa70ea \ No newline at end of file +322a2ede6dae04a8e7e07fe0d99040f38f025fa142bd0493025ad6d65c2aaf6d \ No newline at end of file diff --git a/src/build.c b/src/build.c index e04406d857..f1a6aed24d 100644 --- a/src/build.c +++ b/src/build.c @@ -1734,15 +1734,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 @@ -1762,6 +1753,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