Skip to content

Commit 700bcb3

Browse files
dbortfacebook-github-bot
authored andcommitted
Check for missing method-related field before creating MethodMeta (#1507)
Summary: Pull Request resolved: #1507 Some MethodMeta methods don't return Error, assuming that the underlying data is valid. Ensure that the underlying ExecutionPlan is valid for those fields before returning a MethodMeta. For fields whose accessors do return Error or Result, we can check them at the time they're called and return non-fatally then. Reviewed By: lucylq Differential Revision: D52451736 fbshipit-source-id: 24e7f603cd53274b46cc6b8ff89f8b084e218c8a
1 parent d3dfd1b commit 700bcb3

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

runtime/executor/program.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ Result<Method> Program::load_method(
227227
internal::event_tracer_create_event_block(event_tracer, "Default");
228228
internal::EventTracerProfileScope event_tracer_scope =
229229
internal::EventTracerProfileScope(event_tracer, "Program::load_method");
230+
// If we can't create a MethodMeta for the Method, the Method is corrupt;
231+
// Method::method_meta() assumes success, so we must fail here.
232+
Result<MethodMeta> meta = method_meta(method_name);
233+
if (!meta.ok()) {
234+
return meta.error();
235+
}
236+
230237
auto plan = get_execution_plan(internal_program_, method_name);
231238
if (!plan.ok()) {
232239
return plan.error();
@@ -239,6 +246,20 @@ Result<MethodMeta> Program::method_meta(const char* method_name) const {
239246
if (!plan.ok()) {
240247
return plan.error();
241248
}
249+
// Check any fields whose accessors don't return Result<> in case they're
250+
// missing or corrupt.
251+
ET_CHECK_OR_RETURN_ERROR(
252+
plan.get()->name() != nullptr, InvalidProgram, "Missing name field");
253+
ET_CHECK_OR_RETURN_ERROR(
254+
plan.get()->non_const_buffer_sizes() != nullptr,
255+
InvalidProgram,
256+
"Missing non_const_buffer_sizes field");
257+
ET_CHECK_OR_RETURN_ERROR(
258+
plan.get()->inputs() != nullptr, InvalidProgram, "Missing inputs field");
259+
ET_CHECK_OR_RETURN_ERROR(
260+
plan.get()->outputs() != nullptr,
261+
InvalidProgram,
262+
"Missing outputs field");
242263
return MethodMeta(plan.get());
243264
}
244265

0 commit comments

Comments
 (0)