-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Check for integer overflow in Bytes.extend #934
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
Conversation
@@ -128,6 +128,9 @@ Next version (4.05.0): | |||
|
|||
### Bug fixes | |||
|
|||
- GPR#934: check for integer overflow in Bytes.extend | |||
(Jeremy Yallop) |
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.
Sorting entries by MPR first, GPR second, this should go as the very last item of the category.
let len = length s + left in | ||
if len < 0 then invalid_arg "Bytes.extend" else | ||
let len = len + right in | ||
if len < 0 then invalid_arg "Bytes.extend" else |
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.
I find the shadowing used here not very readable. You could name the first variable len_left
, or declare let (++) a b = (* check for overflow *) let c = a + b in if c < 0 then invalid_arg "Bytes.extend" else c
and let len = length s ++ left ++ right
.
ae0edd6
to
85c27f2
Compare
Thanks for the comments, @gasche. I've updated the patch. I think this may need a bit more care before merging, though, since it rejects Bytes.extend "abc" (-4) 4 which was previously accepted, and had reasonable behaviour. I'll come back to this shortly. |
85c27f2
to
35209c3
Compare
35209c3
to
5de7108
Compare
I'm partial to patches that come with testsuite support. Merged. |
Check for integer overflow in Bytes.extend
* Add compilation flag -caml-apply-inline-fast-path * Use -caml-apply-inline-fast-path for main build and libraries * Inline fast path of caml_apply * Bind args * Refactor and apply the same transformation to Flamba 2. * Pass [ty] argument to [call_caml_apply] * Add a CR about a version of caml_applyN that has only cold path and update a comment.
Current behaviour:
With this fix: