Fix out-of-bounds read in CropBase: validate scale attribute length
Merged
CO
6mo ago+25+25+01234567890123456789-0-0-0123456789
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, returnINVALID_ARGUMENTearly ifscale_.size() != 2with a descriptive message before any indexing occurs.Computeis protected transitively since it callsValidateInputfirst.test/contrib_ops/crop_op_test.cc— addedCrop_Invalid_Scale_Sizetest: passes a 1-elementscaleattribute 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).