Skip to content

TextIO.inputAll segfaults when reading 980M file #283

Closed

Description

@serpent7776

Version

110.99.4 (Latest)

Operating System

  • Any
  • Linux
  • macOS
  • Windows
  • Other Unix

OS Version

Linux arc 5.10.194-1-MANJARO #1 SMP PREEMPT Sat Sep 2 20:55:57 UTC 2023 x86_64 GNU/Linux

Processor

  • Any
  • Arm (using Rosetta)
  • PowerPC
  • Sparc
  • x86 (32-bit)
  • x86-64 (64-bit)
  • Other

System Component

Basis Library

Severity

Major

Description

inputAll segfaults when reading 980M file with TextIo.inputAll.

Transcript

$ truncate -s 980M input
$ smlnj
fgrep: warning: fgrep is obsolescent; using grep -F
Standard ML of New Jersey (64-bit) v110.99.4 [built: Tue Aug 08 11:25:21 2023]
- val f = TextIO.openIn "input";
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[library $SMLNJ-BASIS/(basis.cm):basis-common.cm is stable]
[autoloading done]
val f = - : TextIO.instream
- val s = TextIO.inputAll f;
/usr/lib/smlnj/bin/sml: Fatal error -- bogus fault not in ML: pc = 0x55723ef19685, sig = 11

Expected Behavior

file to be read correctly, no segfault.

Steps to Reproduce

$ truncate -s 980M input
$ sml
- val f = TextIO.openIn "input";
- val s = TextIO.inputAll f;
/usr/lib/smlnj/bin/sml: Fatal error -- bogus fault not in ML: pc = 0x55723ef19685, sig = 11

Additional Information

Can reproduce this on FreeBSD DaemONX 12.4-RELEASE-p3 FreeBSD 12.4-RELEASE-p3 GENERIC amd64 with version Standard ML of New Jersey (64-bit) v110.98 [built: Sun Aug 21 21:39:28 2022]

Email address

serpent7776 \at gmail \dot com

Activity

  1. self-assigned this
    on Sep 24, 2023
  2. JohnReppy commented on Sep 26, 2023

    @JohnReppy
    Contributor

    I think that the bug is in runtime/gc/flip.c; it appears that the requested size of the new string arena is too small.

  3. added
    gcproblem with the garbage collector
    on Sep 26, 2023
  4. JohnReppy commented on Jan 31, 2024

    @JohnReppy
    Contributor

    The actual threshold of failure is actually slightly below 384M = (0x18000000). If we try 402653176 (i.e., 8 bytes smaller), then we get a different error:

    /usr/local/smlnj/bin/sml: Fatal error -- bad string tag 1, obj = 0x121240000, desc = 0x86
    

    A simpler test that shows the bug is to use Unsafe.CharVector.create to create a large string object. For example:

    Standard ML of New Jersey (64-bit) v110.99.4 [built: Tue Aug 01 16:07:38 2023]
    - Unsafe.CharVector.create 402653176;
    [autoloading]
    [library $SMLNJ-BASIS/basis.cm is stable]
    [library $SMLNJ-BASIS/(basis.cm):basis-common.cm is stable]
    [autoloading done]
    val it =
      "\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@\^@#"
    Memory fault
    
  5. JohnReppy commented on Mar 1, 2024

    @JohnReppy
    Contributor

    The problem actually turned out to be that we were still using 32-bit ints to represent some size information. Switching to using the Word_t type for array/vector lengths in the runtime system appears to have fixed the problem. The fix will be included in 110.99.5.

  6. changed the title [-]TextIO.inputAll segfaults when reading 980M file[/-] [+]`TextIO.inputAll` segfaults when reading 980M file[/+] on Mar 1, 2024
  7. added a commit that references this issue on Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

basis-libproblem with Standard ML Basis librarybugSomething isn't workingfixed-in-110.99.5issues that will be fixed in the 110.99.5 versiongcproblem with the garbage collector

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions