Fix a zipfile problem with adding new directories to an archive.

FossilOrigin-Name: 5fed67033c9dd4492bf8cfcf98874284581f448d8cc84fa5470dde239f218375
This commit is contained in:
dan 2018-01-09 10:29:34 +00:00
parent cc234a4b66
commit 128011a258
4 changed files with 78 additions and 30 deletions

View File

@ -1152,11 +1152,16 @@ static int zipfileAppendEntry(
return rc; return rc;
} }
static int zipfileGetMode(ZipfileTab *pTab, sqlite3_value *pVal, u32 *pMode){ static int zipfileGetMode(
ZipfileTab *pTab,
sqlite3_value *pVal,
u32 defaultMode, /* Value to use if pVal IS NULL */
u32 *pMode
){
const char *z = (const char*)sqlite3_value_text(pVal); const char *z = (const char*)sqlite3_value_text(pVal);
u32 mode = 0; u32 mode = 0;
if( z==0 ){ if( z==0 ){
mode = S_IFREG + 0644; /* -rw-r--r-- */ mode = defaultMode;
}else if( z[0]>=0 && z[0]<=9 ){ }else if( z[0]>=0 && z[0]<=9 ){
mode = (unsigned int)sqlite3_value_int(pVal); mode = (unsigned int)sqlite3_value_int(pVal);
}else{ }else{
@ -1208,6 +1213,10 @@ static int zipfileUpdate(
u8 *pFree = 0; /* Free this */ u8 *pFree = 0; /* Free this */
ZipfileCDS cds; /* New Central Directory Structure entry */ ZipfileCDS cds; /* New Central Directory Structure entry */
int bIsDir = 0;
int mNull;
assert( pTab->zFile ); assert( pTab->zFile );
assert( pTab->pWriteFd ); assert( pTab->pWriteFd );
@ -1223,20 +1232,17 @@ static int zipfileUpdate(
if( nVal==1 ) return SQLITE_OK; if( nVal==1 ) return SQLITE_OK;
} }
zPath = (const char*)sqlite3_value_text(apVal[2]); mNull = (sqlite3_value_type(apVal[5])==SQLITE_NULL ? 0x0 : 0x8) /* sz */
nPath = (int)strlen(zPath); + (sqlite3_value_type(apVal[6])==SQLITE_NULL ? 0x0 : 0x4) /* rawdata */
rc = zipfileGetMode(pTab, apVal[3], &mode); + (sqlite3_value_type(apVal[7])==SQLITE_NULL ? 0x0 : 0x2) /* data */
if( rc!=SQLITE_OK ) return rc; + (sqlite3_value_type(apVal[8])==SQLITE_NULL ? 0x0 : 0x1); /* method */
if( sqlite3_value_type(apVal[4])==SQLITE_NULL ){ if( mNull==0x00 ){
mTime = (sqlite3_int64)time(0); /* All four are NULL - this must be a directory */
}else{ bIsDir = 1;
mTime = sqlite3_value_int64(apVal[4]);
} }
else if( mNull==0x2 || mNull==0x3 ){
if( sqlite3_value_type(apVal[5])==SQLITE_NULL /* sz */ /* Value specified for "data", and possibly "method". This must be
&& sqlite3_value_type(apVal[6])==SQLITE_NULL /* rawdata */ ** a regular file or a symlink. */
&& sqlite3_value_type(apVal[7])!=SQLITE_NULL /* data */
){
const u8 *aIn = sqlite3_value_blob(apVal[7]); const u8 *aIn = sqlite3_value_blob(apVal[7]);
int nIn = sqlite3_value_bytes(apVal[7]); int nIn = sqlite3_value_bytes(apVal[7]);
int bAuto = sqlite3_value_type(apVal[8])==SQLITE_NULL; int bAuto = sqlite3_value_type(apVal[8])==SQLITE_NULL;
@ -1257,12 +1263,10 @@ static int zipfileUpdate(
} }
} }
} }
}else }
if( sqlite3_value_type(apVal[5])!=SQLITE_NULL /* sz */ else if( mNull==0x0D ){
&& sqlite3_value_type(apVal[6])!=SQLITE_NULL /* rawdata */ /* Values specified for "sz", "rawdata" and "method". In other words,
&& sqlite3_value_type(apVal[7])==SQLITE_NULL /* data */ ** pre-compressed data is being inserted. */
&& sqlite3_value_type(apVal[8])!=SQLITE_NULL /* method */
){
pData = sqlite3_value_blob(apVal[6]); pData = sqlite3_value_blob(apVal[6]);
nData = sqlite3_value_bytes(apVal[6]); nData = sqlite3_value_bytes(apVal[6]);
sz = sqlite3_value_int(apVal[5]); sz = sqlite3_value_int(apVal[5]);
@ -1273,10 +1277,32 @@ static int zipfileUpdate(
); );
rc = SQLITE_ERROR; rc = SQLITE_ERROR;
} }
}else{ }
else{
rc = SQLITE_CONSTRAINT; rc = SQLITE_CONSTRAINT;
} }
if( rc==SQLITE_OK ){
rc = zipfileGetMode(pTab, apVal[3],
(bIsDir ? (S_IFDIR + 0755) : (S_IFREG + 0644)), &mode
);
if( rc==SQLITE_OK && (bIsDir == ((mode & S_IFDIR)==0)) ){
/* The "mode" attribute is a directory, but data has been specified.
** Or vice-versa - no data but "mode" is a file or symlink. */
rc = SQLITE_CONSTRAINT;
}
}
if( rc==SQLITE_OK ){
zPath = (const char*)sqlite3_value_text(apVal[2]);
nPath = (int)strlen(zPath);
if( sqlite3_value_type(apVal[4])==SQLITE_NULL ){
mTime = (sqlite3_int64)time(0);
}else{
mTime = sqlite3_value_int64(apVal[4]);
}
}
if( rc==SQLITE_OK ){ if( rc==SQLITE_OK ){
/* Create the new CDS record. */ /* Create the new CDS record. */
memset(&cds, 0, sizeof(cds)); memset(&cds, 0, sizeof(cds));

View File

@ -1,5 +1,5 @@
C Fix\sa\sproblem\sin\szipfile.c\sfound\sby\s-fsanitize. C Fix\sa\szipfile\sproblem\swith\sadding\snew\sdirectories\sto\san\sarchive.
D 2018-01-09T07:16:51.597 D 2018-01-09T10:29:34.950
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F Makefile.in 12b6daa4bdb03fa87da27cbc205ff88ace645475b5be79414a3038b68ade14cb F Makefile.in 12b6daa4bdb03fa87da27cbc205ff88ace645475b5be79414a3038b68ade14cb
@ -303,7 +303,7 @@ F ext/misc/vfsstat.c bf10ef0bc51e1ad6756629e1edb142f7a8db1178
F ext/misc/vtablog.c 31d0d8f4406795679dcd3a67917c213d3a2a5fb3ea5de35f6e773491ed7e13c9 F ext/misc/vtablog.c 31d0d8f4406795679dcd3a67917c213d3a2a5fb3ea5de35f6e773491ed7e13c9
F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd
F ext/misc/wholenumber.c 784b12543d60702ebdd47da936e278aa03076212 F ext/misc/wholenumber.c 784b12543d60702ebdd47da936e278aa03076212
F ext/misc/zipfile.c b694574b715dc6ea353c90e0fa31f30faa2121e59bd9e1ae40f874300114a84f F ext/misc/zipfile.c eaab322dd4b24199b0c6bdfbf866d1d04f7e93f46b4b5ca8436edadece54b03f
F ext/rbu/rbu.c ea7d1b7eb44c123a2a619332e19fe5313500705c4a58aaa1887905c0d83ffc2e F ext/rbu/rbu.c ea7d1b7eb44c123a2a619332e19fe5313500705c4a58aaa1887905c0d83ffc2e
F ext/rbu/rbu1.test 43836fac8c7179a358eaf38a8a1ef3d6e6285842 F ext/rbu/rbu1.test 43836fac8c7179a358eaf38a8a1ef3d6e6285842
F ext/rbu/rbu10.test 1846519a438697f45e9dcb246908af81b551c29e1078d0304fae83f1fed7e9ee F ext/rbu/rbu10.test 1846519a438697f45e9dcb246908af81b551c29e1078d0304fae83f1fed7e9ee
@ -1598,7 +1598,7 @@ F test/wordcount.c cb589cec469a1d90add05b1f8cee75c7210338d87a5afd65260ed5c0f4bbf
F test/writecrash.test f1da7f7adfe8d7f09ea79b42e5ca6dcc41102f27f8e334ad71539501ddd910cc F test/writecrash.test f1da7f7adfe8d7f09ea79b42e5ca6dcc41102f27f8e334ad71539501ddd910cc
F test/zeroblob.test 3857870fe681b8185654414a9bccfde80b62a0fa F test/zeroblob.test 3857870fe681b8185654414a9bccfde80b62a0fa
F test/zerodamage.test e59a56443d6298ecf7435f618f0b27654f0c849e F test/zerodamage.test e59a56443d6298ecf7435f618f0b27654f0c849e
F test/zipfile.test ad4278e1ebb1c7bc0fcd7f9b47df18916b9e8f841165119865a5a6a095a2d0ba F test/zipfile.test de2ee377705999bcd7391fb742d6b833ffab4f21dab1d4f484098a66d60eb4fb
F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5 F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5
F tool/GetTclKit.bat 8995df40c4209808b31f24de0b58f90930239a234f7591e3675d45bfbb990c5d F tool/GetTclKit.bat 8995df40c4209808b31f24de0b58f90930239a234f7591e3675d45bfbb990c5d
F tool/Replace.cs 02c67258801c2fb5f63231e0ac0f220b4b36ba91 F tool/Replace.cs 02c67258801c2fb5f63231e0ac0f220b4b36ba91
@ -1697,7 +1697,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P cba0206a15f30313e16a08634995ebfd5d325d83affb859a215e72509f539b4e P 4fe697fa6c2b45aec60c33eff1ce2ea97b8a2ca124ef0c0059930269d25cdb2e
R 8cb58dd5bd00b76b67672fc7e3030d3c R e226ce112b5f76c5d01abec530de4ed7
U dan U dan
Z bb6663f307bb629de0b63290f8475ee1 Z 162125bc358610b2bc72c2a7b07e618b

View File

@ -1 +1 @@
4fe697fa6c2b45aec60c33eff1ce2ea97b8a2ca124ef0c0059930269d25cdb2e 5fed67033c9dd4492bf8cfcf98874284581f448d8cc84fa5470dde239f218375

View File

@ -79,5 +79,27 @@ do_execsql_test 1.6.0 {
SELECT name FROM zz; SELECT name FROM zz;
} {f.txt h.txt i.txt} } {f.txt h.txt i.txt}
#-------------------------------------------------------------------------
db close
forcedelete test.zip
reset_db
load_static_extension db zipfile
do_execsql_test 2.1 {
CREATE VIRTUAL TABLE zzz USING zipfile('test.zip');
INSERT INTO zzz(name, mode) VALUES('dirname', 'drwxr-xr-x');
SELECT name, mode, data FROM zzz;
} {dirname 16877 {}}
do_execsql_test 2.2 {
INSERT INTO zzz(name, data) VALUES('dirname2', NULL);
INSERT INTO zzz(name, data) VALUES('dirname2/file1.txt', 'abcdefghijklmnop');
SELECT name, mode, data FROM zzz;
} {
dirname 16877 {}
dirname2 16877 {}
dirname2/file1.txt 33188 abcdefghijklmnop
}
finish_test finish_test