mirror of
https://github.com/python/cpython
synced 2024-09-05 16:38:56 +00:00
bpo-44678: Separate error message for discontinuous padding in binascii.a2b_base64 strict mode (GH-27249)
* Renamed assertLeadingPadding function to match logic * Added a separate error message for discontinuous padding * Updated the tests for discontinuous padding
This commit is contained in:
parent
e25e43e355
commit
366fcbac18
|
@ -130,9 +130,12 @@ def assertExcessData(data, non_strict_mode_expected_result: bytes):
|
|||
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):
|
||||
def assertLeadingPadding(data, non_strict_mode_expected_result: bytes):
|
||||
_assertRegexTemplate(r'(?i)Leading padding', data, non_strict_mode_expected_result)
|
||||
|
||||
def assertDiscontinuousPadding(data, non_strict_mode_expected_result: bytes):
|
||||
_assertRegexTemplate(r'(?i)Discontinuous padding', data, non_strict_mode_expected_result)
|
||||
|
||||
# Test excess data exceptions
|
||||
assertExcessData(b'ab==a', b'i')
|
||||
assertExcessData(b'ab===', b'i')
|
||||
|
@ -148,11 +151,11 @@ def assertMalformedPadding(data, non_strict_mode_expected_result: bytes):
|
|||
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')
|
||||
assertLeadingPadding(b'=', b'')
|
||||
assertLeadingPadding(b'==', b'')
|
||||
assertLeadingPadding(b'===', b'')
|
||||
assertDiscontinuousPadding(b'ab=c=', b'i\xb7')
|
||||
assertDiscontinuousPadding(b'ab=ab==', b'i\xb6\x9b')
|
||||
|
||||
|
||||
def test_base64errors(self):
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Added a separate error message for discontinuous padding in *binascii.a2b_base64* strict mode.
|
|
@ -464,7 +464,6 @@ binascii_a2b_base64_impl(PyObject *module, Py_buffer *data, int strict_mode)
|
|||
unsigned char *bin_data_start = bin_data;
|
||||
|
||||
if (strict_mode && ascii_len > 0 && ascii_data[0] == '=') {
|
||||
malformed_padding:
|
||||
state = get_binascii_state(module);
|
||||
if (state) {
|
||||
PyErr_SetString(state->Error, "Leading padding not allowed");
|
||||
|
@ -516,7 +515,11 @@ binascii_a2b_base64_impl(PyObject *module, Py_buffer *data, int strict_mode)
|
|||
|
||||
// Characters that are not '=', in the middle of the padding, are not allowed
|
||||
if (strict_mode && padding_started) {
|
||||
goto malformed_padding;
|
||||
state = get_binascii_state(module);
|
||||
if (state) {
|
||||
PyErr_SetString(state->Error, "Discontinuous padding not allowed");
|
||||
}
|
||||
goto error_end;
|
||||
}
|
||||
pads = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue