Skip to content
Permalink
Browse files Browse the repository at this point in the history
Fix a dangerous integer overflow and a malloc of negative size.
PiperOrigin-RevId: 371254154
Change-Id: I250a98a3df26328770167025670235a963a72da0
  • Loading branch information
mihaimaruseac authored and tensorflower-gardener committed Apr 30, 2021
1 parent 4ceffae commit 7c8cc4e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
6 changes: 4 additions & 2 deletions tensorflow/lite/c/common.c
Expand Up @@ -45,8 +45,10 @@ int TfLiteIntArrayEqualsArray(const TfLiteIntArray* a, int b_size,
#ifndef TF_LITE_STATIC_MEMORY

TfLiteIntArray* TfLiteIntArrayCreate(int size) {
TfLiteIntArray* ret =
(TfLiteIntArray*)malloc(TfLiteIntArrayGetSizeInBytes(size));
int alloc_size = TfLiteIntArrayGetSizeInBytes(size);
if (alloc_size <= 0) return NULL;
TfLiteIntArray* ret = (TfLiteIntArray*)malloc(alloc_size);
if (!ret) return ret;
ret->size = size;
return ret;
}
Expand Down
1 change: 1 addition & 0 deletions tensorflow/lite/kernels/embedding_lookup_sparse.cc
Expand Up @@ -173,6 +173,7 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {

// Resize output tensor.
TfLiteIntArray* output_shape = TfLiteIntArrayCreate(output_rank);
TF_LITE_ENSURE(context, output_shape != nullptr);
int k = 0;
int embedding_size = 1;
int lookup_size = 1;
Expand Down

0 comments on commit 7c8cc4e

Please sign in to comment.