`7z d archive d/.` (operand ending in `.` or `..`) deletes every item in the archive, rc=0
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Start with CPP/Common/Wildcard.cpp around CCensor::AddItem() and CPP/7zip/UI/Common/Update.cpp around Censor_CheckPath(), following how Prefix and wildcard items are handled for delete selection. Reproduce with the issue’s 7zz d commands and compare against l selection. Done when operands ending in . or .. cannot select every archive item, with regression coverage for the reported cases.
索引モデルが issue の本文から書いたものです。
説明
Environment
- 7-Zip (z) 26.06 (arm64),
ip7z/7zip@d3296e3, built withCPP/7zip/cmpl_mac_arm64.mak(Bundles/Alone2) - macOS arm64, Apple clang. Same result for
.7zand.ziparchives, and with the ASan/UBSan build.
Description
When an operand of the d (delete) command ends with a . or .. path component and has a real directory before it, 7-Zip does not delete that directory or its contents. It deletes all items of the archive and returns exit code 0. l, t and x select nothing for the same operand, so a user who first checks with 7z l archive d/. sees no match and then runs 7z d archive d/. loses the whole archive.
Steps to reproduce
Run verbatim (twice produced the same result; 7zz is the 26.06 binary on PATH):
d=$(mktemp -d) && cd "$d"
mkdir -p src/d/e src/g
printf alpha > src/a.txt; printf c > src/d/c.txt; printf f > src/d/e/f.txt; printf h > src/g/h.txt
(cd src && 7zz a -bd ../arc.7z a.txt d g >/dev/null)
7zz l -slt -ba arc.7z d/. | grep -c '^Path' # 0: list selects nothing
7zz d -bd arc.7z d/. ; echo "rc=$?" # Delete data from archive: 3 folders, 4 files; rc=0
7zz l -slt -ba arc.7z | grep -c '^Path' # 0: archive is now empty
Other operands with the same result (7z and zip): d/e/.., .., d/./; -i!d/. also deletes everything.
For comparison: 7zz d arc.7z d/c.txt deletes only d/c.txt.
Expected
The documentation of the command says only: "d (Delete) command. Deletes files from archive." with the example "7z d archive.zip *.bak -r" (7-zip.opensource.jp/chm/cmdline/commands/delete.htm). Nothing there gives . or .. a meaning that widens the selection. 7z l, 7z t and 7z x share the operand grammar and select no item for d/.. So d should delete nothing for d/.. At most it could delete the contents of d, which is what 7z a arc d/. means on the add side. It must never delete a.txt or g/h.txt.
Actual
rc=0, "Delete data from archive: 3 folders, 4 files", and the archive is left empty. The same happens for d/e/.., .. and d/./ with .7z and .zip, and with -i!d/.. For comparison, 7zz d -bd '-x!d/.' arc.7z deletes nothing (all 7 items remain), so the exclude form does not protect d either.
Root cause (analysis on d3296e3)
CPP/7zip/UI/Common/Update.cpp:1157builds the censor for the update group (a,u,d,rn) withcensor.AddPathsToCensor(options.PathMode), andPathModeisk_RelatPath(ArchiveCommandLine.cpp:1468,:1788).l,tandxusek_AbsPath(ArchiveCommandLine.cpp:1663), so a literal.component never matches an archive name there.- In
k_RelatPathmodeCCensor::AddItem()moves the leading path parts intoCPair::Prefix. If the last./..component is the final part,numSkipParts = pathParts.Size()(CPP/Common/Wildcard.cpp:669-678). All parts, including the real directoryd, become prefix.Wildcard.cpp:706-712then seespathParts.IsEmpty()and creates the universal item*, stored underPairs[index]withPrefix = "d/./"(Wildcard.cpp:702,:736). - On the add side the prefix is used to enumerate the disk directory, so
a arc d/.works. Ford,Censor_CheckPath()(CPP/7zip/UI/Common/Update.cpp:961-979) matches archive items againstPairs[i].Headonly and ignoresPrefix(comment at:966). The*node therefore matches every item in the archive, andai.Censored = true(:1018) for all of them. - A leading
./or../(./d,./a.txt) goes through the same code, but there the prefix removal is the documented "./is stripped" behavior (#55), so it is not part of this report.
Suggested fix
For commands that match against archive names (d, also u/rn selection), either (a) reject operands, -i! and -x! patterns that contain a . or .. component with a command line error (exit code 7), or (b) when Prefix is non-empty and the item is matched against an archive, keep the prefix parts in the tree so d/. becomes d/*. Option (a) is the smaller change and matches what l, t and x effectively do (select nothing).
Related
- #289:
//in a path operand is mishandled in the same wildcard/censor code (Wildcard.cpp). #55: a leading./is stripped on purpose; this report is only about operands that END in.or...
Found with a differential test setup (a model of the documented behavior, and for some reports an independent tool such as libarchive/bsdtar, compared against the real binary) and then checked by hand: every command above was re-run verbatim on the tested build, and the root cause was read in the source. Tested commit: d3296e3 (26.06).
- 主要言語
- C++
- スター
- 4.6k
- フォーク
- 519
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ip7z/7zip のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
area::installer documentation engine::sd enhancement wg::platform-core
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
lemonade-sdk/lemonade#4349 ·
メンテナーはふだん 1 日以内に返信
-
Python example: list a model's scenes and their cameras対応中かも @rudraparmar76 が今日担当しました。 オープンdocumentation good first issue python
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
iamahsanmehmood/openskp#796 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
tenstorrent/tt-umd#4183 ·
メンテナーはふだん 4 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
odelaneau/GLIMPSE#353 · コメント 1 件 ·
メンテナーはふだん 4 日以内に返信