diff options
author | Tal Einat <taleinat+github@gmail.com> | 2018-06-10 07:01:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-10 07:01:50 (GMT) |
commit | 1b85c71a2136d3fa6a1da05b27b1fe4e4b8ee45e (patch) | |
tree | 33e452552b363273857b7499558959277171d1d7 /Modules/binascii.c | |
parent | 98a0e466cd94d4635769cfdfd397c43c07384595 (diff) | |
download | cpython-1b85c71a2136d3fa6a1da05b27b1fe4e4b8ee45e.zip cpython-1b85c71a2136d3fa6a1da05b27b1fe4e4b8ee45e.tar.gz cpython-1b85c71a2136d3fa6a1da05b27b1fe4e4b8ee45e.tar.bz2 |
bpo-33770: improve base64 exception message for encoded inputs of invalid length (#7416)
Diffstat (limited to 'Modules/binascii.c')
-rw-r--r-- | Modules/binascii.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Modules/binascii.c b/Modules/binascii.c index 59e99282..5667018 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -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; } |