Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,830
    • Issues 4,830
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 447
    • Merge requests 447
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #17414

Closed
Open
Created Oct 29, 2019 by Luite Stegeman@luiteDeveloper

File read/write operations >= 2GiB fail on macOS with an "Invalid argument" exception

Summary

File reads/writes bigger than 2GB result in an "Invalid argument" exception on macOS. Files bigger than 2GB still work, but individual read/write operations bigger than 2GB fail.

This was already reported for the bytestring library, but the actual problem is in base. I didn't see an earlier report.

bytestring report: https://github.com/haskell/bytestring/issues/153

Python has a workaround for this issue and more discussion: https://bugs.python.org/issue24658

Steps to reproduce

{-# LANGUAGE ScopedTypeVariables #-}
import Foreign.Ptr (Ptr)
import Foreign.Marshal.Alloc (mallocBytes, free)
import System.IO (hPutBuf, withBinaryFile, IOMode (WriteMode)) 

-- more than 2GiB
numBytes :: Int
numBytes = 2264375889

main :: IO ()
main = do
  (ptr :: Ptr ()) <- mallocBytes numBytes
  -- the next line produces the exception on macOS
  withBinaryFile "test.out" WriteMode (\h -> hPutBuf h ptr numBytes)
  free ptr

Expected behavior

The base library provides operating system independent buffering and encoding functionality. I think it should work around operating system peculiarities and write all the data to the test.out file without throwing an excepion.

Environment

Tested with GHC 8.6.5 on macOS 10.14.6

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking