Skip to content

Commit a7b90b8

Browse files
authored
Merge pull request #387 from Shimuuar/unfoldrn
Change allocation strategy for unfoldrN & add warning for fromListN
2 parents afb189a + e61b1f9 commit a7b90b8

File tree

6 files changed

+26
-6
lines changed

6 files changed

+26
-6
lines changed

vector/src/Data/Vector.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2119,7 +2119,11 @@ fromList :: [a] -> Vector a
21192119
{-# INLINE fromList #-}
21202120
fromList = G.fromList
21212121

2122-
-- | /O(n)/ Convert the first @n@ elements of a list to a vector.
2122+
-- | /O(n)/ Convert the first @n@ elements of a list to a vector. It's
2123+
-- expected that the supplied list will be exactly @n@ elements long. As
2124+
-- an optimization, this function allocates a buffer for @n@ elements, which
2125+
-- could be used for DoS-attacks by exhausting the memory if an attacker controls
2126+
-- that parameter.
21232127
--
21242128
-- @
21252129
-- fromListN n xs = 'fromList' ('take' n xs)

vector/src/Data/Vector/Fusion/Bundle/Monadic.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ unfoldrN n f = unfoldrNM n (return . f)
664664
-- | Unfold at most @n@ elements with a monadic function.
665665
unfoldrNM :: Monad m => Int -> (s -> m (Maybe (a, s))) -> s -> Bundle m u a
666666
{-# INLINE_FUSED unfoldrNM #-}
667-
unfoldrNM n f s = fromStream (S.unfoldrNM n f s) (Max (delay_inline max n 0))
667+
unfoldrNM n f s = fromStream (S.unfoldrNM n f s) Unknown
668668

669669
-- | Unfold exactly @n@ elements
670670
--

vector/src/Data/Vector/Generic.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2297,7 +2297,11 @@ fromList :: Vector v a => [a] -> v a
22972297
{-# INLINE fromList #-}
22982298
fromList = unstream . Bundle.fromList
22992299

2300-
-- | /O(n)/ Convert the first @n@ elements of a list to a vector.
2300+
-- | /O(n)/ Convert the first @n@ elements of a list to a vector. It's
2301+
-- expected that the supplied list will be exactly @n@ elements long. As
2302+
-- an optimization, this function allocates a buffer for @n@ elements, which
2303+
-- could be used for DoS-attacks by exhausting the memory if an attacker controls
2304+
-- that parameter.
23012305
--
23022306
-- @
23032307
-- fromListN n xs = 'fromList' ('take' n xs)

vector/src/Data/Vector/Primitive.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1786,7 +1786,11 @@ fromList :: Prim a => [a] -> Vector a
17861786
{-# INLINE fromList #-}
17871787
fromList = G.fromList
17881788

1789-
-- | /O(n)/ Convert the first @n@ elements of a list to a vector.
1789+
-- | /O(n)/ Convert the first @n@ elements of a list to a vector. It's
1790+
-- expected that the supplied list will be exactly @n@ elements long. As
1791+
-- an optimization, this function allocates a buffer for @n@ elements, which
1792+
-- could be used for DoS-attacks by exhausting the memory if an attacker controls
1793+
-- that parameter.
17901794
--
17911795
-- @
17921796
-- fromListN n xs = 'fromList' ('take' n xs)

vector/src/Data/Vector/Storable.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,11 @@ fromList :: Storable a => [a] -> Vector a
18321832
{-# INLINE fromList #-}
18331833
fromList = G.fromList
18341834

1835-
-- | /O(n)/ Convert the first @n@ elements of a list to a vector.
1835+
-- | /O(n)/ Convert the first @n@ elements of a list to a vector. It's
1836+
-- expected that the supplied list will be exactly @n@ elements long. As
1837+
-- an optimization, this function allocates a buffer for @n@ elements, which
1838+
-- could be used for DoS-attacks by exhausting the memory if an attacker controls
1839+
-- that parameter.
18361840
--
18371841
-- @
18381842
-- fromListN n xs = 'fromList' ('take' n xs)

vector/src/Data/Vector/Unboxed.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,11 @@ fromList :: Unbox a => [a] -> Vector a
18781878
{-# INLINE fromList #-}
18791879
fromList = G.fromList
18801880

1881-
-- | /O(n)/ Convert the first @n@ elements of a list to a vector.
1881+
-- | /O(n)/ Convert the first @n@ elements of a list to a vector. It's
1882+
-- expected that the supplied list will be exactly @n@ elements long. As
1883+
-- an optimization, this function allocates a buffer for @n@ elements, which
1884+
-- could be used for DoS-attacks by exhausting the memory if an attacker controls
1885+
-- that parameter.
18821886
--
18831887
-- @
18841888
-- fromListN n xs = 'fromList' ('take' n xs)

0 commit comments

Comments
 (0)