From 5f23abc9c769089963a3f12359574feaf97a99c0 Mon Sep 17 00:00:00 2001 From: disqualifier Date: Mon, 6 Jul 2026 00:15:05 -0400 Subject: [PATCH] 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 --- src/aiomail/extract.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aiomail/extract.py b/src/aiomail/extract.py index 4744aee..2fc7abc 100644 --- a/src/aiomail/extract.py +++ b/src/aiomail/extract.py @@ -57,7 +57,7 @@ def _decode_part(part: email.message.Message) -> Optional[str]: charset = part.get_content_charset() or "utf-8" try: return payload.decode(charset, errors="replace") - except (LookupError, TypeError): + except (LookupError, TypeError, ValueError): return payload.decode("utf-8", errors="replace")