`7z d` on a non-existent archive exits 0 and silently creates an empty archive (`t`/`l`/`x`/`e`/`rn` exit 2)

Aperta Adatta ai principianti
#301 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à
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp
Ambito
backend

Direzione di ricerca

Inizia da CPP/7zip/UI/Common/Update.cpp e dai controlli di UpdateArchive intorno alle righe 1219–1229 e 1338–1340, che il report identifica come gestione degli archivi mancanti per la modalità di rinomina. Confronta il modo in cui viene identificato il comando d con la condizione esistente di renameMode, quindi esegui la riproduzione segnalata per archivi 7z, zip e tar mancanti. Il lavoro è terminato quando delete segnala un archivio mancante, restituisce un errore e non crea alcun file di output.

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

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.