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

4318: prototyp.BigInt: fix int64 parsing overflow #218

Merged
merged 3 commits into from
Mar 4, 2025

Conversation

david-littlefarmer
Copy link
Contributor

@david-littlefarmer david-littlefarmer commented Mar 4, 2025

Ticket: https://github.com/0xsequence/issue-tracker/issues/4318

Previously, parsing a string into BigInt would silently return 0 on overflow of int64 without any warning. This fix ensures that numbers larger than int64 are correctly parsed instead of returning 0, because of overflow.

Also added handling of negative numbers and tests to cover edge cases related to int64 parsing.

@david-littlefarmer david-littlefarmer changed the title prototyp.BigInt: fix int64 parsing overflow 4318: prototyp.BigInt: fix int64 parsing overflow Mar 4, 2025
Copy link
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

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

Looks like you fixed NewBigIntFromString() for all big numbers. What a great bugfix, David. Excellent work!

LGTM

Copy link
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

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

TL;DR: This PR fixes the following bug:

func TestPrototyp(t *testing.T) {
	a := prototyp.NewBigIntFromString("029a2241af62c000c8", 16)
	b := prototyp.NewBigIntFromString("0x029a2241af62c000c8", 16)
	t.Logf("a: %s", a.String())
	t.Logf("b: %s", b.String())
}
=== RUN   TestPrototyp
    prototyp_test.go:12: a: 48000000000000000200
    prototyp_test.go:13: b: 0

@david-littlefarmer david-littlefarmer merged commit 808fcfa into master Mar 4, 2025
1 check passed
@david-littlefarmer david-littlefarmer deleted the prototyp_big_int_parsing_fix branch March 4, 2025 10:35
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