@@ -34,6 +34,7 @@ use cmp::Ordering::{self, Less, Equal, Greater};
34
34
use cmp;
35
35
use fmt;
36
36
use intrinsics:: assume;
37
+ use isize;
37
38
use iter:: * ;
38
39
use ops:: { FnMut , Try , self } ;
39
40
use option:: Option ;
@@ -4080,6 +4081,9 @@ unsafe impl<'a, T> TrustedRandomAccess for ChunksExactMut<'a, T> {
4080
4081
/// them from other data. You can obtain a pointer that is usable as `data`
4081
4082
/// for zero-length slices using [`NonNull::dangling()`].
4082
4083
///
4084
+ /// The total size of the slice must be no larger than `isize::MAX` **bytes**
4085
+ /// in memory. See the safety documentation of [`pointer::offset`].
4086
+ ///
4083
4087
/// # Caveat
4084
4088
///
4085
4089
/// The lifetime for the returned slice is inferred from its usage. To
@@ -4101,10 +4105,13 @@ unsafe impl<'a, T> TrustedRandomAccess for ChunksExactMut<'a, T> {
4101
4105
/// ```
4102
4106
///
4103
4107
/// [`NonNull::dangling()`]: ../../std/ptr/struct.NonNull.html#method.dangling
4108
+ /// [`pointer::offset`]: ../../std/primitive.pointer.html#method.offset
4104
4109
#[ inline]
4105
4110
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
4106
4111
pub unsafe fn from_raw_parts < ' a , T > ( data : * const T , len : usize ) -> & ' a [ T ] {
4107
4112
debug_assert ! ( data as usize % mem:: align_of:: <T >( ) == 0 , "attempt to create unaligned slice" ) ;
4113
+ debug_assert ! ( mem:: size_of:: <T >( ) . saturating_mul( len) <= isize :: MAX as usize ,
4114
+ "attempt to create slice covering half the address space" ) ;
4108
4115
Repr { raw : FatPtr { data, len } } . rust
4109
4116
}
4110
4117
@@ -4114,15 +4121,19 @@ pub unsafe fn from_raw_parts<'a, T>(data: *const T, len: usize) -> &'a [T] {
4114
4121
/// This function is unsafe for the same reasons as [`from_raw_parts`], as well
4115
4122
/// as not being able to provide a non-aliasing guarantee of the returned
4116
4123
/// mutable slice. `data` must be non-null and aligned even for zero-length
4117
- /// slices as with [`from_raw_parts`]. See the documentation of
4118
- /// [`from_raw_parts`] for more details.
4124
+ /// slices as with [`from_raw_parts`]. The total size of the slice must be no
4125
+ /// larger than `isize::MAX` **bytes** in memory.
4126
+ ///
4127
+ /// See the documentation of [`from_raw_parts`] for more details.
4119
4128
///
4120
4129
/// [`from_raw_parts`]: ../../std/slice/fn.from_raw_parts.html
4121
4130
#[ inline]
4122
4131
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
4123
4132
pub unsafe fn from_raw_parts_mut < ' a , T > ( data : * mut T , len : usize ) -> & ' a mut [ T ] {
4124
4133
debug_assert ! ( data as usize % mem:: align_of:: <T >( ) == 0 , "attempt to create unaligned slice" ) ;
4125
- Repr { raw : FatPtr { data, len} } . rust_mut
4134
+ debug_assert ! ( mem:: size_of:: <T >( ) . saturating_mul( len) <= isize :: MAX as usize ,
4135
+ "attempt to create slice covering half the address space" ) ;
4136
+ Repr { raw : FatPtr { data, len } } . rust_mut
4126
4137
}
4127
4138
4128
4139
/// Converts a reference to T into a slice of length 1 (without copying).
0 commit comments