@@ -25,7 +25,8 @@ ET_NODISCARD Result<executorch::aten::Tensor> parseTensor(
2525
2626ET_NODISCARD Result<BoxedEvalueList<executorch::aten::Tensor>> parseTensorList (
2727    const  flatbuffers::Vector<int32_t >* tensor_indices,
28-     EValue* values_,
28+     EValue* values,
29+     size_t  values_len,
2930    MemoryManager* memory_manager);
3031
3132//  Deserializes a List of optional type. The code here is the same between all
@@ -35,7 +36,8 @@ template <typename T>
3536ET_NODISCARD Result<BoxedEvalueList<executorch::aten::optional<T>>>
3637parseListOptionalType (
3738    const  flatbuffers::Vector<int32_t >* value_indices,
38-     EValue* values_,
39+     EValue* values,
40+     size_t  values_len,
3941    MemoryManager* memory_manager) {
4042  auto * evalp_list = memory_manager->method_allocator ()->allocateList <EValue*>(
4143      value_indices->size ());
@@ -55,7 +57,7 @@ parseListOptionalType(
5557  //  already allocated) and stick it in the list.
5658  for  (int32_t  index : *value_indices) {
5759    //  Lists of objects are stored in fbb as list[int] where the ints are
58-     //  indices into values_ . Currently serialization is deciding if they want to
60+     //  indices into values . Currently serialization is deciding if they want to
5961    //  put -1 for serialized None type indices, or give us a valid index to a
6062    //  serialized None. We support either for now.
6163    //  Placement new as the list elements are not initialized, so calling
@@ -68,9 +70,14 @@ parseListOptionalType(
6870      //  TODO(T161156879): do something less hacky here.
6971      evalp_list[output_idx] = nullptr ;
7072    } else  {
73+       ET_CHECK_OR_RETURN_ERROR (
74+           index >= 0  && index < values_len,
75+           InvalidProgram,
76+           " Invalid value index %"   PRId32 "  for ListOptional"  ,
77+           index);
7178      new  (&optional_tensor_list[output_idx])
72-           executorch::aten::optional<T>(values_ [index].toOptional <T>());
73-       evalp_list[output_idx] = &values_ [static_cast <size_t >(index)];
79+           executorch::aten::optional<T>(values [index].toOptional <T>());
80+       evalp_list[output_idx] = &values [static_cast <size_t >(index)];
7481    }
7582    output_idx++;
7683  }
0 commit comments