Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

diff panics (broken-pipe unwrap) when its stdout is closed early

Đang mở
#244 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
rust
Lĩnh vực
cli

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

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của uutils/diffutils

Tất cả issue của uutils/diffutils

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.