`rn` stores the new name verbatim (`./z`, `../z`, `/z`, `z/`); `a` normalizes the same spellings, and `d` cannot select the renamed item by name
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- Half a day
- Newbie friendliness
- 48/100
Research direction
Start with CPP/7zip/UI/Common/ArchiveCommandLine.cpp around AddRenamePair, then compare how archive operands are normalized in CPP/Common/Wildcard.cpp and how rename paths reach the 7z handler in CPP/7zip/UI/Common/Update.cpp and CPP/7zip/Archive/7z/7zHandlerOut.cpp. Reproduce with the rn and d commands in the issue, including names with leading and trailing separators. Done means renamed paths follow the chosen normalization or rejection behavior and can be selected consistently by d, l, and x.
Written by the indexing model from the issue text.
Description
Environment
- 7-Zip (z) 26.06 (arm64),
ip7z/7zip@d3296e3, built withCPP/7zip/cmpl_mac_arm64.mak(Bundles/Alone2) - macOS 26.4.1 arm64, Apple clang 21.0.0
Description
7zz a arc.7z ./z stores the item as z (a leading ./ is removed on purpose, see #55). 7zz rn arc.7z a ./z stores the literal name ./z. The same happens for ../z and /z. A new name that ends in / (rn arc a z/) is stored on a file item, so the file is listed as z/ and extracts as z/_. The operand of d goes through the ./ stripping and the stored name does not, so d arc ./z and d arc z both leave the item in the archive. Only the wildcard * removes it.
Steps to reproduce
Z=7zz
for n in './z' '../z' '/z'; do
d=$(mktemp -d) && cd "$d" && mkdir w && cd w
printf AAA > a; printf BBB > ab
$Z a -bd -y ../arc.7z a ab >/dev/null
$Z rn -bd -y ../arc.7z a "$n" >/dev/null; echo "rn a '$n' rc=$?"
$Z l -slt -bd ../arc.7z | grep '^Path' | grep -v arc.7z # Path = ./z (or ../z, /z), Path = ab
for sp in "$n" z; do
cp ../arc.7z ../c.7z; $Z d -bd -y ../c.7z "$sp" >/dev/null; echo " d '$sp' rc=$?"
$Z l -slt -bd ../c.7z | grep '^Path' | grep -v c.7z # item still present
done
mkdir ../w3 && cd ../w3 && printf A > z && $Z a -bd ../r.7z "$n" >/dev/null 2>&1
$Z l -slt -bd ../r.7z | grep '^Path' | grep -v r.7z # contrast: a stores 'z'
done
# trailing slash on a file item:
d=$(mktemp -d) && cd "$d" && printf AAA > a
$Z a -bd s.7z a >/dev/null; $Z rn -bd s.7z a z/ >/dev/null
$Z l -slt -bd s.7z | grep -E '^(Path|Size)' | grep -v s.7z # Path = z/ Size = 3
The item can still be reached with a literal old name (rn arc ./z y gives y) and with d arc '*'.
Expected
The documentation says only: "rn : Rename files in archive" (7zz --help) and "Renames files in archive." (https://7-zip.opensource.jp/chm/cmdline/commands/rename.htm). It does not say that the new name is stored byte for byte. The maintainer's position in #55 is that stored names lose ./ and absolute prefixes ("7-zip removes path prefixes for absolute paths and for paths starting from ./"). rn should apply the same normalization, or reject such new names, so that the stored name can be selected by an operand spelling that d, l and x accept.
Actual
l -slt shows Path = ./z, ../z, /z or z/. d with either spelling leaves the item in place (rc=0, no message). a with the same spelling stores z.
Root cause (analysis on d3296e3)
CPP/7zip/UI/Common/ArchiveCommandLine.cpp:500-508(AddRenamePair) storesnewNameas given.CRenamePair::Prepare()(Update.cpp:288-295) checks only the old name for wildcards.CPP/7zip/UI/Common/Update.cpp:337(CRenamePair::GetNewPath) buildsdest = NewName + src.Ptr(num), andUpdate.cpp:526queues it.UpdateCallback.cpp:495-496hands it to the handler askpidPath, andCPP/7zip/Archive/7z/7zHandlerOut.cpp:527-536stores it afterReplaceSlashes_OsToUnixonly.- For
a, the./..parts and a leading/are dropped when the operand is added to the censor:CPP/Common/Wildcard.cpp:664-680(numSkipPartsis raised past a.or..part) andGetNumPrefixParts(Wildcard.cpp:557-602, line 602 treats a leading empty part as a prefix).rnnew names never pass through this code.
Suggested fix
Normalize NewName in AddRenamePair with the same rules that the censor applies to a operands (drop a leading ./, drop ./.. parts, drop a leading /), or throw CArcCmdLineException("Unsupported rename command:") for such new names. Handle a trailing separator on a non-directory item the same way.
Related
- #290:
rn arc d/ NEWloses a path separator. #55:./prefixes are stripped on purpose fora; this report is aboutrnstoring its new name verbatim whileanormalizes it.
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).
- Dominant language
- C++
- Stars
- 4.6k
- Forks
- 519
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ip7z/7zip
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
area::installer documentation engine::sd enhancement wg::platform-core
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
lemonade-sdk/lemonade#4349 ·
Maintainers usually reply within 1 day
-
Python example: list a model's scenes and their camerasPossibly taken @rudraparmar76 claimed this today. Opendocumentation good first issue python
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
iamahsanmehmood/openskp#796 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
tenstorrent/tt-umd#4183 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
odelaneau/GLIMPSE#353 · 1 comment ·
Maintainers usually reply within 4 days