fix(fold): use buffered read to prevent hang on infinite streams like /dev/zero#9966
fix(fold): use buffered read to prevent hang on infinite streams like /dev/zero#9966SaathwikDasari wants to merge 7 commits intouutils:mainfrom
Conversation
|
GNU testsuite comparison: |
CodSpeed Performance ReportMerging #9966 will degrade performance by 6.42%Comparing Summary
Benchmarks breakdown
Footnotes
|
…ev/zero also fixed failure testcases
…ev/zero also fixed failure testcases after cargo fmt
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
| writer.write_all(&output)?; | ||
| output.clear(); | ||
| match std::str::from_utf8(chunk) { | ||
| Ok(s) => process_utf8_line(s, &mut ctx)?, |
There was a problem hiding this comment.
This has the same issue as the following PR: #10396 where multi byte characters that are at the end of a buffer are getting split into multiple characters.
|
It appears that this has already been addressed in another PR: #9274 We should be able to close the associated issue |
Description
Fixes #9845
The previous implementation of
foldattempted to read input line-by-line usingread_until. When processing infinite streams without newlines (such as/dev/zero), this caused the internal buffer to grow indefinitely, leading to a hang or OOM (Out of Memory) crash.Changes
fold_fileto use a fixed-size stack buffer (8KB) andRead::readinstead ofBufRead::read_until./dev/null(guarded by#[cfg(unix)]to avoid Windows CI failures).Verification
fold /dev/zerono longer hangs and streams output correctly.cargo test --package uu_foldpasses.