litert/xnnpack: reject negative begin-tensor shape dimension in SliceOperation::ToXnnpack() - #11138
Open
destro4evr-rgb wants to merge 1 commit into
Open
Conversation
…Operation::ToXnnpack() The existing guard added by PR google#11056 only rejects a 0D begin tensor (begin_info.shape.empty()). A 1D begin tensor whose sole dimension is negative (e.g. -1 for a dynamic/unknown size) bypasses that guard: shape.empty() returns false, shape[0] = -1 is read, and the implicit int32_t -> size_t conversion produces SIZE_MAX. The two std::vector<size_t> allocations that follow request SIZE_MAX elements, exceeding max_size() and causing an unconditional abort at model-load time. Extend the guard to also reject shape[0] <= 0.
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
PR #11056 added a guard for the 0D scalar case (
begin_info.shape.empty()). A 1D begin tensor whose sole dimension is negative (e.g.-1, valid in the flatbuffer format as a dynamic/unknown size marker) bypasses that guard:shape[0] = -1wraps toSIZE_MAXon the implicitint32_t → size_tconversion. Both vector constructors then requestSIZE_MAXelements, exceedingmax_size()and causing an unconditional abort at model-load time - before any inference occurs.Fix
Extend the existing guard to also reject
shape[0] <= 0: