Skip to content

Commit

Permalink
Merge pull request #51324 from tensorflow/mm-cp-bb6a0383ed553c286f87c…
Browse files Browse the repository at this point in the history
…a88c207f6774d5c4a8f-on-r2.4

Prevent heap OOB read in TFLite's `gather_nd.cc`.
  • Loading branch information
mihaimaruseac committed Aug 6, 2021
2 parents 478ad2a + 18b7471 commit 8886d30
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tensorflow/lite/kernels/gather_nd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ TfLiteStatus GatherNdString(const TfLiteTensor* params,
template <typename IndicesT>
TfLiteStatus EvalGatherNd(TfLiteContext* context, const TfLiteTensor* params,
const TfLiteTensor* indices, TfLiteTensor* output) {
bool indices_has_only_positive_elements = true;
const auto* indices_values = GetTensorData<IndicesT>(indices);
const size_t num_indices = indices->bytes / sizeof(IndicesT);
for (size_t i = 0; i < num_indices; i++) {
if (indices_values[i] < 0) {
indices_has_only_positive_elements = false;
break;
}
}
TF_LITE_ENSURE(context, indices_has_only_positive_elements);

switch (params->type) {
case kTfLiteFloat32:
return GatherNd<float, IndicesT>(params, indices, output);
Expand Down

0 comments on commit 8886d30

Please sign in to comment.