diff panics (broken-pipe unwrap) when its stdout is closed early
まだ誰も着手していません。
評価
調査の方向性
src/diff.rs:94 と src/side_diff.rs:353-356 で特定された出力書き込みから始め、提供されている seq、sed、head コマンドを使って通常ケースとサイドバイサイドケースの両方を再現します。クローズされたパイプへの出力で panic が発生したりエラーが表示されたりしなくなったこと、また両方のモードが GNU diff と同じように期待される SIGPIPE ステータスで終了することを確認します。
索引モデルが issue の本文から書いたものです。
説明
Summary
When diff's standard output is a pipe whose reader closes early (e.g. diff … | head), uutils diff aborts with a panic (exit 134, core dump)
instead of dying cleanly to SIGPIPE like GNU (exit 141). The output is written with a bare .unwrap() on the write_all/push_output result; the BrokenPipe error is unwrapped and, under panic="abort", aborts the process. This affects every output mode: the normal/context/unified/ed path writes the buffered result in src/diff.rs:94, and the side-by-side (-y) path writes each line in src/side_diff.rs:353-356.
Steps to reproduce
$ seq 1 100000 > b1; seq 1 100000 | sed 's/5/X/' > b2
$ diffutils diff b1 b2 | head -1
thread 'main' panicked at src/diff.rs:94:41:
called `Result::unwrap()` on an `Err` value: Os { code: 32, kind: BrokenPipe, message: "Broken pipe" }
$ echo "${PIPESTATUS[0]}"
134
Side-by-side mode hits the sibling site src/side_diff.rs:353:
$ diffutils diff -y b1 b2 | head -1
thread 'main' panicked at src/side_diff.rs:353:87:
called `Result::unwrap()` on an `Err` value: Os { code: 32, kind: BrokenPipe, message: "Broken pipe" }
$ echo "${PIPESTATUS[0]}"
134
Expected behavior
Match GNU: a closed output pipe terminates the program via SIGPIPE (exit 141) with no error message and no core dump.
$ /usr/bin/diff b1 b2 | head -1
1c1
$ echo "${PIPESTATUS[0]}"
141
$ /usr/bin/diff -y b1 b2 | head -1
1 < 1
$ echo "${PIPESTATUS[0]}"
141
Root cause
The full diff output (normal/context/unified/ed) is buffered and written once:
// src/diff.rs:94
io::stdout().write_all(&result).unwrap();
Side-by-side writes each line straight to the locked stdout and unwraps every
write:
// src/side_diff.rs:353-356
push_output(...).unwrap(); // and the sibling unwraps at :354, :356
Any write_all/push_output error — BrokenPipe in the common pipe-closed case — is unwrapped and aborts.
Found by our static analysis tooling.
- 主要言語
- Rust
- スター
- 276
- フォーク
- 39
- 平均マージ
- 3時間 27分
- マージ済み PR(30日)
- 3
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
uutils/diffutils のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 64/100
uutils/diffutils の issue をすべて見る
似ている issue
-
risk:low runtime status:in-progress type:test
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
EricSpencer00/Resilient#4835 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
bisq-network/bisq-musig#204 ·
-
agent:ready documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
cesarferreira/stax#890 ·