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

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

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

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

Research direction

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.

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

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.