Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 33.9k
bpo-43086: Added handling for excess data in binascii.a2b_base64#24402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
52d83e9557bce86ed51934ee90f5c7b723f93f497af6283d9cedbb8569c96d53718ebdd0b60e2afb95db3c5758b5f8df5b644dbaf464484ce1ccf8ad6a5cbf5abc68f08aa26c2f1990efa959bda60a8c60307272d26e1eb652e7f4File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -114,6 +114,47 @@ def addnoise(line): | ||
| # empty strings. TBD: shouldn't it raise an exception instead ? | ||
| self.assertEqual(binascii.a2b_base64(self.type2test(fillers)), b'') | ||
| def test_base64_strict_mode(self): | ||
| # Test base64 with strict mode on | ||
| def _assertRegexTemplate(assert_regex: str, data: bytes, non_strict_mode_expected_result: bytes): | ||
| with self.assertRaisesRegex(binascii.Error, assert_regex): | ||
| binascii.a2b_base64(self.type2test(data), strict_mode=True) | ||
| self.assertEqual(binascii.a2b_base64(self.type2test(data), strict_mode=False), | ||
| non_strict_mode_expected_result) | ||
| self.assertEqual(binascii.a2b_base64(self.type2test(data)), | ||
| non_strict_mode_expected_result) | ||
| def assertExcessData(data, non_strict_mode_expected_result: bytes): | ||
| _assertRegexTemplate(r'(?i)Excess data', data, non_strict_mode_expected_result) | ||
| def assertNonBase64Data(data, non_strict_mode_expected_result: bytes): | ||
| _assertRegexTemplate(r'(?i)Only base64 data', data, non_strict_mode_expected_result) | ||
| def assertMalformedPadding(data, non_strict_mode_expected_result: bytes): | ||
| _assertRegexTemplate(r'(?i)Leading padding', data, non_strict_mode_expected_result) | ||
| # Test excess data exceptions | ||
gpshead marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| assertExcessData(b'ab==a', b'i') | ||
| assertExcessData(b'ab===', b'i') | ||
| assertExcessData(b'ab==:', b'i') | ||
| assertExcessData(b'abc=a', b'i\xb7') | ||
| assertExcessData(b'abc=:', b'i\xb7') | ||
| assertExcessData(b'ab==\n', b'i') | ||
| # Test non-base64 data exceptions | ||
idan22moral marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| assertNonBase64Data(b'\nab==', b'i') | ||
| assertNonBase64Data(b'ab:(){:|:&};:==', b'i') | ||
| assertNonBase64Data(b'a\nb==', b'i') | ||
| assertNonBase64Data(b'a\x00b==', b'i') | ||
| # Test malformed padding | ||
| assertMalformedPadding(b'=', b'') | ||
| assertMalformedPadding(b'==', b'') | ||
| assertMalformedPadding(b'===', b'') | ||
| assertMalformedPadding(b'ab=c=', b'i\xb7') | ||
| assertMalformedPadding(b'ab=ab==', b'i\xb6\x9b') | ||
| def test_base64errors(self): | ||
| # Test base64 with invalid padding | ||
| def assertIncorrectPadding(data): | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Added a new optional :code:`strict_mode` parameter to *binascii.a2b_base64*. | ||
| When :code:`scrict_mode` is set to :code:`True`, the *a2b_base64* function will accept only valid base64 content. | ||
| More details about what "valid base64 content" is, can be found in the function's documentation. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.