Skip to content

Avoid arithmetic overflow in TFLite buffer bounds checks - #116204

Merged
rwitcher merged 2 commits into
tensorflow:masterfrom
TristanInSec:fix-tflite-buffer-bounds
Jul 23, 2026
Merged

rwitcher merged 2 commits into
tensorflow:masterfrom
TristanInSec:fix-tflite-buffer-bounds

Conversation

@TristanInSec

Copy link
Copy Markdown
Contributor

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

Rewrite bounds checks in ParseNodes and ParseTensors to use
subtraction instead of addition, preventing potential wraparound
when summing two uint64 values.
@google-ml-butler google-ml-butler Bot added the size:S CL Change Size: Small label Apr 17, 2026
@google-ml-butler google-ml-butler Bot added the awaiting review Pull request awaiting review label Apr 21, 2026
@github-project-automation github-project-automation Bot moved this to Assigned Reviewer in PR Queue Apr 21, 2026
@keerthanakadiri keerthanakadiri added the comp:core issues related to core part of tensorflow label Apr 21, 2026
@TristanInSec

Copy link
Copy Markdown
Contributor Author

Hi, friendly ping on this PR (and the related #116205, #116206). Let me know if any changes are needed. Thanks!

@TristanInSec

TristanInSec commented May 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @gbaned, @keerthanakadiri, @zichuan-wei,
Can you please review?
Thanks.
Best,
Tristan

@keerthanakadiri

Copy link
Copy Markdown
Contributor

Hi @gbaned, @keerthanakadiri, @zichuan-wei, Can you please review? Thanks. Best, Tristan

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 dmiltr3 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@google-ml-butler google-ml-butler Bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Jun 24, 2026
@github-project-automation github-project-automation Bot moved this from Assigned Reviewer to Approved by Reviewer in PR Queue Jun 24, 2026
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Jun 24, 2026
@dmiltr3 dmiltr3 added ready to pull PR ready for merge process and removed ready to pull PR ready for merge process labels Jun 24, 2026
@nithyak0204 nithyak0204 added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process and removed ready to pull PR ready for merge process labels Jun 26, 2026
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Jun 26, 2026
@nithyak0204 nithyak0204 removed the awaiting review Pull request awaiting review label Jun 30, 2026
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
@nithyak0204 nithyak0204 added ready to pull PR ready for merge process and removed ready to pull PR ready for merge process labels Jul 2, 2026
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
@nithyak0204 nithyak0204 added ready to pull PR ready for merge process and removed ready to pull PR ready for merge process labels Jul 7, 2026
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
@nithyak0204 nithyak0204 added ready to pull PR ready for merge process and removed ready to pull PR ready for merge process labels Jul 10, 2026
@rwitcher
rwitcher merged commit 5cf3899 into tensorflow:master Jul 23, 2026
14 checks passed
@github-project-automation github-project-automation Bot moved this from Approved by Reviewer to Merged in PR Queue Jul 23, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:core issues related to core part of tensorflow ready to pull PR ready for merge process size:S CL Change Size: Small

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

7 participants