diff --git a/tensorflow/lite/simple_memory_arena.cc b/tensorflow/lite/simple_memory_arena.cc index a4d6d19656b..4aa0a1eb2ef 100644 --- a/tensorflow/lite/simple_memory_arena.cc +++ b/tensorflow/lite/simple_memory_arena.cc @@ -136,6 +136,8 @@ TfLiteStatus SimpleMemoryArena::ResolveAlloc( char** output_ptr) { TF_LITE_ENSURE(context, committed_); TF_LITE_ENSURE(context, output_ptr != nullptr); + TF_LITE_ENSURE(context, + underlying_buffer_size_ >= (alloc.offset + alloc.size)); if (alloc.size == 0) { *output_ptr = nullptr; } else { diff --git a/tensorflow/lite/simple_memory_arena_test.cc b/tensorflow/lite/simple_memory_arena_test.cc index fe337562b0a..0196421cc9c 100644 --- a/tensorflow/lite/simple_memory_arena_test.cc +++ b/tensorflow/lite/simple_memory_arena_test.cc @@ -197,6 +197,9 @@ TEST_P(BufferAndPlanClearingTest, TestClearBufferAndClearPlan) { EXPECT_NE(resolved_ptr, nullptr); } +INSTANTIATE_TEST_SUITE_P(BufferAndPlanClearingTest, BufferAndPlanClearingTest, + ::testing::Values(true, false)); + } // namespace } // namespace tflite