Add input validation to LinearClassifier#29060
Merged
Merged
Conversation
…ts, and input shape - Validate classlabels size >= class_count to prevent OOB read in multi-class path - Reject models specifying both classlabels_strings and classlabels_ints - Validate coefficients size is a multiple of class_count at construction - Restrict input to 1-D or 2-D per ONNX spec (reject 3-D+) - Use SafeInt for end_scores pointer arithmetic - Add unit tests for all new validation paths
Contributor
There was a problem hiding this comment.
Pull request overview
This PR strengthens LinearClassifier validation logic (constructor-time attribute checks and runtime input shape checks) to better align operator configuration with expected constraints, and expands unit tests to cover new failure modes and edge cases.
Changes:
- Added construction-time validation for mutually exclusive class label attributes and for coefficient array shape consistency.
- Tightened runtime input shape validation to require 1-D or 2-D inputs, and adjusted tests accordingly (including new 1-D/3-D input cases).
- Introduced
SafeIntusage in score pointer arithmetic to reduce overflow risk.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| onnxruntime/core/providers/cpu/ml/linearclassifier.cc | Adds constructor-time attribute validation, improves input-rank error handling, and hardens score-pointer arithmetic. |
| onnxruntime/test/providers/cpu/ml/linearclassifer_test.cc | Expands/adjusts unit tests to cover new validation paths and updated error messages (with exception guards). |
yuslepukhin
force-pushed
the
yuslepukhin/linearclassifier_109934
branch
2 times, most recently
from
June 15, 2026 23:44
fddb520 to
69edca5
Compare
yuslepukhin
force-pushed
the
yuslepukhin/linearclassifier_109934
branch
from
June 16, 2026 00:49
b1eb7ce to
494c42e
Compare
xadupre
previously approved these changes
Jun 16, 2026
neilmsft
reviewed
Jun 16, 2026
Both-empty classlabels is only safe for binary classification (class_count==1) which has a default 0/1 fallback. The multi-class path unconditionally indexes the classlabels vector, so empty labels with class_count > 1 causes an OOB read. Add constructor-time validation and test coverage.
For binary (class_count==1), the compute path only uses labels when the array has exactly 2 elements. Any other non-empty size was silently ignored. Reject misconfigured models at construction time.
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 adds comprehensive validation checks to the
LinearClassifieroperator to ensure its configuration and input data are consistent with the ONNX specification. It also significantly expands the unit tests to cover new validation logic and edge cases. The main changes are grouped below:Validation and Error Handling Improvements
classlabels_stringsorclasslabels_intsis specified, and validated that the number of class labels matches or exceeds the number of classes defined by intercepts. Also, ensured the coefficients array size is a multiple of the number of classes. These checks are performed during construction and provide clear error messages.SafeIntfor pointer arithmetic in score computation to guard against potential overflow.Unit Test Enhancements
Additional Test Coverage