[CXX Lora] Prevent heap OOB from maliciously crafted Lora Adapters.#27518
Merged
yuslepukhin merged 4 commits intomainfrom Mar 3, 2026
Merged
[CXX Lora] Prevent heap OOB from maliciously crafted Lora Adapters.#27518yuslepukhin merged 4 commits intomainfrom
yuslepukhin merged 4 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens LoRA adapter deserialization by validating that a parameter’s raw_data byte length matches the expected size derived from its declared tensor shape and element type, preventing potential heap out-of-bounds access from crafted adapters.
Changes:
- Add a raw-data-size vs (shape × element-size) validation in
CreateOrtValueOverLoraParameter. - Add unit tests covering valid parameters, short/excess raw data, and end-to-end load failure on mismatch.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| onnxruntime/lora/adapter_format_utils.cc | Adds expected-size computation (with SafeInt) and rejects size mismatches before creating an OrtValue over adapter-owned bytes. |
| onnxruntime/test/lora/lora_test.cc | Adds targeted tests for CreateOrtValueOverLoraParameter and LoraAdapter::Load behavior on raw-data size mismatches. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
skottmckay
reviewed
Mar 3, 2026
skottmckay
approved these changes
Mar 3, 2026
yuslepukhin
added a commit
that referenced
this pull request
Mar 3, 2026
### Description <!-- Describe your changes. --> Non required builds fail because Lora Tests use `ASSERT_THROW` while RTTI is disabled. Followup: #27518
tianleiwu
pushed a commit
that referenced
this pull request
Mar 5, 2026
…27518) ### Description <!-- Describe your changes. --> Detect and test mismatch between raw data size and declared data type and shape of the lora adapter parameter. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> Disallow maliciously crafted lora adapters leading to heap OOB. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
tianleiwu
pushed a commit
that referenced
this pull request
Mar 5, 2026
### Description <!-- Describe your changes. --> Non required builds fail because Lora Tests use `ASSERT_THROW` while RTTI is disabled. Followup: #27518
tianleiwu
added a commit
that referenced
this pull request
Mar 5, 2026
This cherry-picks the following commits for the release: | Commit ID | PR Number | Commit Title | |-----------|-----------|-------------| | d5387d8 | #27192 | Avoid repetitive creation of fp4/fp8 native-custom-op domains for NvTensorRtRtx EP | | 0b9906a | #27454 | Suppress spurious Array Out of Bounds warnings produced by GCC 14.2 compiler on Linux builds | | 4a80b0b | #27471 | Fix double-free in TRT EP custom op domain Release functions | | c7c939f | #27499 | Fix -Warray-bounds build error in MLAS on clang 17+ | | f99dcca | #27514 | [Build] Fix pybind11 vcpkg configuration | | ef04b10 | #27518 | [CXX Lora] Prevent heap OOB from maliciously crafted Lora Adapters. | | 0b2b6d0 | #27288 | [NvTensorRTRTX EP]: Add missing override specifiers to suppress warnings | | c1d8f5c | #27522 | Add "library_path" metadata entry to OrtEpDevice instances for plugin and provider bridge EPs | | fdead1c | #27537 | Account for ORT_NO_EXCEPTIONS builds in Lora test | | 3d1365e | #27521 | increase kMaxValueLength to 8192 | | df8f4a7 | #27535 | Add OrtEnv.DisableDllImportResolver to prevent fatal error on resolver conflict | | bdd672a | #27356 | Add/Update telemetry events | | 2da1a30 | #27543 | Fix RoiAlign heap out-of-bounds read via unchecked batch_indices | | 5c3f544 | #27466 | DQ→MatMulNBits fusion transformer for NvTensorRtRtx ep | --------- Co-authored-by: vishalpandya1990 <vipandya@nvidia.com> Co-authored-by: Vishnudas Thaniel S <vishnudas.thaniel.s@intel.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: Dmitri Smirnov <yuslepukhin@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Stephan Seitz <sseitz@nvidia.com> Co-authored-by: Scott McKay <skottmckay@gmail.com> Co-authored-by: xieofxie <xieofxie@126.com> Co-authored-by: hualxie <hualxie@microsoft.com> Co-authored-by: Darshak Bhatti <47045043+dabhattimsft@users.noreply.github.com> Co-authored-by: Darshak Bhatti <dabhatti@micorsoft.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: anujj <ajalota@nvidia.com> Co-authored-by: praneshgo <227579474+praneshgo@users.noreply.github.com>
This was referenced Mar 9, 2026
This was referenced Mar 16, 2026
deps(nuget): Bump the microsoft-packages group with 8 updates
Ellerbach/azure-ai-search-simulator#76
Closed
This was referenced Mar 23, 2026
deps(nuget): Bump the microsoft-packages group with 8 updates
Ellerbach/azure-ai-search-simulator#80
Closed
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.
Description
Detect and test mismatch between raw data size and declared data type and shape of the lora adapter parameter.
Motivation and Context
Disallow maliciously crafted lora adapters leading to heap OOB.