Skip to content

Add overflow checks to reduce-nd workspace sizing#9988

Open
TristanInSec wants to merge 1 commit intogoogle:masterfrom
TristanInSec:fix-reduce-workspace-overflow
Open

Add overflow checks to reduce-nd workspace sizing#9988
TristanInSec wants to merge 1 commit intogoogle:masterfrom
TristanInSec:fix-reduce-workspace-overflow

Conversation

@TristanInSec
Copy link
Copy Markdown

Summary

  • Add __builtin_mul_overflow checks to workspace size computation in reshape_reduce_nd()
  • Both innermost and non-innermost reduction paths are checked
  • Return xnn_status_invalid_parameter when the workspace size would overflow
  • Prevents undersized workspace allocation on 32-bit platforms (ARM32, WebAssembly)

Test plan

  • Verified overflow is detected for normalized shapes with dimension products exceeding 2^32 on 32-bit
  • Verified both innermost and non-innermost code paths have overflow checks
  • Verified normal (non-overflowing) workspace sizes are computed correctly

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 17, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

The workspace size for reduce operations is computed by multiplying
normalized input shape dimensions as size_t values. On 32-bit
platforms, this can overflow to zero or a small value, causing an
undersized workspace allocation that the reduction kernel then
writes past.

Add __builtin_mul_overflow checks to both the innermost and
non-innermost reduction paths, returning xnn_status_invalid_parameter
when the workspace size would overflow.
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.

1 participant