Skip to content

Segfault when using enumFromTo with maxBound as upper bound #188

Description

@noughtmare

I get a segfault when running the following code:

import qualified Data.Vector as V
import Data.Word

main :: IO ()
main = (V.enumFromTo (pred maxBound) maxBound :: V.Vector Word8) `seq` return ()
$ cabal --version
cabal-install version 2.0.0.0
compiled using version 2.0.0.2 of the Cabal library 
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.2.1

I now use enumFromN as a workaround, that works.

This happens with vector-0.12.0.1 from hackage.

Activity

  1. glguy commented on Nov 30, 2017

    @glguy
    Member

    This only happens with optimizations enabled for me. Looking at the core it seems like what's happening is the counter from 0 to 255 is being incremented by one and then being compared with <= to 255. I think that the counter is overflowing back to 0 and so the code writes past the end of the allocated vector (which I checked is correctly allocated to 256 elements).

    I also get a segmentation fault from this simpler code:

    main :: IO ()
    main = do
      let t = V.enumFromTo 255 255 :: V.Vector Word8
      t `seq` putStrLn "Thawing succeeded"
  2. changed the title [-]Segfault when thawing enumFromTo of Word8's[/-] [+]Segfault when using enumFromTo with maxBound as upper bound[/+] on Nov 30, 2017
  3. glguy commented on Nov 30, 2017

    @glguy
    Member

    I updated the ticket title because this isn't specific to thaw, or to Word8, it is reproducible with Word16, Word32, etc as long as the upper bound is set to maxBound

  4. noughtmare commented on Nov 30, 2017

    @noughtmare
    Author

    I have also updated the code.

  5. dolio commented on Dec 10, 2017

    @dolio
    Contributor

    Do we know what's broken? Tracing along the enumFromTo implementation, I get to a corresponding function on (monadic) bundles. But that just calls fromList [x .. y].

    Is it unstream that's broken?

  6. glguy commented on Aug 24, 2018

    @glguy
    Member
  7. cartazio commented on Jul 12, 2019

    @cartazio
    Contributor

    booo, this needs to be fixed, adding to action list :)

  8. cartazio commented on Jan 21, 2020

    @cartazio
    Contributor

    brr, this has been languishing for too long

  9. added a commit that references this issue on Jan 31, 2020
  10. cartazio commented on Jan 31, 2020

    @cartazio
    Contributor

    this should be resolved in master now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions