8000 bpo-43086: Added handling for excess data in binascii.a2b_base64 by idan22moral · Pull Request #24402 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 26 commits into from
Jul 19, 2021
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
52d83e9
Added handling for excess data in binascii.a2b_base64
idan22moral Jan 31, 2021
557bce8
📜🤖 Added by blurb_it.
blurb-it[bot] Jan 31, 2021
6ed5193
Added if-state guard
idan22moral Mar 13, 2021
4ee90f5
Merge branch 'master' of https://github.com/idan22moral/cpython
idan22moral Mar 30, 2021
c7b723f
Implemented the strict mode logic
idan22moral Mar 30, 2021
93f497a
Merge branch 'master' of https://github.com/python/cpython
idan22moral Mar 30, 2021
f6283d9
Trying to fix the "Check if generated files are up to date" failure
idan22moral Apr 7, 2021
cedbb85
Generated function signatures using clinic
idan22moral Apr 7, 2021
69c96d5
Handle data in the middle of the padding in strict mode
idan22moral Apr 12, 2021
3718ebd
Added a test for strict mode
idan22moral Apr 12, 2021
d0b60e2
Added a test for invalid data as the first character
idan22moral Jul 10, 2021
afb95db
Disallowed leading padding in strict mode
idan22moral Jul 10, 2021
3c5758b
Added tests for padding-only input
idan22moral Jul 10, 2021
5f8df5b
Added tests to validate the default behavior.
idan22moral Jul 10, 2021
644dbaf
Described the changed of this pull request
idan22moral Jul 10, 2021
464484c
Modified syntax of RST
idan22moral Jul 10, 2021
e1ccf8a
Updated the docs to explain the strict_mode parameter
idan22moral Jul 10, 2021
d6a5cbf
Moved declaration of state to the beginning to prevent multiple decla…
idan22moral Jul 16, 2021
5abc68f
Merge branch 'main' into master
idan22moral Jul 16, 2021
08aa26c
Corrected the RST syntax for argument in docs (italic)
idan22moral Jul 16, 2021
2f1990e
Corrected the RST syntax for argument in news (italic)
idan22moral Jul 16, 2021
fa959bd
Removed whitespace that lead to build failure
idan22moral Jul 16, 2021
a60a8c6
use self.assertEqual instead of assert ==
gpshead Jul 18, 2021
0307272
remove leadg `| ` characters in NEWS
gpshead Jul 18, 2021
d26e1eb
Simplify the error messages.
gpshead Jul 18, 2021
652e7f4
update test for error message (Leading vs Malformed)
gpshead Jul 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved declaration of state to the beginning to prevent multiple decla…
…raions under the same scope.

This should fix the build errors.
  • Loading bran 8000 ch information
idan22moral committed Jul 16, 2021
commit d6a5cbfbc688711f6f53596e1722865455eb7957
21 changes: 11 additions & 10 deletions Modules/binascii.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ binascii_a2b_base64_impl(PyObject *module, Py_buffer *data, int strict_mode)

const unsigned char *ascii_data = data->buf;
size_t ascii_len = data->len;
binascii_state *state = NULL;
char padding_started = 0;

/* Allocate the buffer */
Expand All @@ -463,7 +464,12 @@ 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] == '=') {
goto malformed_padding;
malformed_padding:
state = PyModule_GetState(module);
if (state) {
PyErr_SetString(state->Error, "Malformed padding in strict mode");
}
goto error_end;
}

int quad_pos = 0;
Expand All @@ -484,7 +490,7 @@ binascii_a2b_base64_impl(PyObject *module, Py_buffer *data, int strict_mode)
** in strict mode, an error should raise if there's excess data after the padding.
*/
if (strict_mode && i + 1 < ascii_len) {
binascii_state *state = PyModule_GetState(module);
state = PyModule_GetState(module);
if (state) {
PyErr_SetString(state->Error, "Excess data after padding is not allowed when using strict mode");
}
Expand All @@ -499,7 +505,7 @@ binascii_a2b_base64_impl(PyObject *module, Py_buffer *data, int strict_mode)
this_ch = table_a2b_base64[this_ch];
if (this_ch >= 64) {
if (strict_mode) {
binascii_state *state = PyModule_GetState(module);
state = PyModule_GetState(module);
if (state) {
PyErr_SetString(state->Error, "Only base64 data is allowed when using strict mode");
}
Expand All @@ -510,12 +516,7 @@ 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) {
malformed_padding:
binascii_state *state = PyModule_GetState(module);
if (state) {
PyErr_SetString(state->Error, "Malformed padding in strict mode");
}
goto error_end;
goto malformed_padding;
}
pads = 0;

Expand Down Expand Up @@ -543,7 +544,7 @@ binascii_a2b_base64_impl(PyObject *module, Py_buffer *data, int strict_mode)
}

if (quad_pos != 0) {
binascii_state *state = PyModule_GetState(module);
495B state = PyModule_GetState(module);
if (state == NULL) {
/* error already set, from PyModule_GetState */
} else if (quad_pos == 1) {
Expand Down
0