Skip to content

gh-101178: Fix possible integer overflow in Ascii85 encoder with wrapcol=1#144778

Open
serhiy-storchaka wants to merge 1 commit intopython:mainfrom
serhiy-storchaka:ascii85-encode-integer-overflow
Open

gh-101178: Fix possible integer overflow in Ascii85 encoder with wrapcol=1#144778
serhiy-storchaka wants to merge 1 commit intopython:mainfrom
serhiy-storchaka:ascii85-encode-integer-overflow

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Feb 13, 2026

It could happen if the size of the input is more than 4/5 of sys.maxsize (only feasible on 32-bit platforms).

Also simplify the integer overflow checks in the Base64 encoder, and harmonize them with the code for Ascii85 and Base85.

…h wrapcol=1

It could happen if the size of the input is more than 4/5 of sys.maxsize
(only feasible on 32-bit platforms).

Also simplify the integer overflow checks in the Base64 encoder, and
harmonize them with the code for Ascii85 and Base85.
out_len -= 4 - (bin_len % 4);
}
if (wrapcol && out_len) {
if (wrapcol && out_len && out_len <= PY_SSIZE_T_MAX) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if I'm misunderstanding, but wouldn't we need to "error out" if the out_len would overflow here instead of not expanding? The larger amount of data will still be written outside ascii_data whether out_len is expanded or not?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We error out in the next "if".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants