Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
This branch has not been deployed
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.
TfLiteInterpreterWrapper::SetStringDatapacks the serving input into TFLite's dynamic string format, whose header is a 4-byte string count followed by one 4-byte offset per string. The header and the stored count were sized frombatch_size, whichTfLiteSession::Runderives from the leading dimension (dim_size(0)) of the input, while the offset loop writes one entry for every string element (flat.size()). For an input of rank > 1 the element count exceeds the leading dimension, so a string tensor of shape[1, N]leavesbatch_sizeat 1 while N+1 offsets are written into space allocated for 3 int32s, a heap out-of-bounds write. It is reachable over the Predict API (gRPC and REST) whenever a TFLite model with a string input is served, since the request controls the tensor rank and shape.The fix counts the string elements actually written and uses that for the stored count, the allocation size, and the offset-table bound, so all three agree. The common rank-1 case, where the element count already equals the leading dimension, is unaffected.
Verified with an AddressSanitizer reproducer of the buffer math (12-byte allocation, 33 offsets written for a
[1, 32]input) and a regression test intflite_interpreter_pool_test.ccthat feeds a rank-2 string input and checks the stored string count equals the element count.