-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbd in position 6: invalid start byte #20791
Comments
Thanks for the bug report, this is fairly easy to reproduce:
Then in cockpit, @allisonkarlitskaya are you interested in fixing this? |
Possibly related: #20628 |
@jciesla can you please elaborate on "latest versions"? Is there a known version of Cockpit that this definitely does not occur with? |
This is caused by this line: self.decoder = codecs.getincrementaldecoder('utf-8')(errors='strict') Having the decoder in strict mode is probably a bad idea. We ought to loosen that up to ignore/replace/surrogate errors. Replace, I guess. |
Hello @allisonkarlitskaya, on version 300.3 the problem is definitely not present. I tested with versions 321 and 318. On version 318 the problem occurs but less often (no black display, only colors issue). |
@allisonkarlitskaya No, no, no. This is the protocol level, strict errors was very deliberate. I'd hate to introduce "let's try to interpret junk as something interpretable" on that low level. This is a websocket, and it's UTF-8 (which is what triggered the whole commit 1b15dcb in the first place). In situations where we can't guarantee UTF-8 or anything else, IMHO the only correct option is |
... and of course the bridge shouldn't crash unceremoniously like that, but close the channel with |
This is a lot more subtle than it appears. First of all, I created a new unit test: @pytest.mark.asyncio
async def test_fsread1_invalid_utf8(transport: MockTransport, tmp_path: Path) -> None:
f = tmp_path / 'valid'
data = b'hello' + bytes([0xFF, 0xFF]) + b'world'
f.write_bytes(data)
ch = await transport.check_open('fsread1', path=str(f))
transport.send_done(ch)
await transport.assert_msg('', command='close', channel=ch, problem='protocol-error')
transport.send_close(ch) but instead of failing, it receives exactly "helloworld" (without the broken binary junk) both on current main and with commit 1b15dcb reverted. |
Ah, this is because the fsread1 channel is outright evil!
I.e. it silently gives you wrong information. This should be fixed separately, and I'll do this with the http channel. |
Unlike most other code paths, raising a ChannelError in data_received() did not get translated to a proper close message. In particular, this caused an unhandled bridge exception in __decode_frame() when a text channel encountered non-UTF8 data since commit 1b15dcb. Side issue in cockpit-project#20791
Terminals are not defined/required to be UTF-8 only. Sometimes people cat binary data to the terminal, or possibly files in other encodings. These cannot be sent through `TEXT` websocket channels, and will also trigger the additional checks from commit 1b15dcb. Use a binary channel to avoid all that. XTerm.js gets along with this just fine, and it ignores invalid data. With this you can now even `cat /bin/true` and get something moderately sensible, instead of no output at all. Fixes cockpit-project#20791
Fixed in #20840 |
Terminals are not defined/required to be UTF-8 only. Sometimes people cat binary data to the terminal, or possibly files in other encodings. These cannot be sent through `TEXT` websocket channels, and will also trigger the additional checks from commit 1b15dcb. Use a binary channel to avoid all that. XTerm.js gets along with this just fine, and it ignores invalid data. With this you can now even `cat /bin/true` and get something moderately sensible, instead of no output at all. Fixes #20791
Thank you for the fix. I tested on my side and all is now working correctly. |
Explain what happens
In the latest versions of Cockpit I sometimes have difficulty opening files in the terminal tool with vim. The problem is intermittent but occurs often. Sometimes I can open the file, sometimes I can't (just a black screen), and sometimes I can open the file but the colors are changed.
Cockpit v321
Python 3.12.4
Kernel 6.6.35
Systemd 255
By exemple, for editing the file /etc/e2scrub.conf (can be any other file) :
Edition is working as expected:
Edition is working but with other colors:
Edition is not working:
When result is not the expected (wrong color or not viewable), I get python errors on journald (please see the attached traces).
Version of Cockpit
~321
Where is the problem in Cockpit?
Terminal
Server operating system
other
Server operating system version
No response
What browsers are you using?
Chrome
System log
The text was updated successfully, but these errors were encountered: