Skip to content

fix(mempool3): increase SIZE_CLASSES to avoid buffer overruns on large objects - #101

Open
shruti2522 wants to merge 1 commit into
boa-dev:mainfrom
shruti2522:size_class
Open

fix(mempool3): increase SIZE_CLASSES to avoid buffer overruns on large objects#101
shruti2522 wants to merge 1 commit into
boa-dev:mainfrom
shruti2522:size_class

Conversation

@shruti2522

Copy link
Copy Markdown
Contributor

mempool3's size classes previously capped at 2048 bytes. When allocating an object larger than this (e.g. ICU structs), size_class_index_for would silently truncate the size to 2048 bytes in release mode. This led to try_alloc placing oversized objects into 2048 byte slots, causing severe buffer overruns and eventual malloc_consolidate heap corruption panics.

this patch expands SIZE_CLASSES up to 65536 and changes size_class_index_for to panic instead of truncating.

Copilot AI lite review requested due to automatic review settings August 21, 2026 01:23
@shruti2522 shruti2522 changed the title fix(mempool3): increase SIZE_CLASSES to avoid buffer overruns on larg… …e objects fix(mempool3): increase SIZE_CLASSES to avoid buffer overruns on large objects Aug 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Expands mempool3’s slot size classes to support larger typed allocations (e.g., ICU-sized structs) and aims to prevent unsafe placement of oversized objects into too-small slots.

Changes:

  • Extends SIZE_CLASSES from a 2048B cap up to 65536B.
  • Adjusts (intended) oversize handling so allocations beyond the largest class should fail loudly rather than silently truncating.
Suppressed comments (1)

oscars/src/alloc/mempool3/mod.rs:35

  • size_class_index_for still truncates oversize allocations in release builds: the bound check is a debug_assert! (compiled out) and the function returns idx.min(SIZE_CLASSES.len() - 1), which silently maps any size > last_class into the largest class. That contradicts the PR description and can still place too-large objects into an undersized slot (now 65536B).
const SIZE_CLASSES: &[usize] = &[16, 24, 32, 48, 64, 96, 128, 192, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536];

#[inline(always)]
fn size_class_index_for(size: usize) -> usize {
    // binary search over size classes

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread oscars/src/alloc/mempool3/mod.rs Outdated
}

const SIZE_CLASSES: &[usize] = &[16, 24, 32, 48, 64, 96, 128, 192, 256, 512, 1024, 2048];
const SIZE_CLASSES: &[usize] = &[16, 24, 32, 48, 64, 96, 128, 192, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536];
Comment thread oscars/src/alloc/mempool3/mod.rs Outdated
}

const SIZE_CLASSES: &[usize] = &[16, 24, 32, 48, 64, 96, 128, 192, 256, 512, 1024, 2048];
const SIZE_CLASSES: &[usize] = &[16, 24, 32, 48, 64, 96, 128, 192, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536];
@shruti2522
shruti2522 force-pushed the size_class branch 3 times, most recently from ef30470 to f1e033f Compare August 21, 2026 01:36
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.

2 participants