Repository navigation
Validate size tensor element count in resize_bilinear - #116205
copybara-service[bot] merged 3 commits into
Conversation
Ensure the size input tensor contains exactly 2 elements before accessing them, matching the validation in resize_nearest_neighbor.
|
Hi @gbaned, @keerthanakadiri, @cantonios. |
|
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
left a comment
There was a problem hiding this comment.
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.
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
left a comment
There was a problem hiding this comment.
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.
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
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
Summary
Ensure the size input tensor contains exactly 2 elements before accessing
them, matching the validation already present in
resize_nearest_neighbor.Test plan