`7z d` on a non-existent archive exits 0 and silently creates an empty archive (`t`/`l`/`x`/`e`/`rn` exit 2)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
Start with CPP/7zip/UI/Common/Update.cpp and the UpdateArchive checks around lines 1219–1229 and 1338–1340, which the report identifies as the missing-archive handling for rename mode. Compare how command d is identified with the existing renameMode guard, then run the reported reproduction for missing 7z, zip, and tar archives. Done means delete reports a missing archive, returns an error, and creates no output file.
Written by the indexing model from the issue text.
Description
Environment
- 7-Zip (z) 26.06 (arm64),
ip7z/7zip@d3296e3, built withCPP/7zip/cmpl_mac_arm64.mak(Bundles/Alone2) - macOS 26.4.1 arm64, Apple clang 21.0.0
Description
Running the d (Delete) command on an archive path that does not exist does not report an error. 7zz treats the command as "update an archive that has zero items", creates a new empty archive, prints Everything is Ok and returns 0. All other commands that read an existing archive (t, l, x, e, rn) return 2 for the same input. A typo in the archive name therefore goes unnoticed and leaves a stray file on disk.
Steps to reproduce
d=$(mktemp -d) && cd "$d"
printf hello > a.txt
7zz t -y missing.7z >/dev/null 2>&1; echo "t rc=$?" # t rc=2 (errno=2 : No such file or directory)
7zz l -y missing.7z >/dev/null 2>&1; echo "l rc=$?" # l rc=2
7zz x -y missing.7z >/dev/null 2>&1; echo "x rc=$?" # x rc=2
7zz e -y missing.7z >/dev/null 2>&1; echo "e rc=$?" # e rc=2
7zz rn missing.7z a b >/dev/null 2>&1; echo "rn rc=$?" # rn rc=2 (ERROR: can't find archive)
ls missing.7z # No such file or directory
7zz d -y missing.7z a.txt; echo "d rc=$?"
# Creating archive: missing.7z
# Add new data to archive: 0 files, 0 bytes
# Files read from disk: 0
# Archive size: 32 bytes (1 KiB)
# Everything is Ok
# d rc=0
ls -l missing.7z # -rw-r--r-- 32 bytes
7zz d -y missing.zip a.txt >/dev/null; echo "zip d rc=$?"; ls -l missing.zip # rc=0, 22 bytes
7zz d -y missing.tar a.txt >/dev/null; echo "tar d rc=$?"; ls -l missing.tar # rc=0, 1024 bytes
Expected
The documentation says d "Deletes files from archive." (https://7-zip.opensource.jp/chm/cmdline/commands/delete.htm). An archive that does not exist has nothing to delete from. The command should fail the same way t, l, x, e and rn do: report the missing file, return 2, and create nothing. Exit code 0 is documented as "No error" (https://7-zip.opensource.jp/chm/cmdline/exit_codes.htm).
Actual
rc=0, Everything is Ok, and a new empty archive file (32 bytes for 7z, 22 for zip, 1024 for tar) is left on disk.
Root cause (analysis on d3296e3)
CPP/7zip/UI/Common/Update.cpp:1219-1229 (function UpdateArchive): after fi.Find_FollowLink(arcPath) fails, only renameMode is rejected (throw "can't find archive", line 1222-1223). For d the code falls through, sets the format from the file extension, and continues with thereIsInArchive == false. At line 1338-1340 the same guard exists again, again only for renameMode. The delete command is executed as an update whose action set removes the selected items from an empty input. The result is an empty output archive, which is written normally.
Suggested fix
Treat the delete command like rename mode when the archive does not exist: throw "can't find archive" (or return the file-not-found error) at Update.cpp:1222 and 1339 for d as well, before any output file is created.
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ip7z/7zip
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
area::installer documentation engine::sd enhancement wg::platform-core
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
lemonade-sdk/lemonade#4349 ·
Maintainers usually reply within 1 day
-
Python example: list a model's scenes and their camerasPossibly taken @rudraparmar76 claimed this today. Opendocumentation good first issue python
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
iamahsanmehmood/openskp#796 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
tenstorrent/tt-umd#4183 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
odelaneau/GLIMPSE#353 · 1 comment ·
Maintainers usually reply within 4 days