Repeating the same file operand: `a` fails with "Duplicate filename on disk", `h` counts the file twice, `l/x/t/d` de-duplicate

Aperta
#304 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à
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
56/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
cli

Direzione di ricerca

Start with the named paths in CPP/7zip/UI/Common/EnumDirItems.cpp and CPP/Common/Wildcard.cpp, then compare direct-name enumeration with wildcard enumeration. Reproduce with the commands in the issue and inspect how repeated operands reach archive creation and hashing. Done means a archives the repeated file once and h lists it once, consistently with l, x, t and d.

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 arm64, Apple clang
Description

Naming the same file twice is fatal for a (rc=2, no archive written) and is double counted by h. Selecting the same file through a wildcard plus a literal (a.txt *.txt) is accepted, and l/x/t/d treat a repeated name as one selector.

Steps to reproduce
Z=7zz
d=$(mktemp -d) && cd "$d" && mkdir w && cd w
echo hi > a.txt
$Z a -bd ../x.7z a.txt a.txt; echo "a a.txt a.txt: rc=$?"; ls ../x.7z
$Z a -bd ../y.7z a.txt '*.txt' >/dev/null; echo "a a.txt '*.txt': rc=$?"
$Z h -bd a.txt a.txt | grep -E '^Files:|a.txt'
$Z a -bd ../k.7z a.txt >/dev/null; $Z l -bd ../k.7z a.txt a.txt | tail -1

Observed (two runs):

ERROR:
Duplicate filename on disk:
a.txt
a.txt
a a.txt a.txt: rc=2
ls: ../x.7z: No such file or directory
a a.txt '*.txt': rc=0
ED6F7A7A             3  a.txt
ED6F7A7A             3  a.txt
Files: 2
2026-11-25 12:18:06                  3            7  1 files
Expected

The documentation describes the arguments as a set of file names or wildcards to process and gives no rule that a name may appear only once:

The switches and other filenames can be in any order.
The default wildcard "*" will be used if there is no filename/wildcard in the command line.

(https://7-zip.opensource.jp/chm/cmdline/syntax.htm). Since a a.txt '*.txt' (the same file selected twice) is accepted and l/x/t/d select a.txt once for a.txt a.txt, a a.txt a.txt should produce an archive with one a.txt, and h a.txt a.txt should list it once.

Actual

a: rc=2 with Duplicate filename on disk, no archive. h: two identical lines, Files: 2. l: one item.

Root cause (analysis on d3296e3)
  1. CPP/7zip/UI/Common/EnumDirItems.cpp:813-919: when every include item is a plain name (CanUseFsDirect, line 806), the loop walks curNode.IncludeItems and calls dirItems.AddDirFileInfo() (line 919) once per item. Two identical items give two identical CDirItem entries.
  2. The wildcard path (generic enumeration) visits each directory entry once, so overlap through *.txt never produces a duplicate entry.
  3. CPP/7zip/UI/Common/UpdatePair.cpp:181-187 sorts the disk names and throws k_Duplicate_inDir_Message ("Duplicate filename on disk:", line 103) when two neighbours compare equal. That is the a failure. h has no such check and prints both entries.
Suggested fix

De-duplicate identical literal include items when the censor tree is built (CCensorNode::AddItemSimple, CPP/Common/Wildcard.cpp:345-349), or skip an entry in the direct-names loop when the same normalized path was already added.

Related

Maintainer comment on #55 (./file ./subdir/file reports Duplicate filename: "It's feature") concerns paths that normalize to the same stored name. Here the two operands are byte-identical.

  • #55: the maintainer answered "It's feature" for ./file ./subdir/file. This report is about repeating the same operand being handled differently by a, h and l/x/t/d.

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

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.