Repository navigation
[operators] Harden transpose-nd against overflow, divide-by-zero, and null pointers - #11334
Open
anagnorisis2peripeteia wants to merge 1 commit into
Open
anagnorisis2peripeteia wants to merge 1 commit into
anagnorisis2peripeteia wants to merge 1 commit into
Conversation
anagnorisis2peripeteia
force-pushed
the
transpose-nd-overflow-hardening
branch
from
September 26, 2026 21:40
df514e3 to
a486889
Compare
anagnorisis2peripeteia
force-pushed
the
transpose-nd-overflow-hardening
branch
from
October 12, 2026 12:49
a486889 to
a854c4d
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 hardens the transpose operator implementation in
src/operators/transpose-nd.cagainst arithmetic overflow, division-by-zero, out-of-bounds indexing, and null pointer dereferences:create_transpose_nd):transpose_op_out != NULL.reshape_transpose_nd):transpose_op != NULL,input_shape != NULL, andperm != NULL.num_elements) and total byte size (total_bytes) calculations againstsize_toverflow withxnn_safe_mul.input_strideandoutput_stridebounds check calculations (stride[i] * shape[i]andcurrent_stride) withxnn_safe_multo prevent integer wrapping that could bypass the stride validation checks.xnn_normalize_transpose_permutationsucceeds and returnsnormalized_dims > 0, avoiding undefined behavior and underflow ofnormalized_dims - 1in subsequent indexing.normalized_element_size != 0before computing tile count, preventing division by zero.max(1, ...)) to prevent division by zero in subsequent tile aspect calculations.setup_transpose_nd):input != NULLandoutput != NULL.Testing
test/operators/transpose-nd.cccovering null pointer outputs, invalid reshape parameters (zero dims, oversized dims, null arrays, overflow shapes, duplicate/out-of-bounds permutations), and null setup pointers.transpose-nd-testand all 18 transpose-related tests in ctest pass cleanly.