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

Check for integer overflows when allocating memory #3549

Merged
merged 1 commit into from
Aug 27, 2019

Conversation

grendello
Copy link
Contributor

Context: android/ndk#294
Context: android/ndk#295
Context: https://bugs.llvm.org/show_bug.cgi?id=16404

Add a couple of functions to Utils taking advantage of the compiler builtin
functions to perform integer addition and multiplication while checking for
overflows. If an overflow is detected, the application is terminated.

Due to a bug in Android NDK's clang, the multiplication is not performed using
"open" types but rather, currently, only size_t for the multiplication
operands.

Using a template for them would result in a link error as the compiler would
generate code to use 128-bit integers to perform the operation, attempting to
call the __muloti4 intrinsic function which is usually defined in libgcc,
libcompiler_rt or libcompiler_rt-extras libraries. In the NDK case the
64-bit targets do not contain implementation of the function in neither of the
libraries mentioned above.

@grendello grendello force-pushed the alloc-overflow-checks branch 2 times, most recently from 596ad3d to 1eb7124 Compare August 26, 2019 12:39
@grendello
Copy link
Contributor Author

/azt run

Context: android/ndk#294
Context: android/ndk#295
Context: https://bugs.llvm.org/show_bug.cgi?id=16404

Add a couple of functions to `Utils` taking advantage of the compiler builtin
functions to perform integer addition and multiplication while checking for
overflows. If an overflow is detected, the application is terminated.

Due to a bug in Android NDK's clang, the multiplication is not performed using
"open" types but rather, currently, only `size_t` for the multiplication
operands.

Using a template for them would result in a link error as the compiler would
generate code to use 128-bit integers to perform the operation, attempting to
call the `__muloti4` intrinsic function which is usually defined in `libgcc`,
`libcompiler_rt` or `libcompiler_rt-extras` libraries. In the NDK case the
64-bit targets do not contain implementation of the function in neither of the
libraries mentioned above.
@grendello
Copy link
Contributor Author

/azt run

@jonpryor jonpryor merged commit f72c91f into dotnet:master Aug 27, 2019
@grendello grendello deleted the alloc-overflow-checks branch August 27, 2019 16:19
@github-actions github-actions bot locked and limited conversation to collaborators Jan 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants