mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
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.
This commit is contained in:
parent
5a98209180
commit
c3f55be7dd
7 changed files with 70 additions and 18 deletions
|
@ -254,6 +254,23 @@ class TestDefectsBase:
|
|||
self.assertDefectsEqual(self.get_defects(msg),
|
||||
[errors.InvalidBase64CharactersDefect])
|
||||
|
||||
def test_invalid_length_of_base64_payload(self):
|
||||
source = textwrap.dedent("""\
|
||||
Subject: test
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset="utf-8"
|
||||
Content-Transfer-Encoding: base64
|
||||
|
||||
abcde
|
||||
""")
|
||||
msg = self._str_msg(source)
|
||||
with self._raise_point(errors.InvalidBase64LengthDefect):
|
||||
payload = msg.get_payload(decode=True)
|
||||
if self.raise_expected: return
|
||||
self.assertEqual(payload, b'abcde')
|
||||
self.assertDefectsEqual(self.get_defects(msg),
|
||||
[errors.InvalidBase64LengthDefect])
|
||||
|
||||
def test_missing_ending_boundary(self):
|
||||
source = textwrap.dedent("""\
|
||||
To: 1@harrydomain4.com
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue