-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add overflow checks for int to bytes conversions #1860
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
Add overflow checks for int to bytes conversions #1860
Conversation
a67c61b
to
f9ca13a
Compare
Thanks! Please ping me when you are ready for a review. |
One of the Travis failures is for a board running out of space... I'll try implementing this without the intermediate |
f3b4d37
to
4c253af
Compare
For both small and long integers, raise an exception if calling struct.pack, adding an element to an array.array, or formatting an int with int.to_bytes would overflow the requested size.
Initially I used one of the existing exception raise functions, but it's more correct and not much more code to raise OverflowError instead.
4c253af
to
fb7bb40
Compare
@tannewt I think this is ready for a review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this! One request to remove gotos, looks great otherwise!
Rather than jumping to a label when an overflow is known to have occurred, return early when one is known not to have.
@tannewt - goto's removed, please take another look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
For both small and long integers, raise an exception if calling
struct.pack
, adding an element to anarray.array
, or formatting anint
withint.to_bytes
would overflow the requested size.