forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bpo-27397: Make email module properly handle invalid-length base64 st…
…rings (python#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.
- Loading branch information
Showing
7 changed files
with
70 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -254,6 +254,23 @@ def test_invalid_chars_in_base64_payload(self): | |
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: [email protected] | ||
|
1 change: 1 addition & 0 deletions
1
Misc/NEWS.d/next/Library/2018-06-10-09-43-54.bpo-27397.0_fFQR.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Make email module properly handle invalid-length base64 strings. |