Fix panic when wrapping a wide char with a background at tiny width - #3890
Open
nagendramohan wants to merge 3 commits into
Open
Fix panic when wrapping a wide char with a background at tiny width#3890nagendramohan wants to merge 3 commits into
nagendramohan wants to merge 3 commits into
Conversation
bat aborts with 'capacity overflow' running e.g.
printf '📦📦\n' | bat --terminal-width 1 --wrap character \
--highlight-line 1 --color always
When a character is wider than the terminal (a double-width CJK char or
emoji) and a background is painted on the line, the per-line cursor
advances past cursor_max, and the background fill computes
" ".repeat(cursor_max - cursor) — a usize subtraction that underflows
and aborts inside str::repeat.
Clamp the fill width with saturating_sub so a terminal narrower than a
single glyph yields an empty fill instead of underflowing, mirroring the
clamping bat already applies elsewhere.
Adds a regression test (verified failing before the fix) and CHANGELOG
entry. Closes sharkdp#3844.
Signed-off-by: Nagendra Mohan <nagendramohan1990@gmail.com>
Signed-off-by: Nagendra Mohan <nagendramohan1990@gmail.com>
Signed-off-by: Nagendra Mohan <nagendramohan1990@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
bat aborts with 'capacity overflow' running e.g.
When a character is wider than the terminal (a double-width CJK char or emoji) and a background is painted on the line, the per-line cursor advances past cursor_max, and the background fill computes " ".repeat(cursor_max - cursor) — a usize subtraction that underflows and aborts inside str::repeat.
Clamp the fill width with saturating_sub so a terminal narrower than a single glyph yields an empty fill instead of underflowing, mirroring the clamping bat already applies elsewhere.
Adds a regression test (verified failing before the fix) and CHANGELOG entry. Closes #3844.
Fixes #3844.
bat aborts with capacity overflow on e.g.:
When a character is wider than the terminal (a double-width CJK char or emoji) and a background is painted on the line, the per-line cursor advances
past cursor_max, so the background fill " ".repeat(cursor_max - cursor) (src/printer.rs) does a usize subtraction that underflows and aborts inside
str::repeat.
Fix: clamp the fill width with saturating_sub, so a terminal narrower than a single glyph yields an empty fill instead of underflowing — mirroring the clamping bat already applies elsewhere. Same defect class as the --style=snip width-1 panic (#3803).
Adds a regression test (verified failing before the fix) and a CHANGELOG entry. cargo fmt --check, cargo clippy, and the full integration suite (255 tests) all pass locally.