From e902d771197fd93488938b5eacb1ad6f23d408b7 Mon Sep 17 00:00:00 2001 From: Matthew Craven <5086-clyring@users.noreply.gitlab.haskell.org> Date: Fri, 7 Oct 2022 18:11:59 -0400 Subject: Fix bounds-checking buglet in Data.Array.Byte ...another manifestation of #20851 which I unfortunately missed in my first pass. --- libraries/base/Data/Array/Byte.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/base/Data/Array/Byte.hs b/libraries/base/Data/Array/Byte.hs index 549ca96bd7..918e20bae8 100644 --- a/libraries/base/Data/Array/Byte.hs +++ b/libraries/base/Data/Array/Byte.hs @@ -101,18 +101,20 @@ byteArrayToList arr = go 0 -- | Create a 'ByteArray' from a list of a known length. If the length -- of the list does not match the given length, this throws an exception. byteArrayFromListN :: Int -> [Word8] -> ByteArray -byteArrayFromListN n ys = runST $ do +byteArrayFromListN n ys + | n >= 0 = runST $ do marr <- newByteArray n let go !ix [] = if ix == n then return () - else error $ "Data.Array.Byte.byteArrayFromListN: list length less than specified size" + else errorWithoutStackTrace $ "Data.Array.Byte.byteArrayFromListN: list length less than specified size" go !ix (x : xs) = if ix < n then do writeByteArray marr ix x go (ix + 1) xs - else error $ "Data.Array.Byte.byteArrayFromListN: list length greater than specified size" + else errorWithoutStackTrace $ "Data.Array.Byte.byteArrayFromListN: list length greater than specified size" go 0 ys unsafeFreezeByteArray marr + | otherwise = errorWithoutStackTrace "Data.Array.Byte.ByteArrayFromListN: specified size is negative" -- | Copy a slice of an immutable byte array to a mutable byte array. -- -- cgit v1.2.1