Fix iter_blocks on oddly sized or unaligned blocks#21
Closed
Fix iter_blocks on oddly sized or unaligned blocks#21
Conversation
If len < GRANULARITY * 2, insert_free_block_ptr doesn't insert another block:
```
let len = if let Some(x) = len
.checked_sub((start as usize).wrapping_sub(unaligned_start as usize))
.filter(|&x| x >= GRANULARITY * 2)
{
// Round down
x & !(GRANULARITY - 1)
} else {
// The block is too small
return None;
};
```
This can happen if the block being added has an odd size (not a multiple
of GRANULARITY * 2) or is unaligned.
Therefore, iter_blocks must also skip remaining lengths smaller than this.
I think this is the root cause for a panic we observed in
rust-embedded/embedded-alloc#121
jannic
added a commit
to jannic-dev-forks/embedded-alloc
that referenced
this pull request
Jan 28, 2026
Author
|
Interesting, seems like I missed that detail (and the author of https://github.com/rust-embedded/embedded-alloc/blob/master/src/tlsf.rs#L82-L83 as well). |
Owner
|
That is correct. |
Author
|
Thanks, I provided a PR for fixing the bug in embedded-alloc. I no longer think there is a bug in rlsf, so I'll close this ticket. |
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.
If len < GRANULARITY * 2, insert_free_block_ptr doesn't insert another block:
This can happen if the block being added has an odd size (not a multiple of GRANULARITY * 2) or is unaligned.
Therefore, iter_blocks must also skip remaining lengths smaller than this.
I think this is the root cause for a panic we observed in rust-embedded/embedded-alloc#121