Skip to content

Commit 7ceccdf

Browse files
authored
Add null checks in tensor parser to prevent SIGSEGV (pytorch#19267)
Summary: Add two defensive checks in `tensor_parser_exec_aten.cpp`: 1. `getMemPlannedPtr()`: Validate that the `HierarchicalAllocator` pointer is non-null before dereferencing it. A null allocator causes a SIGSEGV when a model has memory-planned tensors but the caller provides zero planned buffers (T266226256 — wearables Android crash at 0.0003% hit rate). 2. `getTensorDataPtr()`: When a tensor has `allocation_info` (indicating it expects memory-planned storage), validate that the allocator is non-null before any code path reaches `getMemPlannedPtr()`. This is the primary fix; the check in `getMemPlannedPtr` is defense-in-depth. Differential Revision: D103467786
1 parent f1062a7 commit 7ceccdf

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

runtime/executor/tensor_parser_exec_aten.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ ET_NODISCARD Result<void*> getMemPlannedPtr(
4141
const executorch_flatbuffer::AllocationDetails* allocation_info,
4242
size_t nbytes,
4343
HierarchicalAllocator* allocator) {
44+
ET_CHECK_OR_RETURN_ERROR(
45+
allocator != nullptr,
46+
InvalidState,
47+
"HierarchicalAllocator must not be null for memory-planned tensor");
4448
// Normal non-constant Tensor. Allocate data using mem_id and offset.
4549

4650
// TODO(T142455629): make the allocator actually id based and not indexed
@@ -189,6 +193,13 @@ ET_NODISCARD Result<void*> getTensorDataPtr(
189193
const executorch_flatbuffer::AllocationDetails* allocation_info =
190194
s_tensor->allocation_info();
191195

196+
if (allocation_info != nullptr) {
197+
ET_CHECK_OR_RETURN_ERROR(
198+
allocator != nullptr,
199+
InvalidState,
200+
"HierarchicalAllocator is null but tensor has allocation_info requiring memory-planned buffers");
201+
}
202+
192203
// External tensors.
193204
if (s_tensor->extra_tensor_info() != nullptr &&
194205
s_tensor->extra_tensor_info()->location() ==

0 commit comments

Comments
 (0)