diff panics (broken-pipe unwrap) when its stdout is closed early
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Bắt đầu với các lần ghi đầu ra được xác định trong src/diff.rs:94 và src/side_diff.rs:353-356, sau đó tái hiện cả trường hợp thông thường và trường hợp song song bằng các lệnh seq, sed và head được cung cấp. Xác minh rằng đầu ra vào pipe đã đóng không còn gây panic hoặc in ra lỗi, đồng thời cả hai chế độ đều kết thúc với trạng thái SIGPIPE mong đợi như GNU diff.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Rust
- Star
- 276
- Fork
- 39
- Merge trung bình
- 3 giờ 27 phút
- Pull request đã merge (30 ngày)
- 3
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của uutils/diffutils
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 64/100
Tất cả issue của uutils/diffutils
Issue tương tự
-
Replayed reasoning items send "content": null, which the Responses API schema does not permit Đang mởbug CLI custom-model
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
rust-bitcoin/rust-bitcoin#6930 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
fulcrumgenomics/ferro-hgvs#2251 ·
-
Missing examples for `Allocator` Đang mởA-allocators A-docs C-enhancement T-libs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100