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

Throw if unique_ptr or array allocation fails due to SafeInt overflow #18941

Merged

Conversation

skottmckay
Copy link
Contributor

Description

If we fail to calculate the buffer size (due to overflow) we currently return a nullptr. This is inconsistent as an actual memory allocation failure throws. An overflow would typically be due to bad input so an exception makes more sense given that.

Change to throw so code using MakeUniquePtr* and AllocArray* doesn't need to check for nullptr.

Add some extra info to the log message to help debugging.

Motivation and Context

Should help with #18905 by avoiding the invalid attempted usage of a nullptr from the allocation. Extra info might help with figuring out where the overflow is coming from which is the real issue.

…y return a nullptr. This is inconsistent as an actual memory allocation failure throws. An overflow would typically be due to bad input so an exception makes more sense given that.

Change to throw so code using MakeUniquePtr* and AllocArray* doesn't need to check for nullptr.

Add some extra info to the log message to help debugging.

Should help with #18905 by avoiding the invalid attempted usage of a nullptr from the allocation. Extra info _might_ help with figuring out where the overflow is coming from which is the real issue.
Cleanup the 2 places that were checking for a nullptr return and update the documentation to say the methods throw if they cannot allocate memory.
edgchen1
edgchen1 previously approved these changes Dec 28, 2023
…uePtrFromOrtAllocator are allocating `void` and the incorrect value didn't impact the allocation size's correctness.
@skottmckay skottmckay merged commit df740d7 into main Jan 2, 2024
90 of 100 checks passed
@skottmckay skottmckay deleted the skottmckay/ThrowIfWeCantAllocateDueToSizeCalcFailure branch January 2, 2024 21:57
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