Skip to content

Fix out-of-bounds read in CropBase: validate scale attribute length#28399

Merged
tianleiwu merged 5 commits into
mainfrom
copilot/validate-scale-length-crop
May 14, 2026
Merged

Fix out-of-bounds read in CropBase: validate scale attribute length#28399
tianleiwu merged 5 commits into
mainfrom
copilot/validate-scale-length-crop

Conversation

Copilot AI commented May 7, 2026

Copy link
Copy Markdown
Contributor

Description

CropBase::ValidateInput guarded scale_[0]/scale_[1] access with !scale_.empty() but never enforced scale_.size() == 2. A malformed model with a wrong-length scale attribute (e.g. 1 element) causes an out-of-bounds read in both validation and compute paths.

Changes:

  • contrib_ops/cpu/crop.h — inside the !scale_.empty() branch, return INVALID_ARGUMENT early if scale_.size() != 2 with a descriptive message before any indexing occurs. Compute is protected transitively since it calls ValidateInput first.
  • test/contrib_ops/crop_op_test.cc — added Crop_Invalid_Scale_Size test: passes a 1-element scale attribute and asserts the expected error is returned.

Motivation and Context

scale_ is a user-supplied attribute read directly from the model. Without length validation a malformed model can trigger undefined behavior (out-of-bounds vector read) in both the CPU and CUDA Crop kernels (CUDA inherits CropBase).

@tianleiwu
tianleiwu marked this pull request as ready for review May 7, 2026 22:06
hariharans29
hariharans29 previously approved these changes May 12, 2026
@tianleiwu
tianleiwu enabled auto-merge (squash) May 12, 2026 20:03
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