From 1fb2f42b5ad73a716f127de0d194b36dfa8cb575 Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Tue, 7 Dec 2021 00:01:33 -0500 Subject: [PATCH] Add missing checks when converting slices to views --- src/arraytraits.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/arraytraits.rs b/src/arraytraits.rs index 6a4fd1137..d845c3075 100644 --- a/src/arraytraits.rs +++ b/src/arraytraits.rs @@ -336,6 +336,11 @@ impl<'a, A, const N: usize> From<&'a [[A; N]]> for ArrayView<'a, A, Ix2> { if size_of::() == 0 { dimension::size_of_shape_checked(&dim) .expect("Product of non-zero axis lengths must not overflow isize."); + } else if N == 0 { + assert!( + xs.len() <= isize::MAX as usize, + "Product of non-zero axis lengths must not overflow isize.", + ); } // `cols * rows` is guaranteed to fit in `isize` because we checked that it fits in @@ -392,6 +397,11 @@ impl<'a, A, const N: usize> From<&'a mut [[A; N]]> for ArrayViewMut<'a, A, Ix2> if size_of::() == 0 { dimension::size_of_shape_checked(&dim) .expect("Product of non-zero axis lengths must not overflow isize."); + } else if N == 0 { + assert!( + xs.len() <= isize::MAX as usize, + "Product of non-zero axis lengths must not overflow isize.", + ); } // `cols * rows` is guaranteed to fit in `isize` because we checked that it fits in