From c3f55be7dd012b7e92901627d0b31c21e983ccb4 Mon Sep 17 00:00:00 2001 From: Tal Einat Date: Tue, 12 Jun 2018 15:46:22 +0300 Subject: bpo-27397: Make email module properly handle invalid-length base64 strings (#7583) When attempting to base64-decode a payload of invalid length (1 mod 4), properly recognize and handle it. The given data will be returned as-is, i.e. not decoded, along with a new defect, InvalidBase64LengthDefect. --- Lib/test/test_email/test__header_value_parser.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Lib/test/test_email/test__header_value_parser.py') diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py index 5cdc4bceca..5036de2ca0 100644 --- a/Lib/test/test_email/test__header_value_parser.py +++ b/Lib/test/test_email/test__header_value_parser.py @@ -347,6 +347,15 @@ class TestParser(TestParserMixin, TestEmailBase): errors.InvalidBase64PaddingDefect], '') + def test_get_unstructured_invalid_base64_length(self): + # bpo-27397: Return the encoded string since there's no way to decode. + self._test_get_x(self._get_unst, + '=?utf-8?b?abcde?=', + 'abcde', + 'abcde', + [errors.InvalidBase64LengthDefect], + '') + def test_get_unstructured_no_whitespace_between_ews(self): self._test_get_x(self._get_unst, '=?utf-8?q?foo?==?utf-8?q?bar?=', -- cgit v1.2.1