`-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

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

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp
Domain
backend, cli

Research direction

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.

Written by the indexing model from the issue text.

Description

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

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.