nl: zero-padded numbering of i64::MIN panics or prints two minus signs
Maintainer thường phản hồi trong vòng 1 ngày
Một pull request liên quan đã được merge.
- #16092 của @fixfon — đã merge
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Read src/uu/nl/src/nl.rs, especially NumberFormat::format_to, and run the reproduction command in the issue in both debug and release builds. The issue notes that all 72 existing nl integration tests pass; use cargo test --no-default-features --features nl --test tests test_nl:: as a baseline. Done means -n rz prints the minimum value with one minus sign and does not panic.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
nl --number-format=rz mishandles the valid line number -9223372036854775808 (i64::MIN). A release build prints two minus signs and exits successfully; a debug build panics after writing a single -.
Reproduced on Linux x86_64 (Debian 13), with uutils 0.13.0 built from main at 62fcace0def184c550876d81ad1534408767f086. Compared with GNU coreutils 9.12 from the reference package linked in CONTRIBUTING.md; GNU 9.7 gives the same expected result.
From the repository root:
cargo build --release --no-default-features --features nl
export LC_ALL=C LANG=C
printf 'a\nb\n' | target/release/coreutils nl \
--starting-line-number=-9223372036854775808 -n rz -w 1 -s :
Actual output (exit status 0, empty stderr):
--9223372036854775808:a
-9223372036854775807:b
Expected output (GNU 9.12, exit status 0, empty stderr):
-9223372036854775808:a
-9223372036854775807:b
Building without --release and running the same command with target/debug/coreutils instead exits 101, writes only - to stdout, and reports attempt to negate with overflow.
This also happens when numbering reaches the minimum through a decrement:
printf 'a\nb\n' | target/release/coreutils nl \
--starting-line-number=-9223372036854775807 --line-increment=-1 \
-n rz -w 1 -s :
Here the second line gets the extra minus sign. Using -n rn or -n ln with the minimum value works correctly, as does -n rz starting at the adjacent value with the default increment.
The cause is in NumberFormat::format_to: the negative RightZero branch writes -, then calls number.abs(). The absolute value of i64::MIN is not representable as i64. Formatting its unsigned magnitude would avoid this overflow.
All 72 existing nl integration tests pass (cargo test --no-default-features --features nl --test tests test_nl::). The existing minimum-value tests use the default format rather than rz.
I searched open and closed issues and PRs for nl, the minimum value, and overflow/zero-padding reports. The related #15999 concerns parsing separate negative arguments; this reproducer uses the accepted --starting-line-number=... form. #13347 concerns large number widths, whereas this reproducer uses width 1.
- Ngôn ngữ chính
- Rust
- Star
- 24.3k
- Fork
- 2.1k
- Merge trung bình
- 1 ngày 20 giờ
- Pull request đã merge (30 ngày)
- 380
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc 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/coreutils
-
README: Rust version is outdatedĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
fold: tab after an 8 KiB buffer flush exceeds the requested widthCó thể đã có người làm @gibkim đã nhận 1 ngày trước. Đang mởU - fold
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ls: `--block-size=0` is accepted when `--si` comes laterCó thể đã có người làm @Logic769 đã nhận 3 ngày trước. Đang mởgood first issue U - ls
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
uutils/coreutils#15962 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
B - high priority U - tr
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của uutils/coreutils
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
libnativeapi/nativeapi#21 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
longbridge/nsh#804 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày