Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a security vulnerability (heap OOB) in the Pad operator's reflect mode by validating that pad sizes don't exceed extent - 1 per axis, per the ONNX spec. The fix applies to both CPU and CUDA backends.
Changes:
- Added reflect-mode pad size validation in both CPU and CUDA
Padimplementations - Added comprehensive regression tests covering 1D/2D, pre/post pad, boundary conditions, and slicing scenarios
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| onnxruntime/core/providers/cpu/tensor/pad.cc | Added reflect pad size validation checks |
| onnxruntime/core/providers/cuda/tensor/pad.cc | Added reflect pad size validation checks (has duplicate comment) |
| onnxruntime/test/providers/cpu/tensor/pad_test.cc | Added 8 regression tests for reflect-mode validation; introduced BOM |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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 addresses a critical validation gap in the "reflect" mode of the
Padoperator for both CPU and CUDA backends, ensuring compliance with the ONNX specification and preventing out-of-bounds memory access. The main change is the addition of checks that prevent the pad size from exceeding the maximum allowed value (extent - 1) for each axis, and the introduction of comprehensive regression tests to verify the new behavior.Validation fixes for reflect-mode padding:
onnxruntime/core/providers/cpu/tensor/pad.ccandonnxruntime/core/providers/cuda/tensor/pad.ccto ensure that, for reflect mode, both pre-pad and post-pad values do not exceedextent - 1for each axis, as required by the ONNX spec. This prevents heap out-of-bounds errors and aligns with numpy behavior. [1] [2] [3] [4]Testing and regression coverage:
onnxruntime/test/providers/cpu/tensor/pad_test.ccto verify that invalid pad sizes in reflect mode are correctly rejected, including edge cases for 1D and 2D inputs, boundary conditions, and scenarios with slicing. These tests ensure that the operator fails gracefully when pad sizes exceed the allowed limit and succeeds when within bounds.Other changes:
onnxruntime/test/providers/cpu/tensor/pad_test.cc.