Skip to content

Conversation

@ilya-kupchenko
Copy link
Contributor

Description:
bug=fixes #3075 #3076 #3077

Problem
MicroAllocator does not validate the buffer indices. If a model provides an out-of-bounds buffer index for an input, output, or intermediate tensor, it results in segmentation fault.

Solution
Add validation inside MicroAllocator to check that the buffer index for every tensor. If an invalid index is found, InitializeTfLiteTensorFromFlatbuffer and InitializeTfLiteEvalTensorFromFlatbuffer will now return kTfLiteError.

Files Modified
tensorflow/lite/micro/micro_interpreter.cc
tensorflow/lite/micro/micro_interpreter_test.cc

Testing
Added new Bazel tests that use models with invalid buffer-to-tensor mappings.

@ilya-kupchenko ilya-kupchenko requested a review from a team as a code owner October 18, 2025 23:50
@ilya-kupchenko
Copy link
Contributor Author

Hi, this is one of my first PRs. Sorry if anything is wrong (I tried my best). I added the validators for subgraph and tensor indices in MicroAllocator::PopulateTfLiteTensorFromFlatbuffer. I am not sure if this is needed and I am not sure about this:

  if (tensor_index < 0 ||
      static_cast<size_t>(tensor_index) >= subgraph->tensors()->size()) {
    MicroPrintf(
        "Invalid tensor index %d for subgraph %d, subgraph has only %d tensors"

I have heard that "-1" is used sometimes to indicate optional tensors or lacking dimensions, not sure if this should be caught as well.

Contributing on TFLM project was my dream, sorry if I did anything wrong.

Copy link
Contributor

@gonnet gonnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this!

@gonnet gonnet added the ci:run label Oct 20, 2025
@gonnet gonnet self-assigned this Oct 20, 2025
@TFLM-bot TFLM-bot removed the ci:run label Oct 20, 2025
…rs and subgraphs.

Support for DECODE operator (tensorflow#3162)

* Support for DECODE operator

@tensorflow/micro

Add initial support for DECODE operator.
Add reference implementation.
Add LUT decompression support.
Update op resolvers.
Update Makefiles and Bazel BUILD files.
Add kernel unit test.

bug=fixes tensorflow#3131

* update copyright

* Don't use constructors with global objects (bluepill will not call them).

Cleanup unit test.

* Support for DECODE operator

@tensorflow/micro

Additional support for DECODE operator.
Add Xtensa optimizations for LUT decompression.
Move all Xtensa kernel source references to the Xtensa target makefile.

bug=fixes tensorflow#3150

* Updates to Xtensa makefiles

@tensorflow/micro

Reorganize Xtensa makefiles such that all references to optimized kernel sources are moved to the Xtensa target makefile.

Move hifimini kernel sources to the parent directory, and rename them so they do not interfere with the target overlay mechanism of the root makefile.

bug=fixes tensorflow#3153

* Fix incorrect include path.
Fix code style errors.

* fix copyright

* update generic benchmark op resolver size

* Support for DECODE operator

@tensorflow/micro

Add reference implementation of pruning to DECODE operator.
Makefile and Bazel BUILD file changes.
Additional unit tests.

bug=fixes tensorflow#3161

* Split decode tests into seperate files.
Update pruning code with zero-point checks.
Add const-tensor checks.

* Add decode_test_helpers.h file.
Cleanup tests.

Added end-of-line symbols
@ilya-kupchenko ilya-kupchenko force-pushed the bugfix/issue-3075-3076-3077-non-existent-buffer branch from 40aedca to 3d81290 Compare October 24, 2025 08:58
@ilya-kupchenko
Copy link
Contributor Author

ilya-kupchenko commented Oct 24, 2025

I squashed the commit messages, fixed the style and added end-of-line symbols, just in case. Some MicroPrintf() calls in micro_allocator.cc have them, some not. Let me know if you want me to add/remove them for all MicroPrintf() calls it in all the project in a unified way.

If you allow, I will fix #3071, #3072, #3073, #3074, #3128and #2721. Let me know if this is OK (or what other things I can be useful for).

PS. While trying to run the CI/CD tests I ran into some errors. I described them here #3240. If this is a bug, I can push the patch for it.
Thank you!

@ilya-kupchenko ilya-kupchenko requested a review from gonnet October 24, 2025 09:40
@gonnet gonnet added the ci:run label Oct 24, 2025
@TFLM-bot TFLM-bot removed the ci:run label Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non Existent Buffer in Output Tensor Leads to a Crash

4 participants