mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.12] gh-118314: Fix padding edge case in binascii.a2b_base64 strict mode (GH-118320) (GH-118691)
gh-118314: Fix padding edge case in binascii.a2b_base64 strict mode (GH-118320)
Fix an edge case in `binascii.a2b_base64` strict mode, where
excessive padding was not detected when no padding is necessary.
(cherry picked from commit fe47d9bee3
)
Co-authored-by: Youfu Zhang <1315097+zhangyoufu@users.noreply.github.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
This commit is contained in:
parent
7b25d945e0
commit
56c61cc564
3 changed files with 23 additions and 0 deletions
|
@ -424,6 +424,13 @@ binascii_a2b_base64_impl(PyObject *module, Py_buffer *data, int strict_mode)
|
|||
if (this_ch == BASE64_PAD) {
|
||||
padding_started = 1;
|
||||
|
||||
if (strict_mode && quad_pos == 0) {
|
||||
state = get_binascii_state(module);
|
||||
if (state) {
|
||||
PyErr_SetString(state->Error, "Excess padding not allowed");
|
||||
}
|
||||
goto error_end;
|
||||
}
|
||||
if (quad_pos >= 2 && quad_pos + ++pads >= 4) {
|
||||
/* A pad sequence means we should not parse more input.
|
||||
** We've already interpreted the data from the quad at this point.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue