Skip to content

fix(tui): guard backgroundAt against infinite loop on invalid UTF-8 - #3799

Merged
dgageot merged 1 commit into
mainfrom
fix-backgroundat-infinite-loop
Jul 23, 2026
Merged

fix(tui): guard backgroundAt against infinite loop on invalid UTF-8#3799
dgageot merged 1 commit into
mainfrom
fix-backgroundat-infinite-loop

Conversation

@dgageot

@dgageot dgageot commented Jul 23, 2026

Copy link
Copy Markdown
Member

ansi.DecodeSequence can return n == 0 when it encounters invalid UTF-8, such as an isolated continuation byte. The backgroundAt function in the copy-feedback component loops over ANSI sequences until it has consumed the full input, but it never checked for this case — meaning a single bad byte would cause the loop to spin forever and freeze the TUI.

The fix adds an early break when n == 0, preventing the infinite loop regardless of what byte sequence is fed in. A regression test case, "invalid utf-8 terminates", is added to TestBackgroundAt to cover this path.

This follows up on review feedback from #3797 (#3797 (comment)).

Adds an n == 0 break in the decode loop so malformed input that
ansi.DecodeSequence cannot advance past doesn't spin forever.

Assisted-By: Claude
@dgageot
dgageot requested a review from a team as a code owner July 23, 2026 10:08
@dgageot
dgageot merged commit 8448bd9 into main Jul 23, 2026
14 checks passed
@dgageot
dgageot deleted the fix-backgroundat-infinite-loop branch July 23, 2026 10:27
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