-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
integer overflow in binascii.b2a_qp #71947
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
Comments
Thomas E Hybel reports: This vulnerability resides in /Modules/binascii.c in the function The function binascii_b2a_qp_impl qp-encodes binary data. First it computes the /* First, scan to see how many characters need to be encoded */
in = 0;
while (in < datalen) {
if ((databuf[in] > 126) || ... )
{
...
odatalen += 3;
in++;
}
...
} As we can see, each input character can result in more than three odata = (unsigned char *) PyMem_Malloc(odatalen); And finally we encode the input-string and write the result into odata. If our string is so large that "odatalen" will wrap around and become a small Here's a proof-of-concept script: --- begin script --- import binascii
binascii.b2a_qp(b"\x80"*0x531dec0e) # this number gives odatalen=2 --- end script --- Note that this script assumes a 32-bit system where the "odatalen" variable will (gdb) r ../poc3.py Breakpoint 1, binascii_b2a_qp_impl (module=module@entry=0xb7c370f4, Program received signal SIGSEGV, Segmentation fault. |
New changeset af42635b5ed1 by Benjamin Peterson in branch '2.7': New changeset 54c74212db91 by Benjamin Peterson in branch '3.3': New changeset 9822bf4bcece by Benjamin Peterson in branch '3.4': New changeset a277ab6bf66b by Benjamin Peterson in branch '3.5': New changeset 4a00d4ebf60f by Benjamin Peterson in branch 'default': |
The patch seems correct to me. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: