Skip to content

litert/xnnpack: add rank guards to AveragePool2D, MaxPool2D, Conv2D, DepthwiseConv2D, and TransposeConv2D ToXnnpack() before shape subscripts - #11057

Merged
copybara-service[bot] merged 1 commit into
google:masterfrom
destro4evr-rgb:fix/litert-conv-pool-missing-rank-checks
Sep 1, 2026
Merged

Conversation

@destro4evr-rgb

Copy link
Copy Markdown
Contributor

Five ToXnnpack() implementations access fixed shape indices (shape[1], shape[2], shape[3]) on input, filter, and output tensor shape vectors without first validating that the vector has enough elements. A crafted TFLite model that declares a wrong-rank tensor for any of these operations triggers a null pointer dereference during XNNPACK subgraph compilation at model load time, before any inference runs.

TransposeConvOperation::ToXnnpack() (lines 1649–1653) performs the same shape subscripts and already includes the explicit rank guard that the five affected functions are missing:

if (input_info.shape.size() != 4 || filter_info.shape.size() != 4 ||
    output_info.shape.size() != 4) {
    return absl::InvalidArgumentError(...);
}

Fix: add equivalent rank size checks before the first shape subscript in each affected function — size() < 3 for AveragePool2D and MaxPool2D (which only need indices 1 and 2), size() != 4 for Conv2D and DepthwiseConv2D (input + filter), and size() != 4 for all three tensors in TransposeConv2D.

… subscripts

AveragePool2D, MaxPool2D, Conv2D, DepthwiseConv2D, and TransposeConv2D
all access fixed shape indices (shape[0]..shape[3]) on input, filter, and
output tensors without first checking that the shape vector is large enough.
A crafted TFLite model with a wrong-rank tensor triggers a null pointer
dereference during XNNPACK subgraph compilation at model load time.

Add rank size checks before the first shape subscript access in each
function, following the pattern already present in
TransposeConvOperation::ToXnnpack() (lines 1649-1653).
@destro4evr-rgb
destro4evr-rgb force-pushed the fix/litert-conv-pool-missing-rank-checks branch from 0f72007 to 4013867 Compare August 31, 2026 16:09
copybara-service Bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Aug 31, 2026
--
40138679e845958508e9dfcf4710c81948b8ed15 by destro4evr-rgb <destro4evr@proton.me>:

litert/xnnpack: add rank guards to Conv/Pool ToXnnpack() before shape subscripts

AveragePool2D, MaxPool2D, Conv2D, DepthwiseConv2D, and TransposeConv2D
all access fixed shape indices (shape[0]..shape[3]) on input, filter, and
output tensors without first checking that the shape vector is large enough.
A crafted TFLite model with a wrong-rank tensor triggers a null pointer
dereference during XNNPACK subgraph compilation at model load time.

Add rank size checks before the first shape subscript access in each
function, following the pattern already present in
TransposeConvOperation::ToXnnpack() (lines 1649-1653).
FUTURE_COPYBARA_INTEGRATE_REVIEW=google/XNNPACK#11057 from destro4evr-rgb:fix/litert-conv-pool-missing-rank-checks 40138679e845958508e9dfcf4710c81948b8ed15
LiteRT-PiperOrigin-RevId: 971399026
copybara-service Bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Aug 31, 2026
--
40138679e845958508e9dfcf4710c81948b8ed15 by destro4evr-rgb <destro4evr@proton.me>:

litert/xnnpack: add rank guards to Conv/Pool ToXnnpack() before shape subscripts

AveragePool2D, MaxPool2D, Conv2D, DepthwiseConv2D, and TransposeConv2D
all access fixed shape indices (shape[0]..shape[3]) on input, filter, and
output tensors without first checking that the shape vector is large enough.
A crafted TFLite model with a wrong-rank tensor triggers a null pointer
dereference during XNNPACK subgraph compilation at model load time.

Add rank size checks before the first shape subscript access in each
function, following the pattern already present in
TransposeConvOperation::ToXnnpack() (lines 1649-1653).
FUTURE_COPYBARA_INTEGRATE_REVIEW=google/XNNPACK#11057 from destro4evr-rgb:fix/litert-conv-pool-missing-rank-checks 40138679e845958508e9dfcf4710c81948b8ed15
LiteRT-PiperOrigin-RevId: 971399026
copybara-service Bot pushed a commit that referenced this pull request Sep 1, 2026
--
4013867 by destro4evr-rgb <destro4evr@proton.me>:

litert/xnnpack: add rank guards to Conv/Pool ToXnnpack() before shape subscripts

AveragePool2D, MaxPool2D, Conv2D, DepthwiseConv2D, and TransposeConv2D
all access fixed shape indices (shape[0]..shape[3]) on input, filter, and
output tensors without first checking that the shape vector is large enough.
A crafted TFLite model with a wrong-rank tensor triggers a null pointer
dereference during XNNPACK subgraph compilation at model load time.

Add rank size checks before the first shape subscript access in each
function, following the pattern already present in
TransposeConvOperation::ToXnnpack() (lines 1649-1653).
FUTURE_COPYBARA_INTEGRATE_REVIEW=#11057 from destro4evr-rgb:fix/litert-conv-pool-missing-rank-checks 4013867
PiperOrigin-RevId: 971399026
copybara-service Bot pushed a commit to google-ai-edge/LiteRT that referenced this pull request Sep 1, 2026
--
40138679e845958508e9dfcf4710c81948b8ed15 by destro4evr-rgb <destro4evr@proton.me>:

litert/xnnpack: add rank guards to Conv/Pool ToXnnpack() before shape subscripts

AveragePool2D, MaxPool2D, Conv2D, DepthwiseConv2D, and TransposeConv2D
all access fixed shape indices (shape[0]..shape[3]) on input, filter, and
output tensors without first checking that the shape vector is large enough.
A crafted TFLite model with a wrong-rank tensor triggers a null pointer
dereference during XNNPACK subgraph compilation at model load time.

Add rank size checks before the first shape subscript access in each
function, following the pattern already present in
TransposeConvOperation::ToXnnpack() (lines 1649-1653).

Reverts 71dd844

FUTURE_COPYBARA_INTEGRATE_REVIEW=google/XNNPACK#11057 from destro4evr-rgb:fix/litert-conv-pool-missing-rank-checks 40138679e845958508e9dfcf4710c81948b8ed15
LiteRT-PiperOrigin-RevId: 971399026
@copybara-service
copybara-service Bot merged commit 8c02ee3 into google:master Sep 1, 2026
9 checks passed
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.

2 participants