Fix heap overflow - #32553
Open
Akshay Sonawane (apsonawane) wants to merge 1 commit into
Open
Conversation
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
September 10, 2026 21:35
View session
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The validation precedes allocation and copying, with equivalent regression coverage for both implementations.
Pull request overview
Adds CPU and CUDA validation to prevent oversized KV-cache copies from overflowing expanded buffers.
Changes:
- Rejects sequence lengths exceeding the configured maximum.
- Adds CPU and CUDA regression tests.
File summaries
| File | Description |
|---|---|
onnxruntime/contrib_ops/cpu/transformers/generation_device_helper.cc |
Adds CPU bounds validation. |
onnxruntime/contrib_ops/cuda/transformers/generation_device_helper.cc |
Adds CUDA bounds validation. |
onnxruntime/test/contrib_ops/beam_search_test.cc |
Tests CPU rejection behavior. |
onnxruntime/test/providers/cuda/test_cases/generation_cuda_impl_test.cc |
Tests CUDA rejection behavior. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
September 10, 2026 21:55
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 adds input validation to the
ExpandBufferhelper functions for both CPU and CUDA implementations, ensuring that the input sequence length does not exceed the specified maximum sequence length. It also introduces corresponding unit tests to verify this validation logic.Input validation improvements:
GenerationCpuDeviceHelper::ExpandBuffer(generation_device_helper.cc) andGenerationCudaDeviceHelper::ExpandBuffer(generation_device_helper.cc) to return an error if the input sequence length exceeds the maximum allowed sequence length. [1] [2]Testing enhancements:
ExpandBufferRejectsSequenceLengthExceedingMaximumtobeam_search_test.ccfor CPU, which verifies that the function properly rejects inputs with sequence length greater than the maximum.ExpandBufferRejectsSequenceLengthExceedingMaximumtogeneration_cuda_impl_test.ccfor CUDA, ensuring the same validation logic is enforced for CUDA.generation_cuda_impl_test.ccto support the new test.