Repository navigation
Avoid arithmetic overflow in TFLite buffer bounds checks - #116204
Merged
rwitcher merged 2 commits intoJul 23, 2026
Merged
Conversation
Rewrite bounds checks in ParseNodes and ParseTensors to use subtraction instead of addition, preventing potential wraparound when summing two uint64 values.
Contributor
Author
Contributor
Author
|
Hi @gbaned, @keerthanakadiri, @zichuan-wei, |
Contributor
Hi @TristanInSec , A review request has been submitted for this PR. Once approved, it will be ready for the next stage of the process. Thank you! |
dmiltr3
self-requested a review
June 24, 2026 00:32
dmiltr3
approved these changes
Jun 24, 2026
dmiltr3
left a comment
Contributor
There was a problem hiding this comment.
Thank you for bringing this up and proposing the security improvement to make the buffer bounds checks more robust against overflow!
We have reviewed your changes, verified the subtraction checks are mathematically safe, and confirmed that the test suites are passing.
Open
2 tasks
copybara-service Bot
pushed a commit
to google-ai-edge/LiteRT
that referenced
this pull request
Jun 30, 2026
Imported from GitHub PR tensorflow/tensorflow#116204 ## Summary Rewrite bounds checks in `ParseNodes` and `ParseTensors` to use subtraction instead of addition, preventing potential wraparound when summing two `uint64` values against the buffer length. ## Test plan - [ ] Existing TFLite unit tests pass - [ ] Model loading with large offset values is correctly rejected Copybara import of the project: -- b0c73845b908d90520f5c84159c7b4d5a4a7e60a by TristanInSec <[email protected]>: Avoid arithmetic overflow in TFLite buffer bounds checks Rewrite bounds checks in ParseNodes and ParseTensors to use subtraction instead of addition, preventing potential wraparound when summing two uint64 values. Merging this change closes #116204 FUTURE_COPYBARA_INTEGRATE_REVIEW=tensorflow/tensorflow#116204 from TristanInSec:fix-tflite-buffer-bounds 75b01ca50353efc51141d87ac822abccff0a2c8d PiperOrigin-RevId: 936992268
copybara-service Bot
pushed a commit
to google-ai-edge/LiteRT
that referenced
this pull request
Jul 2, 2026
Imported from GitHub PR tensorflow/tensorflow#116204 ## Summary Rewrite bounds checks in `ParseNodes` and `ParseTensors` to use subtraction instead of addition, preventing potential wraparound when summing two `uint64` values against the buffer length. ## Test plan - [ ] Existing TFLite unit tests pass - [ ] Model loading with large offset values is correctly rejected Copybara import of the project: -- b0c73845b908d90520f5c84159c7b4d5a4a7e60a by TristanInSec <[email protected]>: Avoid arithmetic overflow in TFLite buffer bounds checks Rewrite bounds checks in ParseNodes and ParseTensors to use subtraction instead of addition, preventing potential wraparound when summing two uint64 values. Merging this change closes #116204 FUTURE_COPYBARA_INTEGRATE_REVIEW=tensorflow/tensorflow#116204 from TristanInSec:fix-tflite-buffer-bounds 75b01ca50353efc51141d87ac822abccff0a2c8d PiperOrigin-RevId: 936992268
copybara-service Bot
pushed a commit
to google-ai-edge/LiteRT
that referenced
this pull request
Jul 7, 2026
Imported from GitHub PR tensorflow/tensorflow#116204 ## Summary Rewrite bounds checks in `ParseNodes` and `ParseTensors` to use subtraction instead of addition, preventing potential wraparound when summing two `uint64` values against the buffer length. ## Test plan - [ ] Existing TFLite unit tests pass - [ ] Model loading with large offset values is correctly rejected Copybara import of the project: -- b0c73845b908d90520f5c84159c7b4d5a4a7e60a by TristanInSec <[email protected]>: Avoid arithmetic overflow in TFLite buffer bounds checks Rewrite bounds checks in ParseNodes and ParseTensors to use subtraction instead of addition, preventing potential wraparound when summing two uint64 values. Merging this change closes #116204 FUTURE_COPYBARA_INTEGRATE_REVIEW=tensorflow/tensorflow#116204 from TristanInSec:fix-tflite-buffer-bounds 75b01ca50353efc51141d87ac822abccff0a2c8d PiperOrigin-RevId: 936992268
prasanna8585
pushed a commit
to prasanna8585/tensorflow
that referenced
this pull request
Aug 6, 2026
…116204) * Avoid arithmetic overflow in TFLite buffer bounds checks Rewrite bounds checks in ParseNodes and ParseTensors to use subtraction instead of addition, preventing potential wraparound when summing two uint64 values. * Trigger CI re-run (flaky while_op_test failure)
professor-moody
added a commit
to professor-moody/LiteRT
that referenced
this pull request
Oct 12, 2026
READ_VARIABLE and ASSIGN_VARIABLE read the resource id as data.i32[0] without checking that the id tensor holds four bytes, and READ_VARIABLE copied output->bytes from the variable without checking the variable's size. InterpreterBuilder checked external buffer and large custom options ranges as offset + size, which can wrap. Require sizeof(int32_t) id bytes, reject an uninitialized variable tensor, require the variable to cover the output copy, and use the overflow-safe subtraction form in ParseNodes and ParseTensors, as tensorflow/tensorflow#116204 proposed and #123910 applied in the verifier in LiteRT commit bf443ec. The default model loaders call that verifier only when supplied by the caller, so both builder checks remain at the pointer-formation sites. The previous commit's null-data tests asserted that AllocateTensors() allocates a RESOURCE input. It does not, so drop that assertion. Add kernel tests for empty, one- to three-byte, and fully backed ids and an oversized READ output. Add builder tests for both external buffer bounds, both large custom options bounds and in-bounds controls.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Rewrite bounds checks in
ParseNodesandParseTensorsto use subtractioninstead of addition, preventing potential wraparound when summing two
uint64values against the buffer length.
Test plan