[Git][ghc/ghc][master] Fix bounds-checking buglet in Data.Array.Byte
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Thu Dec 8 13:30:40 UTC 2022
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
e902d771 by Matthew Craven at 2022-12-08T08:30:23-05:00
Fix bounds-checking buglet in Data.Array.Byte
...another manifestation of #20851 which
I unfortunately missed in my first pass.
- - - - -
1 changed file:
- libraries/base/Data/Array/Byte.hs
Changes:
=====================================
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.
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e902d771197fd93488938b5eacb1ad6f23d408b7
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e902d771197fd93488938b5eacb1ad6f23d408b7
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20221208/8db1d228/attachment-0001.html>
More information about the ghc-commits
mailing list