shuf: exhausted random source destroys the input during an in-place shuffle
Maintainer thường phản hồi trong vòng 1 ngày
Đá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
- 78/100
Hướng nghiên cứu
Đọc src/uu/shuf/src/shuf.rs, đặc biệt là open_output() và luồng xáo trộn trong shuf_exec(). Sau đó, kiểm tra các bài kiểm thử tích hợp shuf hiện có và thêm một trường hợp hồi quy cho nguồn ngẫu nhiên đã cạn khi ghi đè tại chỗ. Công việc hoàn tất khi lệnh báo lỗi nguồn ngẫu nhiên mà vẫn giữ nguyên đầu vào, và bài kiểm thử hồi quy chạy đạt.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
An in-place shuffle with a readable but exhausted --random-source erases the input file before reporting the error. GNU shuf leaves the file unchanged.
Reproduced on Linux x86_64 at main c1f172886c6643f61ffde5a1ce3db0aaf14e182b, in debug and release builds. References: GNU 9.7 and the project-recommended GNU 9.12 package (9.12-0ubuntu1~ppa1).
Reproduce
From a built repository, using only disposable files:
d=$(mktemp -d)
printf 'one\ntwo\nthree\n' > "$d/input"
: > "$d/seed"
LC_ALL=C target/debug/coreutils shuf \
--random-source="$d/seed" -o "$d/input" "$d/input"
echo "status: $?"
wc -c < "$d/input"
Actual: "shuf: end of random source", exit 1, and input is now 0 bytes.
Expected: exit 1 with the original 14 bytes intact, as with GNU 9.7 and 9.12. Recreate the input before running the GNU comparison.
This also occurs with a nonempty but insufficient random source: 100 input records and a one-byte seed. It affects an existing separate output file and output paths that are hard links or symlinks to the input.
Cause and validation
In src/uu/shuf/src/shuf.rs, open_output() at line 164 calls File::create() before shuf_exec() draws random bytes. An EOF during the shuffle therefore happens after the output has been truncated. The syscall trace confirms O_TRUNC before the random-source EOF read.
Across 16 cases per binary (four random-source conditions and four output relationships), both GNU versions passed. Each uutils build lost data in all eight empty/short-source cases. Sufficient and missing-source controls passed. The existing shuf integration suite passes: 75 passed, 1 ignored.
Related: #13113 fixed truncation when input or random-source opening fails. This case successfully opens the random source and fails later while reading it. Searches of open/closed issues, PRs, and comments found no report of this remaining exhaustion case.
Please delay destructive output opening until the non-repeating shuffle has completed successfully, and add a regression test for random-source exhaustion with in-place output.
- Ngôn ngữ chính
- Rust
- Star
- 24.3k
- Fork
- 2.1k
- Merge trung bình
- 1 ngày 21 giờ
- Pull request đã merge (30 ngày)
- 357
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
-
Độ 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
-
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
-
U - df
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
U - mv
Độ 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
-
fmt: stops at an unreadable file operand and says only 'read error' for a directoryCó thể đã có người làm @emirmrkaljevic đã nhận 1 ngày trước. Đang mởU - fmt
Độ 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
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 85/100
FalkorDB/FalkorDB#3597 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/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 65/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
mozilla-services/syncstorage-rs#2715 ·
Maintainer thường phản hồi trong vòng 1 ngày