File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -101,6 +101,19 @@ Result<Tensor> parseTensor(
101
101
sizes = const_cast <exec_aten::SizesType*>(serialized_sizes);
102
102
dim_order = const_cast <exec_aten::DimOrderType*>(serialized_dim_order);
103
103
}
104
+ // Validate sizes before using them in case the PTE data is bad. We can't
105
+ // detect bad positive values, but we can reject negative values, which would
106
+ // otherwise panic in the TensorImpl ctor. dim_order_to_stride() will validate
107
+ // dim_order.
108
+ for (int i = 0 ; i < dim; i++) {
109
+ ET_CHECK_OR_RETURN_ERROR (
110
+ sizes[i] >= 0 ,
111
+ InvalidProgram,
112
+ " Negative size[%d] %" PRId32,
113
+ i,
114
+ sizes[i]);
115
+ }
116
+
104
117
// We will remove strides from schema.
105
118
// Allocating strides buffer here and populating it.
106
119
// In subsequent diffs we can remove strides accessor, however this
You can’t perform that action at this time.
0 commit comments