Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate evalue indexes in MethodMeta #7581

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions runtime/executor/method_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ Result<Tag> MethodMeta::input_tag(size_t index) const {
index,
num_inputs);
auto input_index = s_plan_->inputs()->Get(index);
size_t num_values = s_plan_->values()->size();
ET_CHECK_OR_RETURN_ERROR(
input_index >= 0 && input_index < num_values,
InvalidProgram,
"internal value index %d out of range [0,%zu) for input %zu",
input_index,
num_values,
index);
auto serialization_value = s_plan_->values()->Get(input_index);
return get_tag(serialization_value, index);
}
Expand All @@ -132,6 +140,7 @@ Result<TensorInfo> MethodMeta::input_tensor_meta(size_t index) const {
(size_t)tag.get(),
index);
auto input_index = s_plan_->inputs()->Get(index);
// input_index was already validated by input_tag().
auto tensor_value = s_plan_->values()->Get(input_index)->val_as_Tensor();
return TensorInfo(
Span<const int32_t>(
Expand All @@ -156,8 +165,16 @@ Result<Tag> MethodMeta::output_tag(size_t index) const {
"index %zu out of range. num_outputs: %zu",
index,
num_outputs);
auto input_index = s_plan_->outputs()->Get(index);
auto serialization_value = s_plan_->values()->Get(input_index);
auto output_index = s_plan_->outputs()->Get(index);
size_t num_values = s_plan_->values()->size();
ET_CHECK_OR_RETURN_ERROR(
output_index >= 0 && output_index < num_values,
InvalidProgram,
"internal value index %d out of range [0,%zu) for output %zu",
output_index,
num_values,
index);
auto serialization_value = s_plan_->values()->Get(output_index);
return get_tag(serialization_value, index);
}

Expand All @@ -173,6 +190,7 @@ Result<TensorInfo> MethodMeta::output_tensor_meta(size_t index) const {
(size_t)tag.get(),
index);
auto output_index = s_plan_->outputs()->Get(index);
// output_index was already validated by output_tag().
auto tensor_value = s_plan_->values()->Get(output_index)->val_as_Tensor();

return TensorInfo(
Expand Down