Skip to content

Commit c44d2d5

Browse files
dbortYIWENX14
authored andcommitted
Validate evalue indexes in MethodMeta
Differential Revision: D68000726 Pull Request resolved: #7581
1 parent 95b2603 commit c44d2d5

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

runtime/executor/method_meta.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ Result<Tag> MethodMeta::input_tag(size_t index) const {
116116
index,
117117
num_inputs);
118118
auto input_index = s_plan_->inputs()->Get(index);
119+
size_t num_values = s_plan_->values()->size();
120+
ET_CHECK_OR_RETURN_ERROR(
121+
input_index >= 0 && input_index < num_values,
122+
InvalidProgram,
123+
"internal value index %d out of range [0,%zu) for input %zu",
124+
input_index,
125+
num_values,
126+
index);
119127
auto serialization_value = s_plan_->values()->Get(input_index);
120128
return get_tag(serialization_value, index);
121129
}
@@ -132,6 +140,7 @@ Result<TensorInfo> MethodMeta::input_tensor_meta(size_t index) const {
132140
(size_t)tag.get(),
133141
index);
134142
auto input_index = s_plan_->inputs()->Get(index);
143+
// input_index was already validated by input_tag().
135144
auto tensor_value = s_plan_->values()->Get(input_index)->val_as_Tensor();
136145
return TensorInfo(
137146
Span<const int32_t>(
@@ -156,8 +165,16 @@ Result<Tag> MethodMeta::output_tag(size_t index) const {
156165
"index %zu out of range. num_outputs: %zu",
157166
index,
158167
num_outputs);
159-
auto input_index = s_plan_->outputs()->Get(index);
160-
auto serialization_value = s_plan_->values()->Get(input_index);
168+
auto output_index = s_plan_->outputs()->Get(index);
169+
size_t num_values = s_plan_->values()->size();
170+
ET_CHECK_OR_RETURN_ERROR(
171+
output_index >= 0 && output_index < num_values,
172+
InvalidProgram,
173+
"internal value index %d out of range [0,%zu) for output %zu",
174+
output_index,
175+
num_values,
176+
index);
177+
auto serialization_value = s_plan_->values()->Get(output_index);
161178
return get_tag(serialization_value, index);
162179
}
163180

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

178196
return TensorInfo(

0 commit comments

Comments
 (0)