Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,11 @@ fn rc_inner_layout_for_value_layout(layout: Layout) -> Layout {
// Previously, layout was calculated on the expression
// `&*(ptr as *const RcInner<T>)`, but this created a misaligned
// reference (see #54908).
Layout::new::<RcInner<()>>().extend(layout).unwrap().0.pad_to_align()
Layout::new::<RcInner<()>>()
.extend(layout)
.unwrap_or_else(|_| panic!("capacity overflow"))
.0
.pad_to_align()
}

/// A single-threaded reference-counting pointer. 'Rc' stands for 'Reference
Expand Down
6 changes: 5 additions & 1 deletion library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,11 @@ fn arcinner_layout_for_value_layout(layout: Layout) -> Layout {
// Previously, layout was calculated on the expression
// `&*(ptr as *const ArcInner<T>)`, but this created a misaligned
// reference (see #54908).
Layout::new::<ArcInner<()>>().extend(layout).unwrap().0.pad_to_align()
Layout::new::<ArcInner<()>>()
.extend(layout)
.unwrap_or_else(|_| panic!("capacity overflow"))
.0
.pad_to_align()
}

unsafe impl<T: ?Sized + Sync + Send> Send for ArcInner<T> {}
Expand Down
6 changes: 6 additions & 0 deletions library/alloctests/tests/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,9 @@ fn issue_155746_make_mut_panic_safety() {
assert_eq!(*arc, [[1]]);
assert_eq!(Arc::strong_count(&arc), 1); // if this is 0, we have a UAF!
}

#[test]
#[should_panic = "capacity overflow"]
fn new_uninit_slice_capacity_overflow() {
let _ = Arc::<[u8]>::new_uninit_slice(isize::MAX as usize);
}
8 changes: 8 additions & 0 deletions library/alloctests/tests/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,3 +967,11 @@ fn issue_158875_make_mut_dont_leak_allocator() {

assert_eq!(Rc::strong_count(&alloc), 1); // if this is >1, we have a memory leak!
}

#[test]
#[should_panic = "capacity overflow"]
fn new_uninit_slice_capacity_overflow() {
// header + payload layout exceeds isize::MAX -> "capacity overflow", not
// an unwrapped LayoutError. Regression test for #136797.
let _ = Rc::<[u8]>::new_uninit_slice(isize::MAX as usize);
}
Loading