Repository navigation
Fix underflow in range_to_pow_2_blocks - #909
Open
LI SHANGXI (WinnieSmasher) wants to merge 1 commit into
Open
LI SHANGXI (WinnieSmasher) wants to merge 1 commit into
LI SHANGXI (WinnieSmasher) wants to merge 1 commit into
Conversation
The aligned range can be empty if the input is smaller than the minimum block size, or if its ends round towards each other. In that case pointer_diff() underflows size_t and the loop emits increasingly large blocks beyond the end of the range. Return early when there is no aligned range left, and add a unit test covering small and unaligned ranges. Fixes microsoft#567.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the range-length underflow fix.
No open issues 🎉
What changed in this PR
Fixes the range-length underflow reported in #567 by stopping block generation when alignment leaves an empty range.
Changes:
- Returns before
pointer_diff()when aligned endpoints meet or cross, preventing underflow and out-of-range block generation. - Adds regression tests covering unaligned, zero-length, and sub-minimum-block ranges, checking block bounds, alignment, contiguity, and total size.
| File | Description |
|---|---|
src/test/func/range_helpers/range_helpers.cc |
Adds an offset-and-length sweep validating emitted blocks. |
src/snmalloc/backend_helpers/range_helpers.h |
Guards empty aligned ranges before calculating their length. |
Review effort: Balanced
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.
The aligned range can be empty if
lengthis smaller than a minimum-sized block, or if the range's ends round towards each other.pointer_diff()then underflowssize_t, and the loop below callsfwith ever-increasing block sizes that walk past the end of the input range. On CHERI this manifests as capability length violations (see #567).Return early when there is no aligned range left. The check is performed before
pointer_diff(), so it also avoids tripping that function'scursor >= baseassertion in debug builds.Added
func-range_helpersto sweep unaligned offsets and lengths (including zero and sub-minimum-block lengths). It checks that every emitted block lies within the input range, is power-of-two sized, naturally aligned and contiguous, and that the total size matches the aligned range. The test fails without the fix (for example atoffset=1 length=0).Verified locally with GCC 15.2 on Windows in both Debug and Release;
func-range_helpers-fast,func-range_helpers-check,func-bits,func-pagemap,func-sizeclass,func-fixed_region,func-fixed_region_allocandfunc-mallocall pass.Fixes #567.