Skip to content

litert/tensor/arithmetic.h: bounds-check multiples length in Tile()#10772

Open
destro4evr-rgb wants to merge 1 commit into
google:masterfrom
destro4evr-rgb:fix/litert-tile-multiples-rank-check
Open

litert/tensor/arithmetic.h: bounds-check multiples length in Tile()#10772
destro4evr-rgb wants to merge 1 commit into
google:masterfrom
destro4evr-rgb:fix/litert-tile-multiples-rank-check

Conversation

@destro4evr-rgb

@destro4evr-rgb destro4evr-rgb commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Tile() resized output_info.shape to input_shape.size() (N elements) but iterated multiples_data.size() (M) times. When M > N, output_info.shape[i] and input_shape[i] are both accessed out-of-bounds - a heap OOB write and OOB read on separate std::vector<int> allocations.

This adds a length equality check before the loop, matching the pattern already used in Transpose() (added in #10702):

if (multiples_data.size() != input_shape.size()) {
  return Tensor<Mixins...>(graph::ErrorTensor(absl::InvalidArgumentError(
      "Tile multiples length must equal input rank.")));
}

Root cause

Tile() was introduced in #10464. Transpose() received the equivalent rank-equality guard in #10702 but Tile() did not.

Impact

A crafted LiteRT model with a Tile op whose multiples tensor has more elements than the input tensor's rank triggers the OOB accesses during graph construction. The number of out-of-bounds writes is M - N, fully attacker-controlled.

Tile() resized output_info.shape to input_shape.size() (N) but iterated
multiples_data.size() (M) times, causing heap OOB read/write when M > N.
Add a length equality check mirroring the existing guard in Transpose().
copybara-service Bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Jul 20, 2026
--
7463b89ac06473fedbb916c51576c08d1595135e by destro4evr-rgb <destro4evr@proton.me>:

litert/tensor/arithmetic.h: bounds-check multiples length in Tile()

Tile() resized output_info.shape to input_shape.size() (N) but iterated
multiples_data.size() (M) times, causing heap OOB read/write when M > N.
Add a length equality check mirroring the existing guard in Transpose().

FUTURE_COPYBARA_INTEGRATE_REVIEW=google/XNNPACK#10772 from destro4evr-rgb:fix/litert-tile-multiples-rank-check 7463b89ac06473fedbb916c51576c08d1595135e
LiteRT-PiperOrigin-RevId: 950807692
copybara-service Bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Jul 20, 2026
--
7463b89ac06473fedbb916c51576c08d1595135e by destro4evr-rgb <destro4evr@proton.me>:

litert/tensor/arithmetic.h: bounds-check multiples length in Tile()

Tile() resized output_info.shape to input_shape.size() (N) but iterated
multiples_data.size() (M) times, causing heap OOB read/write when M > N.
Add a length equality check mirroring the existing guard in Transpose().

FUTURE_COPYBARA_INTEGRATE_REVIEW=google/XNNPACK#10772 from destro4evr-rgb:fix/litert-tile-multiples-rank-check 7463b89ac06473fedbb916c51576c08d1595135e
LiteRT-PiperOrigin-RevId: 950807692
copybara-service Bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Jul 20, 2026
--
7463b89ac06473fedbb916c51576c08d1595135e by destro4evr-rgb <destro4evr@proton.me>:

litert/tensor/arithmetic.h: bounds-check multiples length in Tile()

Tile() resized output_info.shape to input_shape.size() (N) but iterated
multiples_data.size() (M) times, causing heap OOB read/write when M > N.
Add a length equality check mirroring the existing guard in Transpose().

FUTURE_COPYBARA_INTEGRATE_REVIEW=google/XNNPACK#10772 from destro4evr-rgb:fix/litert-tile-multiples-rank-check 7463b89ac06473fedbb916c51576c08d1595135e
LiteRT-PiperOrigin-RevId: 950807692
copybara-service Bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Jul 20, 2026
--
7463b89ac06473fedbb916c51576c08d1595135e by destro4evr-rgb <destro4evr@proton.me>:

litert/tensor/arithmetic.h: bounds-check multiples length in Tile()

Tile() resized output_info.shape to input_shape.size() (N) but iterated
multiples_data.size() (M) times, causing heap OOB read/write when M > N.
Add a length equality check mirroring the existing guard in Transpose().

FUTURE_COPYBARA_INTEGRATE_REVIEW=google/XNNPACK#10772 from destro4evr-rgb:fix/litert-tile-multiples-rank-check 7463b89ac06473fedbb916c51576c08d1595135e
LiteRT-PiperOrigin-RevId: 950807692
copybara-service Bot pushed a commit that referenced this pull request Jul 20, 2026
--
7463b89 by destro4evr-rgb <destro4evr@proton.me>:

litert/tensor/arithmetic.h: bounds-check multiples length in Tile()

Tile() resized output_info.shape to input_shape.size() (N) but iterated
multiples_data.size() (M) times, causing heap OOB read/write when M > N.
Add a length equality check mirroring the existing guard in Transpose().

FUTURE_COPYBARA_INTEGRATE_REVIEW=#10772 from destro4evr-rgb:fix/litert-tile-multiples-rank-check 7463b89
PiperOrigin-RevId: 950807692
copybara-service Bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Jul 20, 2026
--
7463b89ac06473fedbb916c51576c08d1595135e by destro4evr-rgb <destro4evr@proton.me>:

litert/tensor/arithmetic.h: bounds-check multiples length in Tile()

Tile() resized output_info.shape to input_shape.size() (N) but iterated
multiples_data.size() (M) times, causing heap OOB read/write when M > N.
Add a length equality check mirroring the existing guard in Transpose().

FUTURE_COPYBARA_INTEGRATE_REVIEW=google/XNNPACK#10772 from destro4evr-rgb:fix/litert-tile-multiples-rank-check 7463b89ac06473fedbb916c51576c08d1595135e
LiteRT-PiperOrigin-RevId: 950807692
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