Add boundary checks for input validation#28747
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR strengthens input validation for the CPU contrib BERT MultiHeadAttention helpers by rejecting invalid past_sequence_length values when past_present_share_buffer is enabled, helping prevent out-of-bounds access into the shared KV-cache buffer.
Changes:
- Add a bounds check in
CheckPastto require0 <= past_sequence_length < max_sequence_length(in buffer-sharing mode). - Improve the INVALID_ARGUMENT error message to include both
max_sequence_lengthand the offending value.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tianleiwu
approved these changes
Jun 2, 2026
This was referenced Jun 20, 2026
deps(nuget): Bump the microsoft-packages group with 1 update
Ellerbach/azure-ai-search-simulator#171
Merged
This was referenced Jun 29, 2026
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 introduces an important input validation in the
multihead_attention_helper.hfile to ensure the integrity of thepast_sequence_lengthparameter. The main change is an additional check that validates the value ofpast_sequence_lengthto prevent invalid or out-of-bounds values.Input validation improvements:
past_sequence_lengthis non-negative and less thanmax_sequence_length, returning an error status if the condition is not met inStatus CheckPastinonnxruntime/contrib_ops/cpu/bert/multihead_attention_helper.h.