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:
2026-07-06 00:15:05 -04:00
parent 0d88764510
commit 5f23abc9c7
+1 -1
View File
@@ -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")