[operators, subgraph] Harden operator reshape workspace initialization and subgraph tensor rank/axis validation - #11459
Open
anagnorisis2peripeteia wants to merge 1 commit into
Conversation
…rank/axis validation
anagnorisis2peripeteia
force-pushed
the
fix-operator-workspace-and-subgraph-validation
branch
from
October 1, 2026 00:52
16b9147 to
3efdbd7
Compare
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.
Summary
This PR addresses several edge-case defects across operator reshape routines and subgraph runtime reshaping:
Operator Reshape Workspace Sizing & Safety:
fully-connected-nc,batch-matrix-multiply-nc: Initialize*workspace_size = 0unconditionally upon entry whenworkspace_size != NULL.dynamic-fully-connected-nc: Set*workspace_size = 0whenbatch_size == 0, and checkif (workspace_size != NULL)prior to computing workspace requirements.resize-bilinear-nhwc: Set*workspace_size = 0whenbatch_size == 0.pack-lh: Set*output_size_bytes = 0whennum_groups == 0 || batch_size == 0.reduce-nd: Set*workspace_size = 0whennum_output_elements == 0. In addition:xnn_safe_mulandxnn_safe_add.scalecalculation against division by zero whennum_reduction_elements == 0.Subgraph Rank & Axis Reshape Validation:
static-constant-pad: Recordnum_padding_dimsinxnn_operator_dataand zero-initialize pre/post padding buffers. Validate during reshape thatinput_value->shape.num_dims >= opdata->num_padding_dims.static-slice: Recordnum_slice_dimsinxnn_operator_dataand zero-initialize begins/ends buffers. Validate during reshape thatinput_value->shape.num_dims == opdata->num_slice_dims.concatenate: Validate axis bounds (axis < 0 || (size_t) axis >= num_dims) early inreshape_concatenate_operatorbefore accessing input shapes or strides. Also fix duplicate word typo in error log ("failed to reshape reshape operator operator").Tests:
batch-matrix-multiply-nc,dynamic-fully-connected-nc,reduce-nd, andresize-bilinear-nhwc.concatenate, rank mismatch instatic-slice, and input rank less than padding rank instatic-constant-pad.