diff --git a/runtime/executor/method.cpp b/runtime/executor/method.cpp index 8eb48480463..2a9859f8d47 100644 --- a/runtime/executor/method.cpp +++ b/runtime/executor/method.cpp @@ -761,7 +761,7 @@ Error Method::resolve_operator( // However, it does not have to be provided, so if it // is not provided (or an empty one is provided), we // fall back to the method allocator. - if (allocator == nullptr || allocator->size() == 0) { + if (allocator == nullptr || allocator->size() == 0 || allocator->size() < (sizeof(TensorMeta) * n_args) + (sizeof(executorch::aten::DimOrderType) * kTensorDimensionLimit * n_args)) { allocator = memory_manager_->method_allocator(); } TensorMeta* meta = allocator->allocateList(n_args); @@ -769,7 +769,7 @@ Error Method::resolve_operator( if (allocator == memory_manager_->temp_allocator()) { memory_manager_->temp_allocator()->reset(); } - return Error::MemoryAllocationFailed; + return Error::MemoryAllocationFailed; } size_t count = 0;