fix(mempool3): increase SIZE_CLASSES to avoid buffer overruns on large objects - #101
Open
shruti2522 wants to merge 1 commit into
Open
fix(mempool3): increase SIZE_CLASSES to avoid buffer overruns on large objects#101shruti2522 wants to merge 1 commit into
shruti2522 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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_CLASSESfrom 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_forstill truncates oversize allocations in release builds: the bound check is adebug_assert!(compiled out) and the function returnsidx.min(SIZE_CLASSES.len() - 1), which silently maps anysize > last_classinto 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.
| } | ||
|
|
||
| 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]; |
| } | ||
|
|
||
| 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
force-pushed
the
size_class
branch
3 times, most recently
from
August 21, 2026 01:36
ef30470 to
f1e033f
Compare
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.
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_allocplacing oversized objects into 2048 byte slots, causing severe buffer overruns and eventualmalloc_consolidateheap corruption panics.this patch expands
SIZE_CLASSESup to 65536 and changessize_class_index_forto panic instead of truncating.