Skip to content

Commit 6191529

Browse files
bmehta001Copilot
andcommitted
Use SafeInt for overflow-safe coefficients size validation
Address review feedback: the multiplication of num_targets * num_features could overflow with very large dimensions. Use SafeInt for checked multiplication and also reject negative num_targets. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f2b60a1 commit 6191529

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

onnxruntime/core/providers/cpu/ml/linearregressor.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ Status LinearRegressor::Compute(OpKernelContext* ctx) const {
8989

9090
// Coefficients are treated as a [num_targets, num_features] matrix.
9191
// Validate size to prevent out-of-bounds reads in the GEMM backend.
92-
if (coefficients_.size() != static_cast<size_t>(num_targets_) * static_cast<size_t>(num_features)) {
92+
// Use SafeInt for overflow-safe multiplication.
93+
if (num_targets_ < 0 ||
94+
coefficients_.size() != SafeInt<size_t>(num_targets_) * static_cast<size_t>(num_features)) {
9395
return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT,
9496
"LinearRegressor: coefficients attribute size (", coefficients_.size(),
9597
") does not match targets (", num_targets_,

0 commit comments

Comments
 (0)