litert/tensor: guard AveragePool2D/MaxPool2D/Conv2D/DepthwiseConv2D against under-rank input in arithmetic.h - #11154
Open
destro4evr-rgb wants to merge 1 commit into
Conversation
…gainst under-rank input in arithmetic.h AveragePool2D, MaxPool2D, Conv2DImpl, and DepthwiseConv2DImpl all access fixed shape indices (shape[1], shape[2], shape[3]) without first checking that the input (and filter) shape vectors are large enough. A crafted TFLite model with a rank-0 or rank-1 tensor on any of these operators causes an out-of-bounds std::vector::operator[] access at graph-construction time, before inference, resulting in SIGSEGV. PR google#11057 added equivalent guards to the ToXnnpack() methods in arithmetic.cc (graph-compilation time), but the earlier crash in arithmetic.h (graph-construction time) was not covered. Add rank < 4 checks before the first shape subscript in each function.
qukhan
approved these changes
Sep 7, 2026
This was referenced Sep 7, 2026
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.
Problem
AveragePool2D(),MaxPool2D(),Conv2DImpl(), andDepthwiseConv2DImpl()inlitert/tensor/arithmetic.hsubscript fixed shape indices (1, 2, 3) without first checking that the input/filter shape vectors are large enough. A crafted TFLite model with a rank-0 or rank-1 tensor on any of these operators causes an out-of-boundsstd::vector::operator[]access during graph construction (model-load time), before inference begins, resulting in SIGSEGV.Fix
Add
shape.size() < 4checks before the first shape subscript in each of the four functions, returning anInvalidArgumentErroron violation — consistent with the pattern used in FullyConnected, EmbeddingLookup, and GatherNd.Affected functions
AveragePool2Darithmetic.h:1220shape[1]on rank-0 inputMaxPool2Darithmetic.h:1260shape[1]on rank-0 inputConv2DImplarithmetic.h:1305shape[1]on rank-0 input or filterDepthwiseConv2DImplarithmetic.h:1379shape[1]on rank-0 input or filter