Data.ByteString.elemIndices causes SEGV
The elemIndices for strict ByteString causes SEGV in some situation.
import Data.Int
import qualified Data.ByteString as S
main = do
cs <- S.getContents
let ps = S.elemIndices 10 cs
putStrLn $ "S.length cs = " ++ show (S.length cs)
putStrLn $ "length ps = " ++ show (length ps)
If above program gets some large input, it crashes.
$ ghc --make ei
[1 of 1] Compiling Main ( ei.hs, ei.o )
Linking ei ...
$ yes | head -10000 | ./ei
S.length cs = 20000
Segmentation fault
By the way, there might be a border of SEGV or not.
$ yes | head -4096 | ./ei
S.length cs = 8192
Segmentation fault
$ yes | head -4095 | ./ei
S.length cs = 8190
length ps = 4095
And this script works fine.
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
main = do
let cs = S.pack . take 8192 . cycle $ [48,10]
ps = S.elemIndices 10 cs
putStrLn $ "length cs = " ++ show (S.length cs)
putStrLn $ "length ps = " ++ show (length ps)
I think there is causes about the bug in S.getContents or S.elemIndices or both. But I cannot figure out it.
Trac metadata
Trac field | Value |
---|---|
Version | 6.10.4 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | libraries/base |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |