fix: tolerate NUL-bearing charset in part decode
a MIME part charset param containing a NUL character (e.g. malformed/adversarial .eml input) makes codec lookup raise ValueError instead of the LookupError/TypeError already handled here, escaping uncaught through extract_code. Catch ValueError too and fall back to utf-8 like the existing bad-charset path, mirroring decode_header_value's existing (UnicodeDecodeError, LookupError, ValueError) pattern. Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
@@ -57,7 +57,7 @@ def _decode_part(part: email.message.Message) -> Optional[str]:
|
|||||||
charset = part.get_content_charset() or "utf-8"
|
charset = part.get_content_charset() or "utf-8"
|
||||||
try:
|
try:
|
||||||
return payload.decode(charset, errors="replace")
|
return payload.decode(charset, errors="replace")
|
||||||
except (LookupError, TypeError):
|
except (LookupError, TypeError, ValueError):
|
||||||
return payload.decode("utf-8", errors="replace")
|
return payload.decode("utf-8", errors="replace")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user