CVS-183516: Fix offset & length conversion in weight sharing logic as size_t#988
Merged
ankitm3k merged 1 commit intoovep-developfrom Mar 24, 2026
Merged
CVS-183516: Fix offset & length conversion in weight sharing logic as size_t#988ankitm3k merged 1 commit intoovep-developfrom
ankitm3k merged 1 commit intoovep-developfrom
Conversation
… in weight sharing
sfatimar
approved these changes
Mar 24, 2026
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.
CVS-183516: Fix offset & length conversion in weight sharing logic as size_t
Summary
Fixes a Windows-only crash (
std::out_of_range) when creating inference sessions withOVEP weight sharing enabled on models whose external data files exceed 4.29 GB.
Problem
During weight-sharing session creation,
CreateModelWithStrippedQDQNodesiterates overTensorProtoexternal data entries and parses theoffsetandlengthfields — storedas plain decimal strings per the ONNX spec — using
std::stoul:On Windows, MSVC defines
unsigned longas 32-bit (max 4,294,967,295 ≈ 4.29 GB).For models like Phi-Silica PSU2, external tensor offsets into
phi_36_lora_2_5_1.data_proxyreach ~5.67 GB — well above this ceiling.
std::stoulthrowsstd::out_of_rangebeforeany value is assigned, crashing session creation.
The target variables
data_offsetandsizeare already declared assize_t(64-bit onx64), so the overflow happens entirely inside
stoulitself.On Linux, GCC/Clang define
unsigned longas 64-bit so the bug is latent but nottriggered — however the code was still incorrect and non-portable.
Fix
Replace
std::stoulwithstd::from_charsfrom<charconv>(C++17):std::from_charsis the correct tool here for several reasons:std::stoulstd::from_charsunsigned long(32-bit on Windows)size_t= 64-bit)std::out_of_rangeRoot Cause Chain
Files Changed
onnxruntime/core/providers/openvino/qdq_transformations/qdq_stripping.cc#include <charconv>; replace 2×std::stoulwithstd::from_charstargetingsize_tTesting
Validated against Phi-Silica PSU2 with
ep.share_ep_contexts=1on Windows. Sessioncreation completes without
std::out_of_range. No functional change on Linux.