mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-devtest
synced 2026-01-15 02:22:56 +01:00
os.Connection._read(): Safeguard against non-utf8
Don't try to decode non-UTF-8 garbage as UTF-8 if it shows up in _read(). Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
6239c0546a
commit
ab8b04ad30
1 changed files with 5 additions and 1 deletions
|
|
@ -120,7 +120,11 @@ class Connection(ABC): # export
|
||||||
r = await self._read(act_timeout, flags)
|
r = await self._read(act_timeout, flags)
|
||||||
if r is not None:
|
if r is not None:
|
||||||
if flags & self.Flags.ReadDecodeToString:
|
if flags & self.Flags.ReadDecodeToString:
|
||||||
r = r.decode('utf-8')
|
try:
|
||||||
|
r = r.decode('utf-8', errors='replace')
|
||||||
|
except Exception as e:
|
||||||
|
slog(WARNING, 'Failed to decode string, returning undecoded ({}): "{}"'.format(e, r))
|
||||||
|
return str(r)
|
||||||
if flags & self.Flags.ReadStripNewline:
|
if flags & self.Flags.ReadStripNewline:
|
||||||
if len(r) and r[-1] == '\n':
|
if len(r) and r[-1] == '\n':
|
||||||
r = r[0:-1]
|
r = r[0:-1]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue