Repository navigation
Conversation
…flow Covers both external-offset sites that tflite::Verify() bounds-checks in the subtraction form: Buffer (offset, size) in VerifyTensors and Operator large_custom_options_(offset, size) in VerifyOperators. Each negative case uses a pair whose uint64 sum wraps below the model length, which the old `offset + size > len` form accepted; the positive case pins the in-range path. Re-submission of tensorflow/tensorflow#116631 against LiteRT, per review.
Folds the four cases into two table-driven tests over (offset, size, valid), so every assertion line runs for every row, adds SCOPED_TRACE for per-row diagnostics, and gives the Buffer check the same in-range control the large_custom_options check already had. What is verified is unchanged: both uint64-wrapping pairs are rejected by VerifyTensors and VerifyOperators with the specific error, the in-range pair is accepted. Follows the coverage note on tensorflow/tensorflow#116631.
Folds the four cases into two table-driven tests over (offset, size, valid), so every assertion line runs for every row, adds SCOPED_TRACE for per-row diagnostics, and gives the Buffer check the same in-range control the large_custom_options check already had. What is verified is unchanged: both uint64-wrapping pairs are rejected by VerifyTensors and VerifyOperators with the specific error, the in-range pair is accepted. Same content as google-ai-edge/LiteRT#10223 (3013ba6).
|
@dmiltr3 status for this PR, since the Sep 24 internal run on tensorflow/tensorflow#116631 (same diff) came back with two items and this is the copy that should be imported. Revision 2 (3013ba6), identical content to 1d4fb06 on #116631:
Coverage. That run reported 40% incremental coverage for the test file. I could not reproduce anything unexecuted: building gcov, the added lines at 3013ba6 (count:line:source; `-` is a line with no code)gcov, tflite/core/tools/verifier.cc, the two checks under testABI check. The change is test-only, one Once this one is imported I will close #116631. |
|
@aravindmurali22 @terryheo gentle ping on this one. It is the verifier-side regression test for the external-offset overflow (the check itself landed in tensorflow/tensorflow#123910); the builder-side fix and its tests merged today in tensorflow/tensorflow#123123 and arrived here through #10506, and this PR does not overlap with those files. No conflicts as far as I can see; the workflows are waiting on approval. |
What
Regression tests in
tflite/core/tools/verifier_test.ccfor theuint64_twrap in the external-offset bounds checks that
tflite::Verify()performs onBuffer.offset/Buffer.size(VerifyTensors) andOperator.large_custom_options_offset/large_custom_options_size(
VerifyOperators).The checks themselves already use the subtraction form on
main(
size > len || offset > len - size). This PR pins that behavior so a returnto the
offset + size > lenform is caught.Why the verifier
offset + sizecomputed inuint64_twraps when the pair straddles 2^64, sothe addition form compares a small wrapped value against the model length and
accepts the buffer.
tflite::Verify()(orFlatBufferModel::VerifyAndBuildFromBufferwith a verifier) is the ingressvalidation layer for untrusted models, so the tests target it rather than
InterpreterBuilder.Tests
Two table-driven tests over
(offset, size, valid), one per check, eachrow run with
SCOPED_TRACE:840xFFFFFFFFFFFFFF000x1000xFFFFFFFFFFFFFFF80x10sizealone fits in the model, so only theoffset > len - sizeclause can reject itBufferOffsetBoundsCheckHandlesUint64Wrap:Buffer.offset/sizevia theexisting
AddBufferOffsetTensorhelper.LargeCustomOptionsBoundsCheckHandlesUint64Wrap: the same rows onOperator.large_custom_options_offset/size, via a newAddOperatorWithLargeCustomOptionshelper onTfLiteFlatbufferModelBuilder.Rejected rows assert both
Verifyoverloads return false and match thespecific
VerifyTensors/VerifyOperatorserror string; the accepted rowasserts both return true with no error.
To run:
bazel test //tflite/core/tools:verifier_testHistory
Re-submission of tensorflow/tensorflow#116631 against this repository, as
requested there by @dmiltr3 (
tflite/core/tools/verifier_test.ccismaintained here and mirrored into TensorFlow). That PR started as a fix in
interpreter_builder.ccand was narrowed to these tests afterreview that the validation lives in the verifier. Earlier LiteRT
exports of it: #8183, #9992.
Fixes #8180 (the check itself is on
mainintflite/core/tools/verifier.cc;this PR adds the regression tests for it). Supersedes #8183.