Fix misaligned addresses while reading tensor attributes from raw data buffers#27312
Fix misaligned addresses while reading tensor attributes from raw data buffers#27312yuslepukhin merged 4 commits intomicrosoft:mainfrom
Conversation
|
Thank you for reporting it and taking initiative to fix. |
There was a problem hiding this comment.
Pull request overview
This PR hardens Common Subexpression Elimination’s handling of scalar tensor attributes stored in TensorProto::raw_data() by avoiding undefined behavior from misaligned pointer dereferences (notably impacting ARM32).
Changes:
- Replaced
reinterpret_cast<T*>dereferences ofraw_data().data()withstd::memcpyinto properly aligned local variables in scalar tensor equality checks. - Applied the same
std::memcpyapproach when hashing scalar tensor attributes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
yuslepukhin
left a comment
There was a problem hiding this comment.
Please, review and address all of the Copilot comments.
|
@yuslepukhin, I made it data type agnostic. |
yuslepukhin
left a comment
There was a problem hiding this comment.
Please, review and address all of the Copilot comments.
|
/azp run Linux QNN CI Pipeline,Win_TRT_Minimal_CUDA_Test_CI,Windows ARM64 QNN CI Pipeline,Windows GPU Doc Gen CI Pipeline |
|
Azure Pipelines successfully started running 4 pipeline(s). |
Description
Explicitly copy tensor attribute values from raw data buffers instead of directly using pointers without checking proper memory alignment.
Motivation and Context
Fixes #27311
With some (rare) models ONNXRuntime built for Android armeabi-v7a 32 bit architecture crashes with bus error. Raw data buffers for tensor attributes of type
char*has no proper alignment guarantees while reading values from them.Actually, it is in general (not only Android armeabi-v7a) UB to access objects at a misaligned address in C++, though many modern platforms allow it.