mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-33770: improve base64 exception message for encoded inputs of invalid length (#7416)
This commit is contained in:
parent
98a0e466cd
commit
1b85c71a21
3 changed files with 41 additions and 1 deletions
|
@ -510,7 +510,18 @@ binascii_a2b_base64_impl(PyObject *module, Py_buffer *data)
|
|||
}
|
||||
|
||||
if (leftbits != 0) {
|
||||
PyErr_SetString(Error, "Incorrect padding");
|
||||
if (leftbits == 6) {
|
||||
/*
|
||||
** There is exactly one extra valid, non-padding, base64 character.
|
||||
** This is an invalid length, as there is no possible input that
|
||||
** could encoded into such a base64 string.
|
||||
*/
|
||||
PyErr_SetString(Error,
|
||||
"Invalid base64-encoded string: "
|
||||
"length cannot be 1 more than a multiple of 4");
|
||||
} else {
|
||||
PyErr_SetString(Error, "Incorrect padding");
|
||||
}
|
||||
_PyBytesWriter_Dealloc(&writer);
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue