From f0fa55217c376a54c90969596dcda4d1684113ca Mon Sep 17 00:00:00 2001 From: RJ Ascani Date: Fri, 1 May 2026 16:48:28 -0700 Subject: [PATCH] Add null checks in tensor parser to prevent SIGSEGV MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- runtime/executor/tensor_parser_exec_aten.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/runtime/executor/tensor_parser_exec_aten.cpp b/runtime/executor/tensor_parser_exec_aten.cpp index 5267a089d60..31ec2377f16 100644 --- a/runtime/executor/tensor_parser_exec_aten.cpp +++ b/runtime/executor/tensor_parser_exec_aten.cpp @@ -41,6 +41,10 @@ ET_NODISCARD Result getMemPlannedPtr( const executorch_flatbuffer::AllocationDetails* allocation_info, size_t nbytes, HierarchicalAllocator* allocator) { + ET_CHECK_OR_RETURN_ERROR( + allocator != nullptr, + InvalidState, + "HierarchicalAllocator must not be null for memory-planned tensor"); // Normal non-constant Tensor. Allocate data using mem_id and offset. // TODO(T142455629): make the allocator actually id based and not indexed @@ -189,6 +193,13 @@ ET_NODISCARD Result getTensorDataPtr( const executorch_flatbuffer::AllocationDetails* allocation_info = s_tensor->allocation_info(); + if (allocation_info != nullptr) { + ET_CHECK_OR_RETURN_ERROR( + allocator != nullptr, + InvalidState, + "HierarchicalAllocator is null but tensor has allocation_info requiring memory-planned buffers"); + } + // External tensors. if (s_tensor->extra_tensor_info() != nullptr && s_tensor->extra_tensor_info()->location() ==