litert/tensor/arithmetic.h: bounds-check axis in Split/Unpack and rank in Tile#10762
Closed
destro4evr-rgb wants to merge 1 commit into
Closed
Conversation
…k in Tile Split: after negative-axis normalization, axis_val was used directly as a subscript into the shape vector without checking it was within [0, rank). A value >= rank caused an OOB read from input_info.shape and an OOB write to output_shape. Unpack: axis was passed directly to vector::erase() with no range check. An out-of-range iterator to erase() is undefined behaviour that corrupts the heap in practice. The sibling Pack() function already validates its axis; align Unpack to the same pattern. Tile: output_info.shape was resized to input_shape.size() (N elements) but the fill loop iterated multiples_data.size() (M) times. When M > N the loop wrote output_info.shape[i] and read input_shape[i] for i >= N, both past the end of their respective heap-allocated vectors. Fixes follow the same error-return pattern used by Transpose, ExpandDims, Pack, and Concatenation after PR google#10464 and PR google#10702.
Contributor
Author
|
Closing for now, will resubmit after further review. |
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.
Three shape-inference functions in
litert/tensor/arithmetic.huse attacker-controlled values as unchecked subscripts into heap-allocated shape vectors.Split — after negative-axis normalization,
axis_valis used asinput_info.shape[axis_val](OOB read) andoutput_shape[axis_val] /= num_splits(OOB write) without checkingaxis_val < input_info.shape.size().Unpack —
axisis passed directly tooutput_shape.erase(output_shape.begin() + axis)with no range check. An out-of-range iterator toerase()is UB that corrupts the heap. The siblingPack()already validates its axis (PR #10464); this alignsUnpackto the same pattern.Tile —
output_info.shapeis resized toinput_shape.size()(N elements) but the fill loop iteratesmultiples_data.size()(M) times. When M > N the loop writesoutput_info.shape[i]and readsinput_shape[i]fori >= N, both past the end of their heap-allocated vectors.Fixes follow the same error-return pattern used in PR #10464 and PR #10702.