zip: extracting with a wrong or missing password truncates an existing target file to 0 bytes (`-y` / `-aoa`)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Read CPP/7zip/Archive/Zip/ZipHandler.cpp around Extract() and the wrong-password branches, then compare how CPP/7zip/Archive/7z/7zExtract.cpp opens output files lazily. Reproduce the ZIP and 7z cases from the issue, including the overwrite modes. Done when a wrong password leaves existing files unchanged and creates no empty output file, with extraction behavior still covered for the listed modes.
索引モデルが issue の本文から書いたものです。
説明
Environment
- 7-Zip (z) 26.06 (arm64),
ip7z/7zip@d3296e3 - macOS 26.4.1 arm64, Apple clang 21.0.0
Description
For an encrypted zip item, the extraction callback opens (creates or truncates) the output file before the password is checked. When the password is wrong, nothing is written, but the file already exists with length 0. With -y / -aoa an existing file with the same name loses its contents. A 7z archive with the same wrong password does not touch the existing file.
Steps to reproduce
Z=7zz
d=$(mktemp -d) && cd "$d" && printf 'hello hello' > a.txt
$Z a -bd -tzip -psecret z.zip a.txt >/dev/null
$Z a -bd -t7z -psecret s.7z a.txt >/dev/null
for f in z.zip s.7z; do
rm -rf xo; mkdir xo; printf 'ORIGINAL-CONTENT' > xo/a.txt
$Z x -bd -y -pwrong -oxo $f >/dev/null 2>&1 </dev/null
echo "$f rc=$? existing a.txt is now $(wc -c < xo/a.txt | tr -d ' ') bytes (was 16)"
done
# z.zip rc=2 existing a.txt is now 0 bytes (was 16)
# s.7z rc=2 existing a.txt is now 16 bytes (was 16)
rm -rf xo; mkdir xo; $Z x -bd -y -pwrong -oxo z.zip >/dev/null 2>&1
ls -l xo # a.txt, 0 bytes, although nothing could be extracted
for sw in -aoa -aot -aos -aou; do
rm -rf xo; mkdir xo; printf ORIGINAL-CONTENT > xo/a.txt
$Z x -bd $sw -pwrong -oxo z.zip >/dev/null 2>&1
echo "$sw rc=$? $(ls -l xo | tail -n +2 | awk '{print $9":"$5}' | tr '\n' ' ')"
done
# -aoa rc=2 a.txt:0
# -aot rc=2 a.txt:0 a_1.txt:16
# -aos rc=0 a.txt:16
# -aou rc=2 a.txt:16 a_1.txt:0
Expected
x is documented as "Extracts files from an archive to the current directory or to the output directory. ... with full paths", and -ao{a|s|t|u} as the overwrite mode ("-aoa Overwrite All existing files without prompt") for files that are extracted. An item that cannot be extracted because of a wrong password should not replace or empty an existing file, and should not leave an empty file that looks like a successful extraction. 7z archives already behave this way.
Actual
ERROR: Wrong password : a.txt, rc=2, but xo/a.txt is now 0 bytes (was 16). In a fresh directory a 0-byte a.txt is created.
Root cause (analysis on d3296e3)
CPP/7zip/Archive/Zip/ZipHandler.cpp:1608:Extract()callsextractCallback->GetStream(index, &realOutStream, askMode)first.CPP/7zip/UI/Common/ArchiveExtractCallback.cpp:1577:GetStreamends in_outFileStreamSpec->Create_ALWAYS_or_Open_ALWAYS(...), which truncates or creates the file immediately.- Only afterwards
CZipDecoder::Decode()checks the password and returnskWrongPassword(ZipHandler.cpp:1133,1139,1270,1285,1311). No data was written, and the zero-length file stays. - The 7z handler opens the output file lazily:
CPP/7zip/Archive/7z/7zExtract.cpp:75-106(CFolderOutStream::OpenFile) is called when the first data arrives, so a failed decode never reaches it.
Suggested fix
In ZipHandler.cpp Extract(), run the password/header check (the kWrongPassword branches) before requesting the output stream, or call GetStream lazily on the first write as the 7z handler does. Alternatively remove the zero-length file when the item result is kWrongPassword.
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).
- 主要言語
- C++
- スター
- 4.6k
- フォーク
- 519
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ip7z/7zip のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
need triaging
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
area::installer documentation engine::sd enhancement wg::platform-core
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
lemonade-sdk/lemonade#4349 ·
メンテナーはふだん 1 日以内に返信
-
Python example: list a model's scenes and their cameras対応中かも @rudraparmar76 が今日担当しました。 オープンdocumentation good first issue python
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
iamahsanmehmood/openskp#796 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
tenstorrent/tt-umd#4183 ·
メンテナーはふだん 4 日以内に返信