Skip to content

Fix OOB pointer in TensorAt for sub-byte packed types - #28973

Merged
neilmsft merged 6 commits into
mainfrom
neilmsft/tensoratfix
Jun 15, 2026
Merged

Fix OOB pointer in TensorAt for sub-byte packed types#28973
neilmsft merged 6 commits into
mainfrom
neilmsft/tensoratfix

Conversation

@neilmsft

@neilmsft neilmsft commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Description

Reject sub-byte packed types with appropriate error message. The TensorAt API returns a void*, it fundamentally cannot point to a sub-byte element. The fix is to reject sub-byte types at the API boundary, similar to how strings are rejected. Tests have been updated to reflect the changes.

Motivation and Context

TensorAt computed pointer offsets using logical element indices but Size() returns the byte size of the packed storage unit (1 byte for Int4x2/UInt4x2 which holds 2 elements). This caused out-of-bounds pointer returns when element indices exceeded the actual buffer size.

The API fundamentally cannot return a pointer to a sub-byte element, so reject sub-byte packed types with an appropriate error message, similar to how strings are already rejected.

neilmsft and others added 2 commits June 9, 2026 21:42
TensorAt computed pointer offsets using logical element indices but
Size() returns the byte size of the packed storage unit (1 byte for
Int4x2/UInt4x2 which holds 2 elements). This caused out-of-bounds
pointer returns when element indices exceeded the actual buffer size.

The API fundamentally cannot return a pointer to a sub-byte element,
so reject sub-byte packed types with an appropriate error message,
similar to how strings are already rejected.

Fixes MSRC case 119499 (VULN-191667).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- tensor_at_normal_types_still_work: verifies float, int32, and int8
  tensors still return correct values via TensorAt
- tensor_at_bounds_check: verifies OOB indices, negative indices, and
  wrong dimension count all throw as expected

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread onnxruntime/core/session/onnxruntime_c_api.cc
Comment thread onnxruntime/test/shared_lib/test_inference.cc Outdated
Comment thread onnxruntime/test/shared_lib/test_inference.cc Outdated
@neilmsft
neilmsft requested a review from devang-ml June 11, 2026 04:45
Comment thread onnxruntime/test/shared_lib/test_inference.cc Outdated
edgchen1
edgchen1 previously approved these changes Jun 12, 2026
Comment thread onnxruntime/test/shared_lib/test_inference.cc Outdated
@neilmsft

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree company="Microsoft"

@neilmsft
neilmsft merged commit f490d89 into main Jun 15, 2026
87 checks passed
@neilmsft
neilmsft deleted the neilmsft/tensoratfix branch June 15, 2026 20:45
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.

2 participants