Repository navigation
Fix overflow in qb4w f16 scale buffer sizing - #10946
Merged
copybara-service[bot] merged 2 commits intoAug 18, 2026
Merged
copybara-service[bot] merged 2 commits into
copybara-service[bot] merged 2 commits into
Conversation
Contributor
|
Please resolve conflicts |
Contributor
Author
done :) LGTM? |
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
Four
*_qb4w_f16_scalesfully-connected creation wrappers calculate atemporary BF16 scale-buffer size from caller-supplied dimensions before the
shared parameter validation runs. Both the scale-count multiplication and the
subsequent byte-size multiplication were unchecked.
With
input_channels = block_size = 32andoutput_channels = SIZE_MAX / sizeof(xnn_bfloat16) + 33, the byte-sizecalculation wraps to 64 bytes while the conversion loop retains the large
unwrapped element count. ASan reports a two-byte heap-buffer-overflow on the
first write past that allocation.
Fix
divide_round_upandxnn_safe_mulhelpersto calculate both the scale count and allocation size.
wrappers.
This follows the checked-allocation pattern already used in
create_fully_connected_ncand the overflow hardening merged in #10606. It isseparate from #10934 and #10935, which protect different buffers, and from
#10940, which adds allocation-failure checks after these three sibling
allocations.
Test
Added a regression test that calls all four affected wrappers with the
overflowing dimensions and verifies that they return
xnn_status_invalid_parameterwithout creating an operator.Before the fix, the focused test fails under ASan with:
After the fix:
All 10 fully-connected test shards pass under ASan/UBSan.
Authored with OpenAI Codex.