Skip to content

Segfault on Windows when stdout is not a real console handle #124

@davesnx

Description

@davesnx

Description

lambda-term 3.3.3 segfaults on Windows (GitHub Actions windows-latest runner, OCaml 4.14.3) when LTerm.stdout is force-evaluated. This affects utop and anything built on top of it (e.g. Reason's rtop).

Reproduction

On a Windows GitHub Actions runner (or any Windows environment where stdout may not be a real console handle):

echo "1 + 1;;" | utop 2>&1

Output:

OCaml version 4.14.3
Enter #help;; for help.

Segmentation fault

This also happens without piped input — just running utop segfaults.

Environment

  • OS: Windows (GitHub Actions windows-latest runner)
  • OCaml: 4.14.3
  • lambda-term: 3.3.3
  • utop: 2.16.0
  • lwt: 6.1.1

Analysis

The crash appears to be in lt_term_get_size_from_fd in lTerm_term_stubs.c:

CAMLprim value lt_term_get_size_from_fd(value fd)
{
  CONSOLE_SCREEN_BUFFER_INFO info;
  if (!GetConsoleScreenBufferInfo(Handle_val(fd), &info)) {
    win32_maperr(GetLastError());
    uerror("GetConsoleScreenBufferInfo", Nothing);
  }
  ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions