Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix potential panic due to huge layout #79

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

00xc
Copy link
Contributor

@00xc 00xc commented Oct 2, 2023

If a user provides a layout with a big enough size, the allocator might panic on an unwrap instead of returning an error. The reason is that, even though the layout size is properly rounded to a power of two, Layout::from_size_align() will fail if the size overflows isize when rounded to the layout alignment.

Fix this by handling the error instead of unwrapping it.

Keep an unwrap in the HoleList::deallocate() as the validity of the layout must be guaranteed by the caller since it is an unsafe function.

If a user provides a layout with a big enough size, the allocator
might panic on an unwrap instead of returning an error. The reason is
that, even though the layout size is properly rounded to a power of
two, Layout::from_size_align() will fail if the size overflows isize
when rounded to the layout alignment.

Fix this by handling the error instead of unwrapping it.

Keep an unwrap in the HoleList::deallocate() as the validity of the
layout must be guaranteed by the caller since it is an unsafe
function.
Copy link
Member

@phil-opp phil-opp left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@phil-opp phil-opp enabled auto-merge October 25, 2023 12:55
@phil-opp phil-opp merged commit 3c9bafa into rust-osdev:main Oct 25, 2023
12 checks passed
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