Skip to content
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

Fix overflow checking for repeat operation #558

Merged
merged 1 commit into from
Jul 5, 2024

Conversation

marco6
Copy link
Contributor

@marco6 marco6 commented Jul 4, 2024

The current overflow check for repeat operation fails to check when a multiplication wraps to a positive number.

On 64 bits build it is hard to get one (as you would need a tuple/string with more than 2^32 element - but it's still possible).

On a 32 bits build however it is quite trivial:

# tuples and lists return the wrong count
len((1,) * 641 * 6700417) # returns 1
len([1] * 641 * 6700417) # returns 1

# strings/bytes cause panic: strings: Repeat count causes overflow
"a" * 641 * 6700417

This PR uses bits.Mul to make sure that this does not happen.

Copy link
Collaborator

@adonovan adonovan left a comment

Choose a reason for hiding this comment

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

Well spotted! Many thanks for contributing this fix.

@adonovan adonovan merged commit 7000200 into google:master Jul 5, 2024
13 checks passed
@marco6 marco6 deleted the fix-overflow-32bit branch August 29, 2024 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants