Skip to content

fmt: fix fmt /dev/zero panic#10602

Open
mattsu2020 wants to merge 5 commits intouutils:mainfrom
mattsu2020:fmt_devzero
Open

fmt: fix fmt /dev/zero panic#10602
mattsu2020 wants to merge 5 commits intouutils:mainfrom
mattsu2020:fmt_devzero

Conversation

@mattsu2020
Copy link
Copy Markdown
Contributor

Summary

Prevent unbounded line buffering in fmt by introducing a capped, incremental line reader.
Split oversized paragraphs by byte/line thresholds to keep memory bounded on infinite input.

related
#10580

@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/shuf/shuf-reservoir (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/sort/sort-stale-thread-mem (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/basenc/bounded-memory is now passing!

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 3, 2026

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/follow-name (passes in this run but fails in the 'main' branch)

@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/pr/bounded-memory. tests/pr/bounded-memory is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/tail/symlink (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/factor/t33 is no longer failing!
Congrats! The gnu test tests/factor/t34 is no longer failing!
Note: The gnu test tests/tail/pipe-f is now being skipped but was previously passing.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Feb 14, 2026

Merging this PR will not alter performance

✅ 299 untouched benchmarks
⏩ 46 skipped benchmarks1


Comparing mattsu2020:fmt_devzero (a6a7472) with main (e0f0318)

Open in CodSpeed

Footnotes

  1. 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/factor/t10. tests/factor/t10 is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/factor/t33. tests/factor/t33 is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/factor/t34. tests/factor/t34 is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/tty/tty-eof (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/factor/t28 is no longer failing!
Congrats! The gnu test tests/cut/cut-huge-range is now passing!
Congrats! The gnu test tests/rm/many-dir-entries-vs-OOM is now passing!

@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/timeout/timeout-group. tests/timeout/timeout-group is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/tail/symlink (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/basenc/bounded-memory is now being skipped but was previously passing.

@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/date/date-locale-hour. tests/date/date-locale-hour is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test tests/cut/bounded-memory is no longer failing!
Note: The gnu test tests/printf/printf-surprise is now being skipped but was previously passing.
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.

Replace verbose closure syntax with method reference for cleaner, more idiomatic test assertions.
@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/symlink (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/timeout/timeout-group is no longer failing!
Note: The gnu test tests/seq/seq-epipe is now being skipped but was previously passing.
Congrats! The gnu test tests/tail/tail-n0f is now passing!

@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/csplit/csplit-heap is now passing!

Copy link
Copy Markdown
Contributor

@sylvestre sylvestre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too much added complexity for a rare case
please simplify it

@mattsu2020 mattsu2020 marked this pull request as draft March 24, 2026 11:10
- Removed MAX_PARAGRAPH_BYTES and MAX_PARAGRAPH_LINES constants
- Simplified read_line_limited() to read_limited_line() with cleaner logic
- Improved handling of pending bytes and line splitting
- Removed unused paragraph-related code and constants
- Enhanced memory management for large lines without newlines
Extracted the repeated logic for removing trailing LF or CRLF line endings into a dedicated `strip_line_ending` method to improve code maintainability and reduce duplication across the `read_limited_line` function.
@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/tail/tail-n0f is now being skipped but was previously passing.

@mattsu2020 mattsu2020 requested a review from sylvestre March 24, 2026 11:43
@mattsu2020
Copy link
Copy Markdown
Contributor Author

too much added complexity for a rare case please simplify it

I tried to keep it as simple as possible

@mattsu2020 mattsu2020 marked this pull request as ready for review March 24, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants