aboutsummaryrefslogtreecommitdiff
path: root/b4/__init__.py
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2021-07-18 00:34:05 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2021-08-03 11:46:41 -0400
commit50dd627b9658081b8f9ddf2466ebb4b174684a55 (patch)
tree9ec9fd3f96fa38a827a6d5c2c26223a05b331c3b /b4/__init__.py
parent6edc636bb497de461739e10000a29165df08c3dc (diff)
downloadb4-50dd627b9658081b8f9ddf2466ebb4b174684a55.tar.gz
Avoid decoding errors when extracting message ID from stdin
The mbox, am, and pr subcommands accept an mbox on stdin and extract the message ID. When stdin.read() is called, Python assumes the encoding is locale.getpreferredencoding(False). This may not match the content encoding, leading to a decoding error. Instead feed the stdin bytes to message_from_bytes(), which leads to a decode('ASCII', errors='surrogateescape') underneath. That's sufficient to get the message ID from the ASCII headers. Reported-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Kyle Meyer <kyle@kyleam.com> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Diffstat (limited to 'b4/__init__.py')
-rw-r--r--b4/__init__.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/b4/__init__.py b/b4/__init__.py
index c019358..bc05dcd 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -2075,7 +2075,7 @@ def get_requests_session():
def get_msgid_from_stdin():
if not sys.stdin.isatty():
- message = email.message_from_string(sys.stdin.read())
+ message = email.message_from_bytes(sys.stdin.buffer.read())
return message.get('Message-ID', None)
return None