Skip to content

Fix UnicodeDecodeError crash on invalid UTF-8 input (#6456)#6498

Open
hamza-mobeen wants to merge 2 commits intoTextualize:mainfrom
hamza-mobeen:fix/utf8-decode-error-6456
Open

Fix UnicodeDecodeError crash on invalid UTF-8 input (#6456)#6498
hamza-mobeen wants to merge 2 commits intoTextualize:mainfrom
hamza-mobeen:fix/utf8-decode-error-6456

Conversation

@hamza-mobeen
Copy link
Copy Markdown

@hamza-mobeen hamza-mobeen commented Apr 17, 2026

Link to issue or discussion

#6456

Summary

The UTF-8 incremental decoders in LinuxDriver, LinuxInlineDriver, and WebDriver default to errors="strict", which raises UnicodeDecodeError when invalid byte sequences are received from the terminal. This kills the input thread and leaves the application unresponsive with no recovery.

This PR changes the decoder to use errors="replace", which substitutes the Unicode replacement character (U+FFFD) for any invalid bytes, matching the behavior described in the issue.

Changes

  • src/textual/drivers/linux_driver.py — line 415: errors="replace"
  • src/textual/drivers/linux_inline_driver.py — line 133: errors="replace"
  • src/textual/drivers/web_driver.py — line 188: errors="replace"
  • tests/test_utf8_decode_resilience.py — new regression test (3 test cases)

AI Disclosure

This PR was generated with the assistance of an AI agent (Antigravity by Google DeepMind). It follows the project's AI_POLICY.md and links to the approved issue above.

@hamza-mobeen
Copy link
Copy Markdown
Author

Hello @willmcgugan,

Please find the proposed fix for issue #6456 attached for your review. This addresses the UnicodeDecodeError threading crashes by implementing a resilient byte replacement strategy across all three input drivers, complete with regression tests.

I look forward to your feedback.

@willmcgugan
Copy link
Copy Markdown
Member

Your tests aren’t testing the code you changed. A regression tests should fail without your change. Yours pass.

@hamza-mobeen
Copy link
Copy Markdown
Author

hamza-mobeen commented Apr 20, 2026

Your tests aren’t testing the code you changed. A regression tests should fail without your change. Yours pass.

@willmcgugan hello, hope you good, I've re written the test, you can check it out when you free. thanks for the feedback

@hamza-mobeen
Copy link
Copy Markdown
Author

hello @willmcgugan

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