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

Aperta
#289 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
cli

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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).

Lingua principale
C++
Stelle
4.6k
Fork
519
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ip7z/7zip

Tutte le issue di ip7z/7zip

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.