Validate CUDA NMS mask size - #32014
Merged
Akshay Sonawane (apsonawane) merged 1 commit intoAug 13, 2026
Merged
Conversation
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
August 12, 2026 06:09
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 12, 2026 06:11
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request hardens the CUDA NonMaxSuppression (NMS) implementation against integer overflow by validating the computed NMS mask size before allocating/zeroing the mask buffer, and adds a CUDA-scoped unit test to ensure oversized mask requests are rejected with an expected error.
Changes:
- Compute
max_nms_mask_sizeusingSafeInt<size_t>and fail fast when the mask size would exceedintindexability. - Replace the
ceil(float(...))-based grid size computation forSetZerowith integer math and pass anint-validated element count into the kernel. - Add a CUDA-only unit test that constructs an input size where
num_boxes * bit_mask_lencrossesINT_MAX, asserting the new failure behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| onnxruntime/core/providers/cuda/object_detection/non_max_suppression_impl.cu | Adds safe arithmetic + explicit int-range validation for the NMS mask sizing/allocation/zeroing path to prevent overflow-driven misallocation. |
| onnxruntime/test/providers/cpu/object_detection/non_max_suppression_test.cc | Adds a USE_CUDA-guarded test that runs NMS on CUDA and asserts failure when the required mask size exceeds the supported int range. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ti-Tai Wang (titaiwangms)
approved these changes
Aug 13, 2026
Akshay Sonawane (apsonawane)
deleted the
fix/cuda-nms-mask-size-overflow
branch
August 13, 2026 17:54
This was referenced Sep 10, 2026
Open
This was referenced Sep 14, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request improves the robustness and error handling of the CUDA NonMaxSuppression (NMS) implementation in ONNX Runtime. The changes ensure that large input sizes which could exceed the range of supported integer indices are properly checked and handled, preventing potential overflows or crashes. Additionally, a new CUDA-specific test has been added to verify this behavior.
Error handling and robustness improvements:
max_nms_mask_sizeinnon_max_suppression_impl.cuto useSafeInt<size_t>for safer arithmetic and added a check to ensure the mask size does not exceed the maximum value of anint. If the limit is exceeded, an error is returned. (onnxruntime/core/providers/cuda/object_detection/non_max_suppression_impl.cu)<limits>,core/common/safeint.h>) to support the above changes. (onnxruntime/core/providers/cuda/object_detection/non_max_suppression_impl.cu)Testing enhancements:
onnxruntime/test/providers/cpu/object_detection/non_max_suppression_test.cc)onnxruntime/test/providers/cpu/object_detection/non_max_suppression_test.cc)