Return an SQLITE_CONSTRAINT error if an attempt is made to insert duplicate

entries into a zip archive.

FossilOrigin-Name: 1f099b2b45074c89eeff8ff241aa49489c95c2221b25c305fcda670ebf63fb4e
This commit is contained in:
dan 2018-01-10 17:37:58 +00:00
parent f2ed70e4de
commit 4bfd182939
4 changed files with 60 additions and 9 deletions

View File

@ -1033,7 +1033,7 @@ static int zipfileLoadDirectory(ZipfileTab *pTab){
}else{
memset(pNew, 0, sizeof(ZipfileEntry));
pNew->zPath = (char*)&pNew[1];
memcpy(pNew->zPath, &aBuf[ZIPFILE_CDS_FIXED_SZ], nFile);
memcpy(pNew->zPath, &aRec[ZIPFILE_CDS_FIXED_SZ], nFile);
pNew->zPath[nFile] = '\0';
pNew->aCdsEntry = (u8*)&pNew->zPath[nFile+1];
pNew->nCdsEntry = ZIPFILE_CDS_FIXED_SZ+nFile+nExtra+nComment;
@ -1189,6 +1189,18 @@ static int zipfileGetMode(
return SQLITE_ERROR;
}
/*
** Both (const char*) arguments point to nul-terminated strings. Argument
** nB is the value of strlen(zB). This function returns 0 if the strings are
** identical, ignoring any trailing '/' character in either path. */
static int zipfileComparePath(const char *zA, const char *zB, int nB){
int nA = strlen(zA);
if( zA[nA-1]=='/' ) nA--;
if( zB[nB-1]=='/' ) nB--;
if( nA==nB && memcmp(zA, zB, nA)==0 ) return 0;
return 1;
}
/*
** xUpdate method.
*/
@ -1321,6 +1333,17 @@ static int zipfileUpdate(
}
}
/* Check that we're not inserting a duplicate entry */
if( rc==SQLITE_OK ){
ZipfileEntry *p;
for(p=pTab->pFirstEntry; p; p=p->pNext){
if( zipfileComparePath(p->zPath, zPath, nPath)==0 ){
rc = SQLITE_CONSTRAINT;
break;
}
}
}
if( rc==SQLITE_OK ){
/* Create the new CDS record. */
memset(&cds, 0, sizeof(cds));

View File

@ -1,5 +1,5 @@
C Have\sthe\szipfile\smodule\sautomatically\sappend\s"/"\sto\sdirectory\snames\sthat\sdo\nnot\salready\send\swith\ssuch\sa\scharacter.\sThis\sis\srequired\sfor\sinfo-zip\ncompatibility.
D 2018-01-10T16:30:40.654
C Return\san\sSQLITE_CONSTRAINT\serror\sif\san\sattempt\sis\smade\sto\sinsert\sduplicate\nentries\sinto\sa\szip\sarchive.
D 2018-01-10T17:37:58.434
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in 12b6daa4bdb03fa87da27cbc205ff88ace645475b5be79414a3038b68ade14cb
@ -303,7 +303,7 @@ F ext/misc/vfsstat.c bf10ef0bc51e1ad6756629e1edb142f7a8db1178
F ext/misc/vtablog.c 31d0d8f4406795679dcd3a67917c213d3a2a5fb3ea5de35f6e773491ed7e13c9
F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd
F ext/misc/wholenumber.c 784b12543d60702ebdd47da936e278aa03076212
F ext/misc/zipfile.c 08ec2ee0093d7a91d66db4ce1d8543cc4c19fc3fb57ee113ef49f95b8613f501
F ext/misc/zipfile.c 00d78e61f0b0a7f51a4d5ffef302ef840336f09d75a97a8e0be1fabf048511b8
F ext/rbu/rbu.c ea7d1b7eb44c123a2a619332e19fe5313500705c4a58aaa1887905c0d83ffc2e
F ext/rbu/rbu1.test 43836fac8c7179a358eaf38a8a1ef3d6e6285842
F ext/rbu/rbu10.test 1846519a438697f45e9dcb246908af81b551c29e1078d0304fae83f1fed7e9ee
@ -1598,7 +1598,7 @@ F test/wordcount.c cb589cec469a1d90add05b1f8cee75c7210338d87a5afd65260ed5c0f4bbf
F test/writecrash.test f1da7f7adfe8d7f09ea79b42e5ca6dcc41102f27f8e334ad71539501ddd910cc
F test/zeroblob.test 3857870fe681b8185654414a9bccfde80b62a0fa
F test/zerodamage.test e59a56443d6298ecf7435f618f0b27654f0c849e
F test/zipfile.test 355e499ed4e8e0081e136510d8a7895496ee1196be10905e5dd61b0f7fdda39e
F test/zipfile.test e7132ca60031ca5d1df684cf644952bb3f253de3671a5b502780c5de3126a453
F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5
F tool/GetTclKit.bat 8995df40c4209808b31f24de0b58f90930239a234f7591e3675d45bfbb990c5d
F tool/Replace.cs 02c67258801c2fb5f63231e0ac0f220b4b36ba91
@ -1697,7 +1697,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 c42c734f11c58724f5d8b32cb1c92e274be350028868d6ed045b2cfd274c64e7
R f9e0f45080131d91f8369d2321791b35
P 94bc3c60e7d2ec849b90444b06e3057ed645edf3af334f2737252960602868e5
R 9dfa6dcaeef4eb497b2c9753cb4a2823
U dan
Z be2a3cd4c41b45eb12aa75b434fd5e7e
Z 2990c2df8ab5dd5a7f9266ba3fc45276

View File

@ -1 +1 @@
94bc3c60e7d2ec849b90444b06e3057ed645edf3af334f2737252960602868e5
1f099b2b45074c89eeff8ff241aa49489c95c2221b25c305fcda670ebf63fb4e

View File

@ -133,5 +133,33 @@ if {$::tcl_platform(platform)=="unix"} {
} {abcdefghijklmnop}
}
#-------------------------------------------------------------------------
reset_db
forcedelete test.zip
load_static_extension db zipfile
do_execsql_test 3.0 {
CREATE VIRTUAL TABLE temp.x1 USING zipfile('test.zip');
INSERT INTO x1(name, data) VALUES('dir1/', NULL);
INSERT INTO x1(name, data) VALUES('file1', '1234');
INSERT INTO x1(name, data) VALUES('dir1/file2', '5678');
}
foreach {tn fname} {
1 dir1
2 file1
3 dir1/file2
} {
do_catchsql_test 3.1.$tn.0 {
INSERT INTO x1(name, data) VALUES($fname, NULL);
} {1 {constraint failed}}
do_catchsql_test 3.1.$tn.1 {
INSERT INTO x1(name, data) VALUES($fname || '/', NULL);
} {1 {constraint failed}}
do_catchsql_test 3.1.$tn.2 {
INSERT INTO x1(name, data) VALUES($fname, 'abcd');
} {1 {constraint failed}}
}
finish_test