Skip to content

Validate size tensor element count in resize_bilinear - #116205

Merged
copybara-service[bot] merged 3 commits into
tensorflow:masterfrom
TristanInSec:fix-resize-bilinear-validate
Jul 8, 2026
Merged

copybara-service[bot] merged 3 commits into
tensorflow:masterfrom
TristanInSec:fix-resize-bilinear-validate

Conversation

@TristanInSec

Copy link
Copy Markdown
Contributor

Summary

Ensure the size input tensor contains exactly 2 elements before accessing
them, matching the validation already present in resize_nearest_neighbor.

Test plan

  • Existing resize_bilinear tests pass
  • Model with incorrect size tensor shape is rejected

Ensure the size input tensor contains exactly 2 elements before
accessing them, matching the validation in resize_nearest_neighbor.
@google-ml-butler google-ml-butler Bot added the size:XS CL Change Size: Extra Small label Apr 17, 2026
@google-ml-butler google-ml-butler Bot added the awaiting review Pull request awaiting review label Apr 21, 2026
@keerthanakadiri keerthanakadiri added the comp:lite TF Lite related issues label Apr 21, 2026
@github-project-automation github-project-automation Bot moved this to Assigned Reviewer in PR Queue Apr 21, 2026
@TristanInSec

Copy link
Copy Markdown
Contributor Author

Hi @gbaned, @keerthanakadiri, @cantonios.
Can you please review?
Thanks.
Best,
Tristan

@keerthanakadiri

Copy link
Copy Markdown
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 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.

Hi @TristanInSec,

Thank you for this security and consistency fix! Standardizing the size validation behavior across ResizeBilinear and ResizeNearestNeighbor is indeed the correct path forward to avoid out-of-bounds reads.

Could you please add a negative unit test to verify this validation rejection? You can place it at the end of tensorflow/lite/kernels/resize_bilinear_test.cc.

Here is an example test structure you can use:

TEST(ResizeBilinearOpTest, ModelWithIncorrectSizeTensorShapeIsRejected) {
#if GTEST_HAS_DEATH_TEST
  class ResizeBilinearOpModelInvalidSize : public SingleOpModel {
   public:
     ResizeBilinearOpModelInvalidSize() {
       input_ = AddInput({TensorType_FLOAT32, {1, 1, 2, 1}});
       size_ = AddConstInput(TensorType_INT32, {3}, {1});
       output_ = AddOutput(TensorType_FLOAT32);
       SetBuiltinOp(BuiltinOperator_RESIZE_BILINEAR,
                    BuiltinOptions_ResizeBilinearOptions,
                    CreateResizeBilinearOptions(builder_, false, false).Union());
       BuildInterpreter({GetShape(input_)});
     }
   private:
     int input_;
     int size_;
     int output_;
  };
  EXPECT_DEATH(ResizeBilinearOpModelInvalidSize(), "Cannot allocate tensors");
#endif
}

Once that is added and passes tests, we can merge this PR.

@github-project-automation github-project-automation Bot moved this from Assigned Reviewer to Reviewer Requested Changes in PR Queue Jun 24, 2026
Add negative unit test verifying that a ResizeBilinear model with
a size tensor of shape [1] instead of [2] is rejected during
interpreter build, as requested by reviewer.

@TristanInSec TristanInSec left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review! I've added the death test as requested:

TEST(ResizeBilinearOpTest, ModelWithIncorrectSizeTensorShapeIsRejected)

Uses the exact structure you suggested -- a SingleOpModel subclass with a size tensor of shape {1} instead of {2}, verified via EXPECT_DEATH to abort with "Cannot allocate tensors".

Pushed in 7ad1f56.

@nithyak0204
nithyak0204 requested a review from dmiltr3 June 26, 2026 07:29
@github-project-automation github-project-automation Bot moved this from Reviewer Requested Changes to Approved by Reviewer in PR Queue Jun 26, 2026
@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 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 29, 2026
copybara-service Bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Jun 29, 2026
Imported from GitHub PR tensorflow/tensorflow#116205

## Summary

Ensure the size input tensor contains exactly 2 elements before accessing
them, matching the validation already present in `resize_nearest_neighbor`.

## Test plan

- [ ] Existing resize_bilinear tests pass
- [ ] Model with incorrect size tensor shape is rejected
Copybara import of the project:

--
e519f63f40d5b2a92bdf6b470d35361dc380ee15 by TristanInSec <[email protected]>:

Validate size tensor element count in resize_bilinear

Ensure the size input tensor contains exactly 2 elements before
accessing them, matching the validation in resize_nearest_neighbor.

--
7ad1f56f6cecb79b870d89823fedc382fa885722 by TristanInSec <[email protected]>:

Add death test for incorrect size tensor shape rejection

Add negative unit test verifying that a ResizeBilinear model with
a size tensor of shape [1] instead of [2] is rejected during
interpreter build, as requested by reviewer.

Merging this change closes #116205

FUTURE_COPYBARA_INTEGRATE_REVIEW=tensorflow/tensorflow#116205 from TristanInSec:fix-resize-bilinear-validate 7ad1f56f6cecb79b870d89823fedc382fa885722
PiperOrigin-RevId: 938552903
@nithyak0204 nithyak0204 added ready to pull PR ready for merge process and removed ready to pull PR ready for merge process labels Jul 8, 2026
copybara-service Bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Jul 8, 2026
Imported from GitHub PR tensorflow/tensorflow#116205

## Summary

Ensure the size input tensor contains exactly 2 elements before accessing
them, matching the validation already present in `resize_nearest_neighbor`.

## Test plan

- [ ] Existing resize_bilinear tests pass
- [ ] Model with incorrect size tensor shape is rejected
Copybara import of the project:

--
e519f63f40d5b2a92bdf6b470d35361dc380ee15 by TristanInSec <[email protected]>:

Validate size tensor element count in resize_bilinear

Ensure the size input tensor contains exactly 2 elements before
accessing them, matching the validation in resize_nearest_neighbor.

--
7ad1f56f6cecb79b870d89823fedc382fa885722 by TristanInSec <[email protected]>:

Add death test for incorrect size tensor shape rejection

Add negative unit test verifying that a ResizeBilinear model with
a size tensor of shape [1] instead of [2] is rejected during
interpreter build, as requested by reviewer.

Merging this change closes #116205

PiperOrigin-RevId: 944569557
@copybara-service
copybara-service Bot merged commit f85cf0b into tensorflow:master Jul 8, 2026
17 checks passed
@github-project-automation github-project-automation Bot moved this from Approved by Reviewer to Merged in PR Queue Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:lite TF Lite related issues ready to pull PR ready for merge process size:XS CL Change Size: Extra Small

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

6 participants