Ticket #3514 (closed merge: fixed)

Opened 4 years ago

Last modified 3 years ago

mallocPlainForeignPtrBytes -1000 gives runtime internal error: allocGroup: requested zero blocks

Reported by: andrewbirkett Owned by: igloo
Priority: normal Milestone: 6.12.2
Component: Runtime System Version: 6.10.4
Keywords: Cc:
Operating System: Linux Architecture: x86
Type of failure: None/Unknown Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

Passing negative numbers to mallocPlainForeignPtrBytes causes the following to appear:

Test: internal error: allocGroup: requested zero blocks
   (GHC version 6.10.4 for i386_unknown_linux)
    Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
Aborted

Originally, a bug in my app meant that I called Data.ByteString?.hGet with a negative 'numBytes' argument, however I've managed to boil it down to a one line test case involving just mallocPlainForeignPtrBytes as follows:

$ cat Test.hs
import GHC.ForeignPtr (mallocPlainForeignPtrBytes)
main = mallocPlainForeignPtrBytes (-1000)

$ ghc --make Test.hs 
[1 of 1] Compiling Main             ( Test.hs, Test.o )
Linking Test ...

$ ./Test
Test: internal error: allocGroup: requested zero blocks
    (GHC version 6.10.4 for i386_unknown_linux)
    Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug
Aborted

The magnitude of the number appears to have some effect; with ghc 6.10.1 it seemed to reliably crash with numBytes <= -9. But when I upgraded to ghc 6.10.4, the test case started working. However, changing to -1000 reliably causes a crash on my box - perhaps the behaviour depends on heap layout. Either way, the function should probably behave more gracefully .. perhaps raising an exception.

Full gory details of my setup (ie. ghc -v output, gcc version) are attached because they messed up the formatting.

Attachments

machine.txt Download (7.2 KB) - added by andrewbirkett 4 years ago.
uname/gcc/ghc -v output

Change History

Changed 4 years ago by andrewbirkett

uname/gcc/ghc -v output

Changed 4 years ago by duncan

bytestring hGet is now fixed in the darcs repo. Also audited for other cases in the bytestring package.

Looking at the GHC.ForeignPtr? code, the following probably need fixing:

mallocForeignPtr
mallocForeignPtrBytes
mallocPlainForeignPtr
mallocPlainForeignPtrBytes

In the case of the non-"Bytes" versions that use Storable, that'd be a check for the Storable sizeOf function returning a negative value.

Changed 4 years ago by igloo

  • difficulty set to Unknown
  • milestone set to 6.12.1

Changed 4 years ago by igloo

  • failure set to None/Unknown
  • milestone changed from 6.12.1 to 6.12.2

Changed 3 years ago by simonmar

  • owner set to igloo
  • type changed from bug to merge

Fixed (libraries/base):

Wed Nov 25 06:38:22 PST 2009  Simon Marlow <marlowsd@gmail.com>
  * check for size < 0 in mallocForeignPtrBytes and friends (#3514)

Changed 3 years ago by igloo

  • status changed from new to closed
  • resolution set to fixed

Merged

Note: See TracTickets for help on using tickets.