bpo-22602: Raise an exception in the UTF-7 decoder for ill-formed sequences starting with "+". (GH-8741)
The UTF-7 decoder now raises UnicodeDecodeError for ill-formed
sequences starting with "+" (as specified in RFC 2152).
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 04fd6d0..0460d18 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -4479,6 +4479,11 @@
if (_PyUnicodeWriter_WriteCharInline(&writer, '+') < 0)
goto onError;
}
+ else if (s < e && !IS_BASE64(*s)) {
+ s++;
+ errmsg = "ill-formed sequence";
+ goto utf7Error;
+ }
else { /* begin base64-encoded section */
inShift = 1;
surrogate = 0;