canonical / craft-cli

https://canonical-craft-cli.readthedocs-hosted.com/en/latest/
GNU Lesser General Public License v3.0
9 stars 14 forks source link

Bad handling of non-utf8 text in _PipeReaderThread #221

Closed tigarmo closed 6 months ago

tigarmo commented 6 months ago

Bug Description

the naked decode("utf-8") in _write() breaks when the incoming text isn't valid utf-8.

To Reproduce

See related issue in Snapcraft: https://github.com/snapcore/snapcraft/issues/4515

part yaml

No response

Relevant log output

:: [build HPX] el/helpcontent2/source/text/simpress/guide
:: Entity: line 1: parser error : Opening and ending tag mismatch: switchinline line 1 and root
Exception in thread Thread-45:
Traceback (most recent call last):
  File "/snap/snapcraft/10279/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/snap/snapcraft/10279/lib/python3.10/site-packages/craft_cli/messages.py", line 285, in run
    self._run_posix()
  File "/snap/snapcraft/10279/lib/python3.10/site-packages/craft_cli/messages.py", line 257, in _run_posix
    self._write(data)
  File "/snap/snapcraft/10279/lib/python3.10/site-packages/craft_cli/messages.py", line 242, in _write
    unicode_line = useful_line.decode("utf8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbc in position 0: invalid start byte