From: drh Date: Sat, 10 Mar 2018 13:21:41 +0000 (+0000) Subject: Improved error messages from the zipfile extension. X-Git-Tag: version-3.23.0~65 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=41a6f2cb6d07fdab445ec93bb8ce92e348134f0e;p=thirdparty%2Fsqlite.git Improved error messages from the zipfile extension. FossilOrigin-Name: f634a7e386918b829389f20c330d312315fdd61125cd2c5f66cf17a5d74bce49 --- diff --git a/ext/misc/zipfile.c b/ext/misc/zipfile.c index ae0e54813e..96a2815951 100644 --- a/ext/misc/zipfile.c +++ b/ext/misc/zipfile.c @@ -473,9 +473,17 @@ static int zipfileClose(sqlite3_vtab_cursor *cur){ ** Set the error message for the virtual table associated with cursor ** pCsr to the results of vprintf(zFmt, ...). */ -static void zipfileSetErrmsg(ZipfileCsr *pCsr, const char *zFmt, ...){ +static void zipfileTableErr(ZipfileTab *pTab, const char *zFmt, ...){ va_list ap; va_start(ap, zFmt); + sqlite3_free(pTab->base.zErrMsg); + pTab->base.zErrMsg = sqlite3_vmprintf(zFmt, ap); + va_end(ap); +} +static void zipfileCursorErr(ZipfileCsr *pCsr, const char *zFmt, ...){ + va_list ap; + va_start(ap, zFmt); + sqlite3_free(pCsr->base.pVtab->zErrMsg); pCsr->base.pVtab->zErrMsg = sqlite3_vmprintf(zFmt, ap); va_end(ap); } @@ -1238,7 +1246,7 @@ static int zipfileFilter( if( pTab->zFile ){ zFile = pTab->zFile; }else if( idxNum==0 ){ - zipfileSetErrmsg(pCsr, "zipfile() function requires an argument"); + zipfileCursorErr(pCsr, "zipfile() function requires an argument"); return SQLITE_ERROR; }else if( sqlite3_value_type(argv[0])==SQLITE_BLOB ){ const u8 *aBlob = (const u8*)sqlite3_value_blob(argv[0]); @@ -1256,7 +1264,7 @@ static int zipfileFilter( if( 0==pTab->pWriteFd && 0==bInMemory ){ pCsr->pFile = fopen(zFile, "rb"); if( pCsr->pFile==0 ){ - zipfileSetErrmsg(pCsr, "cannot open file: %s", zFile); + zipfileCursorErr(pCsr, "cannot open file: %s", zFile); rc = SQLITE_ERROR; }else{ rc = zipfileReadEOCD(pTab, 0, 0, pCsr->pFile, &pCsr->eocd); @@ -1405,6 +1413,7 @@ static int zipfileGetMode( if( ((mode & S_IFDIR)==0)==bIsDir ){ /* The "mode" attribute is a directory, but data has been specified. ** Or vice-versa - no data but "mode" is a file or symlink. */ + *pzErr = sqlite3_mprintf("zipfile: mode does not match data"); return SQLITE_CONSTRAINT; } *pMode = mode; @@ -1535,9 +1544,12 @@ static int zipfileUpdate( if( nVal>1 ){ /* Check that "sz" and "rawdata" are both NULL: */ - if( sqlite3_value_type(apVal[5])!=SQLITE_NULL - || sqlite3_value_type(apVal[6])!=SQLITE_NULL - ){ + if( sqlite3_value_type(apVal[5])!=SQLITE_NULL ){ + zipfileTableErr(pTab, "sz must be NULL"); + rc = SQLITE_CONSTRAINT; + } + if( sqlite3_value_type(apVal[6])!=SQLITE_NULL ){ + zipfileTableErr(pTab, "rawdata must be NULL"); rc = SQLITE_CONSTRAINT; } @@ -1557,6 +1569,7 @@ static int zipfileUpdate( pData = aIn; nData = nIn; if( iMethod!=0 && iMethod!=8 ){ + zipfileTableErr(pTab, "unknown compression method: %d", iMethod); rc = SQLITE_CONSTRAINT; }else{ if( bAuto || iMethod ){ @@ -1603,6 +1616,7 @@ static int zipfileUpdate( ZipfileEntry *p; for(p=pTab->pFirstEntry; p; p=p->pNext){ if( zipfileComparePath(p->cds.zFile, zPath, nPath)==0 ){ + zipfileTableErr(pTab, "duplicate name: \"%s\"", zPath); rc = SQLITE_CONSTRAINT; break; } diff --git a/manifest b/manifest index 22ccaac86e..43bf7a1064 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\sharmless\sleft-shifts\sof\snegative\snumbers\sin\sthe\szipfile\sextension\nwhen\sbuilding\sZIP\sarchives\sof\sfiles\swith\spre-DOS\sdates. -D 2018-03-10T12:53:20.192 +C Improved\serror\smessages\sfrom\sthe\szipfile\sextension. +D 2018-03-10T13:21:41.393 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7016fc56c6b9bfe5daac4f34be8be38d8c0b5fab79ccbfb764d3b23bf1c6fff3 @@ -304,7 +304,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 1a234c4e822a11e2e5aa6d402309b527e34e0813dba1b34d2723f050862864d2 +F ext/misc/zipfile.c 1e5a27b6cf84171af95a763f21db990f690dc13eed42b84bc2e5b90eca2e9e1c F ext/misc/zorder.c b0ff58fa643afa1d846786d51ea8d5c4b6b35aa0254ab5a82617db92f3adda64 F ext/rbu/rbu.c ea7d1b7eb44c123a2a619332e19fe5313500705c4a58aaa1887905c0d83ffc2e F ext/rbu/rbu1.test 43836fac8c7179a358eaf38a8a1ef3d6e6285842 @@ -1611,7 +1611,7 @@ F test/wordcount.c cb589cec469a1d90add05b1f8cee75c7210338d87a5afd65260ed5c0f4bbf F test/writecrash.test f1da7f7adfe8d7f09ea79b42e5ca6dcc41102f27f8e334ad71539501ddd910cc F test/zeroblob.test 3857870fe681b8185654414a9bccfde80b62a0fa F test/zerodamage.test 9c41628db7e8d9e8a0181e59ea5f189df311a9f6ce99cc376dc461f66db6f8dc -F test/zipfile.test 44aa8af115cc3e8c905468768dc761260650a8fdfca57e10f9818f5f8008d340 +F test/zipfile.test d4efc5547c2105fdc54b61d6b167ddd5a1a4b9b70993b402d7f20836b1eceef2 F test/zipfile2.test 67d5f08a202796d4b7a71dfa4b8dcb74aa7a9d1f42c5f17bedff9855c1ba7aa5 F test/zipfilefault.test 44d4d7a7f7cca7521d569d7f71026b241d65a6b1757aa409c1a168827edbbc2c F tool/GetFile.cs a15e08acb5dd7539b75ba23501581d7c2b462cb5 @@ -1712,7 +1712,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 2a4493f4ad2d09c1097e98e7086623669f3f252571884d515e51a98b1c6855e1 -R b996514daf8ccd4118140541121adf76 +P 16bba8650cc24a0fd606944422bb31f2b8bdbe0a5a483678989e400b751eab4d +R b511ebdd2c624217586a293149d65f0f U drh -Z 3a20f1e017065f65b485c6880eea221e +Z 5119f4749bf9fb79b4a57766ed83d519 diff --git a/manifest.uuid b/manifest.uuid index 22a9a1cccd..7032bdb217 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -16bba8650cc24a0fd606944422bb31f2b8bdbe0a5a483678989e400b751eab4d \ No newline at end of file +f634a7e386918b829389f20c330d312315fdd61125cd2c5f66cf17a5d74bce49 \ No newline at end of file diff --git a/test/zipfile.test b/test/zipfile.test index 2bb3f07892..18f7b25bfd 100644 --- a/test/zipfile.test +++ b/test/zipfile.test @@ -150,19 +150,19 @@ do_execsql_test 1.0 { do_catchsql_test 1.1.0.1 { INSERT INTO zz(name, mode, mtime, sz, rawdata, method) VALUES('f.txt', '-rw-r--r--', 1000000000, 5, 'abcde', 0); -} {1 {constraint failed}} +} {1 {rawdata must be NULL}} do_catchsql_test 1.1.0.2 { INSERT INTO zz(name, mtime, sz, data, method) VALUES('g.txt', 1000000002, 5, '12345', 0); -} {1 {constraint failed}} +} {1 {sz must be NULL}} do_catchsql_test 1.1.0.3 { INSERT INTO zz(name, mtime, rawdata, method) VALUES('g.txt', 1000000002, '12345', 0); -} {1 {constraint failed}} +} {1 {rawdata must be NULL}} do_catchsql_test 1.1.0.4 { INSERT INTO zz(name, data, method) VALUES('g.txt', '12345', 7); -} {1 {constraint failed}} +} {1 {unknown compression method: 7}} do_execsql_test 1.1.1 { INSERT INTO zz(name, mode, mtime, data, method) @@ -287,7 +287,7 @@ do_execsql_test 1.6.6 { do_catchsql_test 1.6.7 { UPDATE zz SET data=NULL WHERE name='i.txt' -} {1 {constraint failed}} +} {1 {zipfile: mode does not match data}} do_execsql_test 1.6.8 { SELECT name, mode, mtime, data, method FROM zipfile('test.zip'); } { @@ -398,13 +398,13 @@ foreach {tn fname} { } { do_catchsql_test 3.1.$tn.0 { INSERT INTO x1(name, data) VALUES($fname, NULL); - } {1 {constraint failed}} + } [list 1 "duplicate name: \"$fname/\""] do_catchsql_test 3.1.$tn.1 { INSERT INTO x1(name, data) VALUES($fname || '/', NULL); - } {1 {constraint failed}} + } [list 1 "duplicate name: \"$fname/\""] do_catchsql_test 3.1.$tn.2 { INSERT INTO x1(name, data) VALUES($fname, 'abcd'); - } {1 {constraint failed}} + } [list 1 "duplicate name: \"$fname\""] } do_catchsql_test 3.2 { @@ -637,4 +637,3 @@ do_execsql_test 9.0 { SELECT name FROM zipfile((SELECT zipfile(nm, NULL) FROM src)) } {dir1/ dir2/ dir3/ dir4/ /} finish_test -