Path argument containing `//` duplicates the preceding component (`d//c.txt` → `d/d/c.txt`); `a` and `h` silently use a different file

Open
#289 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp
Domain
cli

Research direction

Start with CPP/Common/Wildcard.cpp at SplitPathToParts() and CCensor::AddItem(), then trace the empty-component handling in CPP/7zip/UI/Common/EnumDirItems.cpp around lines 998–1043. Reproduce with the supplied d//c.txt commands and inspect existing path normalization tests. Done means repeated slashes no longer select a different file and exclusion and folder enumeration behave consistently.

Written by the indexing model from the issue text.

Description

Environment
  • 7-Zip (z) 26.06 (arm64), ip7z/7zip @ d3296e3, built with CPP/7zip/cmpl_mac_arm64.mak (Bundles/Alone2)
  • macOS 26.4.1 arm64, Apple clang 21.0.0
Steps to reproduce
d=$(mktemp -d) && cd "$d"
mkdir -p d/d
printf xyz   > d/c.txt       # CRC32 EB8EBA67
printf other > d/d/c.txt     # CRC32 D9583520

7zz h -bd d//c.txt           # prints: D9583520  5  d/d/c.txt   <- wrong file
7zz h -bd d/c.txt            # prints: EB8EBA67  3  d/c.txt

7zz a -bd t.7z d//c.txt; 7zz l -slt t.7z | grep -E '^(Path|CRC)'
# Path = d/d/c.txt   CRC = D9583520   <- wrong file archived, rc=0

Without d/d/c.txt:

rm -r d/d
7zz h -bd d//c.txt   # WARNING: errno=2 : No such file or directory  d/d/c.txt ; Files: 0 ; rc=1
7zz h -bd d//        # lists a phantom folder "d/d/"

Exclusion does not work:

printf q > d/k.txt
7zz h -bd '-x!d//c.txt' 'd/*'   # d/c.txt is still hashed (Files: 2)
7zz h -bd '-x!d/c.txt'  'd/*'   # d/c.txt excluded (Files: 1)
Expected

On POSIX, "multiple successive slashes are considered to be the same as one slash" (POSIX.1-2017 XBD 4.13 Pathname Resolution). 7-Zip's documentation gives // no special meaning, and 7-Zip already normalizes ./ and a single trailing /. So d//c.txt should mean d/c.txt. At the very least it should never select a different existing file.

Root cause (analysis on d3296e3)
  1. CPP/Common/Wildcard.cpp:158 SplitPathToParts() splits d//c.txt into ["d", "", "c.txt"].
  2. CCensor::AddItem() (Wildcard.cpp:607 onward) removes only a trailing empty part, so an empty-named node remains between d and c.txt.
  3. CPP/7zip/UI/Common/EnumDirItems.cpp:998-1043: for the empty-named child, FindFile is called with fullPath = phyPrefix ("d/"). The returned fi.Name is "d". Enumeration then recurses with curFolderName = "d", so the physical prefix becomes d/d/.
Suggested fix

Drop empty path components (//) when splitting user-supplied paths on POSIX, before building the censor tree. An empty component in the middle of a path has no meaning there.

Related
  • #55: the maintainer states that a leading ./ is stripped on purpose ("7-zip removes path prefixes for absolute paths and for paths starting from ./"). A // in the middle of a path is a different case: it is not a prefix, and it makes 7-Zip pick a different file.
  • #175: path normalization of .. with symlinks on Linux.

Found with a differential test setup (a model of the documented behavior 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ip7z/7zip

All issues in ip7z/7zip

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.