Skip to content

Commit 2b8dcf3

Browse files
authored
Add safety check for size after broadcasting (#613)
1 parent f566d8c commit 2b8dcf3

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/impl_methods.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1512,6 +1512,12 @@ where
15121512
/// **Note:** Cannot be used for mutable iterators, since repeating
15131513
/// elements would create aliasing pointers.
15141514
fn upcast<D: Dimension, E: Dimension>(to: &D, from: &E, stride: &E) -> Option<D> {
1515+
// Make sure the product of non-zero axis lengths does not exceed
1516+
// `isize::MAX`. This is the only safety check we need to perform
1517+
// because all the other constraints of `ArrayBase` are guaranteed
1518+
// to be met since we're starting from a valid `ArrayBase`.
1519+
let _ = size_of_shape_checked(to).ok()?;
1520+
15151521
let mut new_stride = to.clone();
15161522
// begin at the back (the least significant dimension)
15171523
// size of the axis has to either agree or `from` has to be 1

0 commit comments

Comments
 (0)