`-p` is silently ignored for tar/wim/gzip/xz (plaintext archive, rc=0, no warning); same for `-mhe=on` and `-mem=AES256` without a password

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

Direzione di ricerca

Start with the update handlers named in the report: CPP/7zip/UI/Console/UpdateCallbackConsole.cpp, UI/Common/Update.cpp, and the 7z, Zip, Tar, Gzip, Xz, and Wim output handlers. Trace how password and encryption options reach each handler, then check the relevant command-line tests or add a focused regression test for unsupported formats and missing passwords. Done means these requests produce the specified warning or error and exit status instead of silently creating an unencrypted archive.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Environment
  • 7-Zip (z) 26.06 (arm64), ip7z/7zip @ d3296e3
  • macOS 26.4.1 arm64, Apple clang 21.0.0
Description

When -p{password} is given for a format that cannot encrypt, 7-Zip creates a plain archive and reports success. The same happens when header encryption (-mhe=on) or an AES method (-mem=AES256) is requested without a password. A user who relies on the password to protect the data ends up with readable content and no signal.

Steps to reproduce
Z=7zz
d=$(mktemp -d) && cd "$d" && printf 'TOP-SECRET-PAYLOAD' > a.txt
for t in tar wim gzip xz zip 7z; do
  rm -f s.$t
  out=$($Z a -bd -t$t -psecret s.$t a.txt 2>&1); rc=$?
  echo "-t$t -psecret rc=$rc msgs=$(echo "$out" | grep -ciE 'warn|error') plaintext_in_file=$(grep -c TOP-SECRET-PAYLOAD s.$t) x_without_password_rc=$($Z x -bd -y -oxo_$t s.$t </dev/null >/dev/null 2>&1; echo $?)"
done
$Z a -bd -mhe=on h.7z a.txt >/dev/null 2>&1; echo "7z -mhe=on (no -p) rc=$? ; l without password lists names: $($Z l -bd h.7z </dev/null | grep -c a.txt)"
$Z a -bd -tzip -mem=AES256 e.zip a.txt >/dev/null 2>&1; echo "zip -mem=AES256 (no -p) rc=$? ; encrypted items: $($Z l -slt e.zip </dev/null | grep -c 'Encrypted = +')"

Output:

-ttar  -psecret rc=0 msgs=0 plaintext_in_file=1 x_without_password_rc=0
-twim  -psecret rc=0 msgs=0 plaintext_in_file=1 x_without_password_rc=0
-tgzip -psecret rc=0 msgs=0 plaintext_in_file=1 x_without_password_rc=0
-txz   -psecret rc=0 msgs=0 plaintext_in_file=1 x_without_password_rc=0
-tzip  -psecret rc=0 msgs=0 plaintext_in_file=0 x_without_password_rc=255
-t7z   -psecret rc=0 msgs=0 plaintext_in_file=0 x_without_password_rc=255
7z -mhe=on (no -p) rc=0 ; l without password lists names: 1
zip -mem=AES256 (no -p) rc=0 ; encrypted items: 0

(for gzip and xz the "plaintext" grep is a stored/deflated check of the small payload; extraction works without any password in all four cases)

Expected

-p is documented as "Specifies password." and the example 7z a archive.7z -psecret -mhe *.txt is described as *"compresses .txt files to archive.7z using password "secret". Also it encrypts archive headers (-mhe switch), so filenames will be encrypted." (https://7-zip.opensource.jp/chm/cmdline/switches/password.htm). 7zz --help lists -p{Password} : set Password with no format restriction. For a format that cannot encrypt, expected: a command-line error or at least a warning ("password is ignored for this format", exit code 1), and likewise when -mhe=on / -mem=AES* has no password to apply.

Actual

rc=0, no message, archive stored without encryption.

Root cause (analysis on d3296e3)
  1. The console always offers the password through CUpdateCallbackConsole::CryptoGetTextPassword2 (CPP/7zip/UI/Console/UpdateCallbackConsole.cpp:830-852), PasswordIsDefined being set from the command line (UI/Console/Main.cpp:1586).
  2. Only the 7z and zip update handlers ask for it: Archive/7z/7zHandlerOut.cpp:731 and Archive/Zip/ZipHandlerOut.cpp:408. The tar, gzip, xz and wim update handlers never call CryptoGetTextPassword2 (no occurrence in TarHandlerOut.cpp, GzHandler.cpp, XzHandler.cpp, WimHandlerOut.cpp), and nothing in UI/Common/Update.cpp checks that a password was consumed.
  3. Header encryption in 7z is gated on a password: 7zHandlerOut.cpp:750: if (methodMode.PasswordIsDefined) { ... encryptHeaders = _encryptHeaders ...}. Without a password the -mhe setting is dropped without a message. The zip handler sets IsAesMode only when Password_Defined (ZipHandlerOut.cpp:410-413), so -mem=AES256 without -p is dropped as well.
Suggested fix

After the update finishes (or before it starts), report a warning (exit code 1) or error when a password was supplied (PasswordEnabled) and no handler requested it, and when -mhe=on / -mem=AES* is specified without a password. At minimum, document on the -p and -mhe pages which formats support encryption.


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.