An include list file with no names makes `l`/`t`/`x` fail with "Cannot use absolute pathnames for this command", while `a`/`h`/`d` accept it

Open
#303 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
58/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp
Domain
backend

Research direction

Start by reading CPP/7zip/UI/Common/ArchiveCommandLine.cpp around the empty censor handling and the relative path check, then inspect CPP/Common/Wildcard.h and the Pairs.Front() uses in Main.cpp mentioned in the report. Reproduce with an empty include list and compare a, h, d, l, t and x. Done when the commands handle the empty selection consistently without breaking the Pairs.Front() assumptions.

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

When the only include source is an empty list file, a, h and d finish with rc=0 and select nothing. l, t and x stop with Command Line Error: Cannot use absolute pathnames for this command (rc=7), although no path was given at all.

Steps to reproduce
Z=7zz
d=$(mktemp -d) && cd "$d"
echo hi > a.txt; : > e.lst; $Z a -bd g.7z a.txt >/dev/null
for c in "a -bd n.7z" "h -bd" "d -bd g.7z" "l -bd g.7z" "t -bd g.7z" "x -bd -y -oxo g.7z"; do
  $Z $c [email protected] >out.txt 2>&1; rc=$?
  echo "7zz $c [email protected] => rc=$rc | $(grep -E 'Command Line|absolute|Everything' out.txt | tr '\n' ' ')"
done

Observed (two runs, identical):

7zz a -bd n.7z [email protected] => rc=0 | Everything is Ok
7zz h -bd [email protected] => rc=0 | Everything is Ok
7zz d -bd g.7z [email protected] => rc=0 | Everything is Ok
7zz l -bd g.7z [email protected] => rc=7 | Command Line Error: Cannot use absolute pathnames for this command
7zz t -bd g.7z [email protected] => rc=7 | Command Line Error: Cannot use absolute pathnames for this command
7zz x -bd -y -oxo g.7z [email protected] => rc=7 | Command Line Error: Cannot use absolute pathnames for this command

@e.lst as a positional operand behaves the same.

Expected

The documentation says only that a list file holds file names separated by newlines:

You can supply one or more filenames or wildcards for special list files (files containing lists of files). The filenames in such list file must be separated by new line symbol(s).

(https://7-zip.opensource.jp/chm/cmdline/syntax.htm). It does not make an empty list an error. The same list should behave the same in every command: either select nothing everywhere, or fail everywhere with a message that names the real problem (an empty list), not an absolute-path problem.

Actual

See the table above: three commands succeed, three fail with a message about absolute pathnames that does not apply.

Root cause (analysis on d3296e3)
  1. CPP/7zip/UI/Common/ArchiveCommandLine.cpp:578 adds the default * item only when there are no non-switch operands and no -i switch. An [email protected] counts as a switch include and an @e.lst operand counts as an operand, so the censor stays empty (Pairs.Size() == 0).
  2. ArchiveCommandLine.cpp:1663-1668 (extract/list group): if (!options.Censor.AllAreRelative()) throw CArcCmdLineException("Cannot use absolute pathnames for this command");.
  3. CPP/Common/Wildcard.h:201-202: AllAreRelative() is Pairs.Size() == 1 && Pairs.Front().Prefix.IsEmpty(). With zero pairs it returns false, which the caller reads as "some path is absolute".
  4. a/h/d do not run this check, so they continue with an empty selection.
Suggested fix

Treat an empty pair list as relative in AllAreRelative() (for example Pairs.Size() == 0 || ...), or check for an empty censor before the absolute-path test and either report "no files specified" or fall through to select nothing, in the same way for all commands. Also note Main.cpp:1410 and Main.cpp:1536 call options.Censor.Pairs.Front() and rely on that earlier exception to keep Pairs non-empty, so the fix must keep that invariant.


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.