Skip to content

Commit d94ffe0

Browse files
Prevent an OOB read in expand_dims.cc
The for loop that follows this check assumes that `axis` is between `0` and `input_dims.size`. If user supplied `axis` is negative, the if code before this check is supposed to bring it back to positive (similar to how in Python one can do `l[-3]` to mean `l[-3 + len(l)]`). PiperOrigin-RevId: 387200206 Change-Id: I162f4feba12d547c3a4340833ae682016a2ebfab
1 parent e95fc64 commit d94ffe0

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

tensorflow/lite/kernels/expand_dims.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ TfLiteStatus ExpandTensorDim(TfLiteContext* context, const TfLiteTensor& input,
3737
axis = input_dims.size + 1 + axis;
3838
}
3939
TF_LITE_ENSURE(context, axis <= input_dims.size);
40+
TF_LITE_ENSURE(context, axis >= 0);
4041

4142
TfLiteIntArray* output_dims = TfLiteIntArrayCreate(input_dims.size + 1);
4243
for (int i = 0; i < output_dims->size; ++i) {

0 commit comments

Comments
 (0)