Skip to content

Commit a4c0fc0

Browse files
author
Github Executorch
committed
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.
1 parent 2dd9034 commit a4c0fc0

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

runtime/executor/method.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,17 @@ class BackendDelegate final {
8686
}
8787

8888
// Parse compilation specs from program
89-
CompileSpec* compile_specs;
90-
Error err = PopulateCompileSpecs(
91-
delegate.compile_specs(), backend_init_context, &compile_specs);
92-
if (err != Error::Ok) {
93-
ET_LOG(Error, "Failed to get compile specs for backend %s", backend_id);
94-
return err;
89+
CompileSpec* compile_specs = nullptr;
90+
size_t num_compile_specs = 0;
91+
if (delegate.compile_specs() != nullptr) {
92+
Error err = PopulateCompileSpecs(
93+
delegate.compile_specs(), backend_init_context, &compile_specs);
94+
if (err != Error::Ok) {
95+
ET_LOG(Error, "Failed to get compile specs for backend %s", backend_id);
96+
return err;
97+
}
98+
num_compile_specs = delegate.compile_specs()->size();
9599
}
96-
size_t num_compile_specs = delegate.compile_specs()->size();
97100

98101
out->backend_ = backend;
99102
out->handle_ = nullptr;

0 commit comments

Comments
 (0)