From fccc64f2f0cb42ecac0d76c9e0be9aa0d9e91d55 Mon Sep 17 00:00:00 2001 From: TristanInSec Date: Fri, 17 Apr 2026 15:28:14 -0400 Subject: [PATCH] Validate buffer index before accessing buffers vector Check that the tensor buffer index is within the bounds of the model buffers vector before accessing it. The FlatBuffers Vector::operator[] does not perform bounds checking. --- tensorflow/lite/micro/micro_allocator.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tensorflow/lite/micro/micro_allocator.cc b/tensorflow/lite/micro/micro_allocator.cc index ecb1651c71e..0270873cf4f 100644 --- a/tensorflow/lite/micro/micro_allocator.cc +++ b/tensorflow/lite/micro/micro_allocator.cc @@ -203,7 +203,11 @@ void* GetFlatbufferTensorBuffer( // First see if there's any buffer information in the serialized tensor. // TODO(b/170379532): Add better unit tests to validate flatbuffer values. void* out_buffer = nullptr; - if (auto* buffer = (*buffers)[flatbuffer_tensor.buffer()]) { + uint32_t buffer_index = flatbuffer_tensor.buffer(); + if (buffer_index >= buffers->size()) { + return out_buffer; + } + if (auto* buffer = (*buffers)[buffer_index]) { // If we've found a buffer, does it have any data? if (auto* array = buffer->data()) { // If it has any data, is the data size larger than zero?