From c064debacd70e5ff10b3a46535baf846ffe8e62a Mon Sep 17 00:00:00 2001 From: Github Executorch Date: Wed, 4 Mar 2026 22:52:05 -0800 Subject: [PATCH] Guard BackendDelegate::Init against null compile_specs The FlatBuffer schema defines compile_specs as optional, but the code unconditionally dereferenced it. Add a null check so delegates without compile_specs get initialized with an empty spec list instead of crashing. Addresses TOB-EXECUTORCH-38. This PR was authored with the assistance of Claude. --- runtime/executor/method.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/runtime/executor/method.cpp b/runtime/executor/method.cpp index 606b2460155..2abf8f175d5 100644 --- a/runtime/executor/method.cpp +++ b/runtime/executor/method.cpp @@ -86,14 +86,17 @@ class BackendDelegate final { } // Parse compilation specs from program - CompileSpec* compile_specs; - Error err = PopulateCompileSpecs( - delegate.compile_specs(), backend_init_context, &compile_specs); - if (err != Error::Ok) { - ET_LOG(Error, "Failed to get compile specs for backend %s", backend_id); - return err; + CompileSpec* compile_specs = nullptr; + size_t num_compile_specs = 0; + if (delegate.compile_specs() != nullptr) { + Error err = PopulateCompileSpecs( + delegate.compile_specs(), backend_init_context, &compile_specs); + if (err != Error::Ok) { + ET_LOG(Error, "Failed to get compile specs for backend %s", backend_id); + return err; + } + num_compile_specs = delegate.compile_specs()->size(); } - size_t num_compile_specs = delegate.compile_specs()->size(); out->backend_ = backend; out->handle_ = nullptr;