Fix overflow/underflow bugs in bitset allocator, RtServer replenish, and IndexMap iterator#49
Draft
Copilot wants to merge 2 commits intofix/misc-bugsfrom
Draft
Fix overflow/underflow bugs in bitset allocator, RtServer replenish, and IndexMap iterator#49Copilot wants to merge 2 commits intofix/misc-bugsfrom
Copilot wants to merge 2 commits intofix/misc-bugsfrom
Conversation
Agent-Logs-Url: https://github.com/OsirisRTOS/osiris/sessions/f63a1358-2cfb-4d9d-8ada-ddd2c84eff6f Co-authored-by: xarantolus <32465636+xarantolus@users.noreply.github.com>
Author
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. |
Copilot
AI
changed the title
[WIP] Fix different over/underflow bugs
Fix overflow/underflow bugs in bitset allocator, RtServer replenish, and IndexMap iterator
Apr 4, 2026
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.
Four arithmetic bugs exposed by panicking tests, covering integer overflow and underflow in the PFA bitset allocator marking phase, RT budget replenishment, and the IndexMap cycle iterator.
Fixes
bitset.rsmarking underflow —rem = len.min(BITS_PER_WORD) - skipunderflowed when a free run started at the last bit of a word (skip=63, len=1→1 - 63). Replaced withrem = (BITS_PER_WORD - skip).min(count)using a dedicatedcount = page_countvariable for the marking loop, keeping search-phaselenuntouched.thread.rsreplenish overflow —budget_left += budgetoverflowed when both values approachedu32::MAX. Changed tosaturating_add.array.rsiter_from_cycle/next()overflow —K::to_index(idx) + 1panicked whenidx = usize::MAX. Fixed with.wrapping_add(1) % Niniter_from_cycleand the same wrapping arithmetic in thenext()index computation.array.rsreserve()OOM in tests —reserve()legitimately needs to grow extra heap storage (e.g.len=7, N=8, additional=2requires 1 extra slot), butGLOBAL_ALLOCATORis uninitialized in the test environment. Added#[cfg(test)] pub(crate) init_test_heap()tomem.rsthat seeds the global allocator with 64 KiB of host memory viastd::alloc::alloc, called from the affected test.