Skip to content

Fix potential panic due to huge layout - #79

Merged
phil-opp merged 1 commit into
rust-osdev:mainfrom
00xc:fix_layout_panic
Oct 25, 2023
Merged

phil-opp merged 1 commit into
rust-osdev:mainfrom
00xc:fix_layout_panic

Conversation

@00xc

@00xc 00xc commented Oct 2, 2023 •

Copy link
Copy Markdown
Contributor

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.

@phil-opp phil-opp left a comment

Copy link
Copy Markdown
Member

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
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