Skip to content

litert/tensor/arithmetic.h: bounds-check axis in Split/Unpack and rank in Tile#10762

Closed
destro4evr-rgb wants to merge 1 commit into
google:masterfrom
destro4evr-rgb:fix/litert-arithmetic-split-tile-unpack-bounds
Closed

litert/tensor/arithmetic.h: bounds-check axis in Split/Unpack and rank in Tile#10762
destro4evr-rgb wants to merge 1 commit into
google:masterfrom
destro4evr-rgb:fix/litert-arithmetic-split-tile-unpack-bounds

Conversation

@destro4evr-rgb

Copy link
Copy Markdown
Contributor

Three shape-inference functions in litert/tensor/arithmetic.h use attacker-controlled values as unchecked subscripts into heap-allocated shape vectors.

Split — after negative-axis normalization, axis_val is used as input_info.shape[axis_val] (OOB read) and output_shape[axis_val] /= num_splits (OOB write) without checking axis_val < input_info.shape.size().

Unpackaxis is passed directly to output_shape.erase(output_shape.begin() + axis) with no range check. An out-of-range iterator to erase() is UB that corrupts the heap. The sibling Pack() already validates its axis (PR #10464); this aligns Unpack to the same pattern.

Tileoutput_info.shape is resized to input_shape.size() (N elements) but the fill loop iterates multiples_data.size() (M) times. When M > N the loop writes output_info.shape[i] and reads input_shape[i] for i >= N, both past the end of their heap-allocated vectors.

Fixes follow the same error-return pattern used in PR #10464 and PR #10702.

…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.
@destro4evr-rgb

Copy link
Copy Markdown
Contributor Author

Closing for now, will resubmit after further review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant