mm gran reject oversized pools#19146
Open
masc2008 wants to merge 1 commit into
Open
Conversation
xiaoxiang781216
approved these changes
Jun 16, 2026
masc2008
commented
Jun 16, 2026
masc2008
left a comment
Contributor
Author
There was a problem hiding this comment.
let it report error if over max of uint16_t.
77b73f5 to
6ac360f
Compare
struct gran_s and struct graninfo_s store granule counts in uint16_t. Reject pools whose computed granule count exceeds UINT16_MAX, instead of truncating the count and creating an invalid handle. Signed-off-by: shichunma <shichunma@bestechnic.com>
6ac360f to
a3a6d91
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.
Summary
Reject oversized granule heaps in
gran_initialize().struct gran_sandstruct graninfo_sstore granule counts inuint16_t, soa large pool with a small granule size can silently truncate
ngranulesduring initialization and produce an invalid handle.
This patch adds a debug assertion and returns
NULLwithEINVALwhen thecomputed granule count does not fit.
Changes
DEBUGASSERT()to catch oversized granule counts in debug buildsNULLwitherrno = EINVALwhen the computedngranulesis zero orexceeds
UINT16_MAXWhy this is needed
For example, a 16 MiB pool with 64-byte granules computes:
ngranules = 16 MiB / 64 = 262144That does not fit in the current 16-bit
ngranulesfields and truncates,leading to a broken allocator handle.
Failing early is safer than silently constructing an invalid granule heap.
Impact
less obvious ways
Testing
struct gran_s/struct graninfo_sdefinitions