Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Register
  • Sign in
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 5.5k
    • Issues 5.5k
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 631
    • Merge requests 631
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Model experiments
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #3486

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
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking