diff options
author | Matthew Craven <5086-clyring@users.noreply.gitlab.haskell.org> | 2022-10-07 18:11:59 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-12-08 08:30:23 -0500 |
commit | e902d771197fd93488938b5eacb1ad6f23d408b7 (patch) | |
tree | 8d3609ebdf5eb5e76019f189d3b3019980f9e83d | |
parent | a74225803dc4ec14e3aef96cfe5e17bdc5f0d2a7 (diff) | |
download | haskell-e902d771197fd93488938b5eacb1ad6f23d408b7.tar.gz |
Fix bounds-checking buglet in Data.Array.Byte
...another manifestation of #20851 which
I unfortunately missed in my first pass.
-rw-r--r-- | libraries/base/Data/Array/Byte.hs | 8 |
1 files 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. -- |