From: drh <> Date: Thu, 11 Jun 2026 23:18:21 +0000 (+0000) Subject: Enhance the ".ar -x" command to add the undocumented --debug option and X-Git-Tag: release~44 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d7436d6cf177a5d9731ec1c63b844b8b35ba51e1;p=thirdparty%2Fsqlite.git Enhance the ".ar -x" command to add the undocumented --debug option and to give enhanced robustness to deliberately malformed archives. FossilOrigin-Name: cd7bb77fdf6c7bad89068d4138f74a950b67a87cc1582de6172b3547519387cb --- diff --git a/manifest b/manifest index e93083395d..9b42df92f0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improved\sdetection\sof\scorrupt\snode\sIDs\sin\sRTree\sshadow\stables. -D 2026-06-11T01:37:00.208 +C Enhance\sthe\s".ar\s-x"\scommand\sto\sadd\sthe\sundocumented\s--debug\soption\sand\nto\sgive\senhanced\srobustness\sto\sdeliberately\smalformed\sarchives. +D 2026-06-11T23:18:21.338 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -736,7 +736,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c F src/resolve.c f5a780a7b604d43b78bca290cace7479bca0c7d8ef9ce855830d9498b975baec F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 5c3a5e3c1e6c3f8ccabeb414e18dce64e6f3e797de225ee93034f2c9e76f289c -F src/shell.c.in 423a188b63a2fbdb968bd4af23b50e4c11522c2594f70d35db785c267303d933 +F src/shell.c.in 62559fae745668a0f3d229360844b37d5a7a49b50edbce4a762cafc784e86ba3 F src/sqlite.h.in e2915e4a86d5e0783afb5cb72411df38d987c7f3c5aa2d5441b8e74d30b649d8 F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479 F src/sqlite3ext.h 1b7a0ee438bb5c2896d0609c537e917d8057b3340f6ad004d2de44f03e3d3cca @@ -2200,9 +2200,11 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee F tool/warnings.sh a554d13f6e5cf3760f041b87939e3d616ec6961859c3245e8ef701d1eafc2ca2 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c -P a6eb055c35f091a8e864c1de3387d389e2bd3025c32596c0b7a78ebdf091898b -Q +e01a185a699d0c4ad2341ce2114bc826f02768735cef67179a1127229a073d03 -R 1d442f9fa6ba5dbe84932cad0535b370 +P 4e875ae5c3f0cb28fd40be9f1327d7496f95a55785cad68cb37472e4d1c2e6fd +Q +37a80d20fe1948db15ac72432ed7bf3d573c80807fe0a58c58440647e3c34ab8 +Q +3a040ffc47fa3e38b36716587c56d9b071d9c69d9daaa9cf0ef6baa654419ab5 +Q +6149b938c7a1e95a0fb8600a81557dd0e3efb7b312f3806e2c09d03acf9f4b17 +R 1b085ef1a9a6128f750621757a401900 U drh -Z 25f14b922fbbc9ceaaa18a981a21afa4 +Z 9def8c3af97262dda588f41b6fb5d448 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 008f2ec993..2dffca606a 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4e875ae5c3f0cb28fd40be9f1327d7496f95a55785cad68cb37472e4d1c2e6fd +cd7bb77fdf6c7bad89068d4138f74a950b67a87cc1582de6172b3547519387cb diff --git a/src/shell.c.in b/src/shell.c.in index a39415193e..71cf8eb25e 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -6241,7 +6241,7 @@ struct ArCommand { u8 eCmd; /* An AR_CMD_* value */ u8 bVerbose; /* True if --verbose */ u8 bZip; /* True if the archive is a ZIP */ - u8 bDryRun; /* True if --dry-run */ + u8 bDryRun; /* 1 for --dry-run, 2 for --debug */ u8 bAppend; /* True if --append */ u8 bGlob; /* True if --glob */ u8 fromCmdLine; /* Run from -A instead of .archive */ @@ -6303,6 +6303,7 @@ static int arErrorMsg(ArCommand *pAr, const char *zFmt, ...){ #define AR_SWITCH_APPEND 11 #define AR_SWITCH_DRYRUN 12 #define AR_SWITCH_GLOB 13 +#define AR_SWITCH_DEBUG 14 static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){ switch( eSwitch ){ @@ -6320,7 +6321,10 @@ static int arProcessSwitch(ArCommand *pAr, int eSwitch, const char *zArg){ break; case AR_SWITCH_DRYRUN: - pAr->bDryRun = 1; + if( pAr->bDryRun<2 ) pAr->bDryRun = 1; + break; + case AR_SWITCH_DEBUG: + pAr->bDryRun = 2; break; case AR_SWITCH_GLOB: pAr->bGlob = 1; @@ -6371,6 +6375,7 @@ static int arParseCommand( { "append", 'a', AR_SWITCH_APPEND, 1 }, { "directory", 'C', AR_SWITCH_DIRECTORY, 1 }, { "dryrun", 'n', AR_SWITCH_DRYRUN, 0 }, + { "debug", 0, AR_SWITCH_DEBUG, 0 }, { "glob", 'g', AR_SWITCH_GLOB, 0 }, }; int nSwitch = sizeof(aSwitch) / sizeof(struct ArSwitch); @@ -6672,13 +6677,27 @@ static int arRemoveCommand(ArCommand *pAr){ */ static int arExtractCommand(ArCommand *pAr){ const char *zSql1 = - "WITH dest(dpath,dlen) AS (SELECT realpath($dir),length(realpath($dir)))\n" - "SELECT ($dir || name),\n" - " CASE WHEN $dryrun THEN 0\n" - " ELSE writefile($dir||name, %s, mode, mtime) END\n" + "WITH dest(dpath,dlen) AS (\n" +#ifdef _WIN32 + " SELECT realpath($dir) || '\\',\n" +#else + " SELECT realpath($dir) || '/',\n" +#endif + " 1+length(realpath($dir))\n" + ")\n" + "SELECT\n" + " ($dir || name),\n" + " CASE $dryrun\n" + " WHEN 0 THEN writefile($dir||name, %s, mode, mtime)\n" + " WHEN 1 THEN 0\n" + " ELSE shell_putsnl(format('writefile(%%Q,%%s,%%0o,%%d)'," + "$dir||name,quote(%s),mode,mtime)) IS NULL\n" + " END\n" " FROM dest CROSS JOIN %s\n" " WHERE (%s)\n" - " AND (data IS NULL OR $pass==0)\n" /* Dirs both passes */ + " AND (CASE $pass WHEN 0 THEN (mode&0xf000)<>0xa000\n" + " WHEN 1 THEN (mode&0xf000)=0xa000\n" + " ELSE data IS NULL END)\n" " AND dpath=substr(realpath($dir||name),1,dlen)\n" /* No escapes */ " AND name NOT GLOB '*..[/\\]*'\n"; /* No /../ in paths */ @@ -6709,7 +6728,7 @@ static int arExtractCommand(ArCommand *pAr){ } shellPreparePrintf(pAr->db, &rc, &pSql, zSql1, - azExtraArg[pAr->bZip], pAr->zSrcTable, zWhere + azExtraArg[pAr->bZip], azExtraArg[pAr->bZip], pAr->zSrcTable, zWhere ); if( rc==SQLITE_OK ){ @@ -6719,25 +6738,31 @@ static int arExtractCommand(ArCommand *pAr){ sqlite3_bind_int(pSql, j, pAr->bDryRun); /* Run the SELECT statement twice - ** (0) writefile() all files and directories - ** (1) writefile() for directory again - ** The second pass is so that the timestamps for extracted directories + ** (0) writefile() files and directories + ** (1) writefile() symlinks + ** (2) writefile() for directory again + ** The third pass is so that the timestamps for extracted directories ** will be reset to the value in the archive, since populating them ** in the first pass will have changed the timestamp. */ - for(i=0; i<2; i++){ + for(i=0; i<3; i++){ + if( pAr->bDryRun>=2 ){ + cli_printf(pAr->out, "*** BEGIN PASS %d ***\n", i+1); + } j = sqlite3_bind_parameter_index(pSql, "$pass"); sqlite3_bind_int(pSql, j, i); - if( pAr->bDryRun ){ + if( pAr->bDryRun && i==0 ){ cli_printf(pAr->out, "%s\n", sqlite3_sql(pSql)); - if( pAr->bVerbose==0 ) break; } while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pSql) ){ if( i==0 && pAr->bVerbose ){ cli_printf(pAr->out, "%s\n", sqlite3_column_text(pSql, 0)); } } - if( pAr->bDryRun ) break; + if( pAr->bDryRun==1 ) break; shellReset(&rc, pSql); + if( pAr->bDryRun>=2 ){ + cli_printf(pAr->out, "*** END PASS %d ***\n", i+1); + } } shellFinalize(&rc, pSql); }