Skip to content

Commit f4efbf3

Browse files
authored
[fix] Possible overflow when allocating contiguous physical memory in bitmap-allocator (#10)
When `align_log2 >= 64` , the values of `1 << align_log2` and `base` will always be equal to 0, causing the while loop not to terminate and the program to panic.
1 parent f5f7fc7 commit f4efbf3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ fn find_contiguous(
313313
size: usize,
314314
align_log2: usize,
315315
) -> Option<usize> {
316-
if capacity < (1 << align_log2) || ba.is_empty() {
316+
if align_log2 >= 64 || capacity < (1 << align_log2) || ba.is_empty() {
317317
return None;
318318
}
319319

@@ -356,7 +356,7 @@ fn check_contiguous(
356356
size: usize,
357357
align_log2: usize,
358358
) -> bool {
359-
if capacity < (1 << align_log2) || ba.is_empty() {
359+
if align_log2 >= 64 || capacity < (1 << align_log2) || ba.is_empty() {
360360
return false;
361361
}
362362

0 commit comments

Comments
 (0)