Skip to content

Add boundary checks for input validation#28747

Merged
apsonawane merged 1 commit into
mainfrom
asonawane/dmha
Jun 2, 2026
Merged

Add boundary checks for input validation#28747
apsonawane merged 1 commit into
mainfrom
asonawane/dmha

Conversation

@apsonawane

Copy link
Copy Markdown
Contributor

This pull request introduces an important input validation in the multihead_attention_helper.h file to ensure the integrity of the past_sequence_length parameter. The main change is an additional check that validates the value of past_sequence_length to prevent invalid or out-of-bounds values.

Input validation improvements:

  • Added a check to ensure that past_sequence_length is non-negative and less than max_sequence_length, returning an error status if the condition is not met in Status CheckPast in onnxruntime/contrib_ops/cpu/bert/multihead_attention_helper.h.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 CheckPast to require 0 <= past_sequence_length < max_sequence_length (in buffer-sharing mode).
  • Improve the INVALID_ARGUMENT error message to include both max_sequence_length and the offending value.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread onnxruntime/contrib_ops/cpu/bert/multihead_attention_helper.h
@apsonawane apsonawane merged commit a28d46d into main Jun 2, 2026
86 of 87 checks passed
@apsonawane apsonawane deleted the asonawane/dmha branch June 2, 2026 02:38
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.

3 participants