Skip to content

Fix misaligned addresses while reading tensor attributes from raw data buffers#27312

Merged
yuslepukhin merged 4 commits intomicrosoft:mainfrom
n-v-k:main
Feb 15, 2026
Merged

Fix misaligned addresses while reading tensor attributes from raw data buffers#27312
yuslepukhin merged 4 commits intomicrosoft:mainfrom
n-v-k:main

Conversation

@n-v-k
Copy link
Contributor

@n-v-k n-v-k commented Feb 11, 2026

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.

@yuslepukhin
Copy link
Member

Thank you for reporting it and taking initiative to fix.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 of raw_data().data() with std::memcpy into properly aligned local variables in scalar tensor equality checks.
  • Applied the same std::memcpy approach when hashing scalar tensor attributes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@yuslepukhin yuslepukhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, review and address all of the Copilot comments.

@n-v-k
Copy link
Contributor Author

n-v-k commented Feb 13, 2026

@yuslepukhin, I made it data type agnostic.
Copilot comments are from outdated review about raw_data usage with memcpy.

Copy link
Member

@yuslepukhin yuslepukhin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, review and address all of the Copilot comments.

@yuslepukhin
Copy link
Member

/azp run Linux QNN CI Pipeline,Win_TRT_Minimal_CUDA_Test_CI,Windows ARM64 QNN CI Pipeline,Windows GPU Doc Gen CI Pipeline

@yuslepukhin yuslepukhin enabled auto-merge (squash) February 15, 2026 18:26
@azure-pipelines
Copy link

Azure Pipelines successfully started running 4 pipeline(s).

@yuslepukhin yuslepukhin merged commit 0df5dbc into microsoft:main Feb 15, 2026
88 checks passed
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.

[Mobile] Android armeabi-v7a 32 bit bus error due to misaligned address

2 participants