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 u64 overflow when decoding #7

Merged
merged 3 commits into from
Dec 21, 2024
Merged

Fix u64 overflow when decoding #7

merged 3 commits into from
Dec 21, 2024

Conversation

Racum
Copy link
Contributor

@Racum Racum commented Dec 8, 2024

I have a scenario where I need to test an ID not knowing before hand if is a valid Sqid or not, and, in some cases when an ID looks valid, but results in elements bigger than the maximum u64 value, the decode() function panics! For example, with the ID 0J4AEXRN106Z0.

To fix this I made to_number() return an Option<u64> (instead of just u64), and only push the value on decode() in case of Some().

By the way, I’m adding support to Sqids to an upcoming version of my ID parser/debug CLI tool, have a look: https://github.com/racum/uuinfo

@4kimov 4kimov merged commit c517814 into sqids:main Dec 21, 2024
1 check failed
@4kimov
Copy link
Member

4kimov commented Dec 21, 2024

Wow, good job catching a panic, and thanks for all the changes! Also, thanks for adding sqids to uuinfo.

I've pushed a few cleanup items, thoughts?

@Racum
Copy link
Contributor Author

Racum commented Dec 21, 2024

Cool, I didn't know the checked_* operations, I think I need to read some std docs! :)

All looks good! 🚀

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