Skip to content

Commit a11e1d6

Browse files
dbortfacebook-github-bot
authored andcommitted
Guard against missing list values
Summary: We checked for missing lists on some types, but not all. Add checks to the anything in method.cpp that calls `->items()`. Differential Revision: D68344960
1 parent cd0e584 commit a11e1d6

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

runtime/executor/method.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -414,10 +414,14 @@ Error Method::parse_values() {
414414
new (&values_[i]) EValue(t.get());
415415
} break;
416416
case executorch_flatbuffer::KernelTypes::TensorList: {
417+
const auto items =
418+
static_cast<const executorch_flatbuffer::TensorList*>(val)->items();
419+
ET_CHECK_OR_RETURN_ERROR(
420+
items != nullptr, InvalidProgram, "Missing list at index %zu", i);
417421
// get list of serialization tensors and allocate storage for executor
418422
// tensors
419423
auto tensors = deserialization::parseTensorList(
420-
static_cast<const executorch_flatbuffer::TensorList*>(val)->items(),
424+
items,
421425
values_,
422426
n_value, // The size of the full array.
423427
memory_manager_);
@@ -432,12 +436,15 @@ Error Method::parse_values() {
432436
new (&values_[i]) EValue(tensors.get());
433437
} break;
434438
case executorch_flatbuffer::KernelTypes::OptionalTensorList: {
439+
const auto items =
440+
static_cast<const executorch_flatbuffer::OptionalTensorList*>(val)
441+
->items();
442+
ET_CHECK_OR_RETURN_ERROR(
443+
items != nullptr, InvalidProgram, "Missing list at index %zu", i);
435444
// Same as TensorList but optional<Tensor> instead of Tensor
436445
auto tensors =
437446
deserialization::parseListOptionalType<exec_aten::Tensor>(
438-
static_cast<const executorch_flatbuffer::OptionalTensorList*>(
439-
val)
440-
->items(),
447+
items,
441448
values_,
442449
n_value, // The size of the full array.
443450
memory_manager_);

0 commit comments

Comments
 (0)