Skip to content

analysis segmentation fault for references after #7887 #8475

@aspeddro

Description

@aspeddro

Segmentation fault in editor analysis references after for...of typedtree change #7887

The editor analysis binary can segfault when running references against an existing project (using v12) after commit f97609381a56063edf37c6b3bdd352f77fe44189. In 1ec0a25be752e97e22fce0d827b08c5e8c69c8fc (Move rescript.json reading out of bsc into rewatch - #8365) references works.

That commit adds new typedtree constructors for for...of / for await...of:

  • Texp_for_of
  • Texp_for_await_of

but the CMT magic number was not changed. Because .cmt files are marshalled OCaml values, changing the typedtree shape without changing the magic number can make the analysis binary read incompatible/stale .cmt files as if they were valid. This can produce invalid runtime values and segfault before OCaml exception handling can catch it.

Reproduction

From rescript-compiler:

git checkout f97609381a56063edf37c6b3bdd352f77fe44189
dune build @install

rescript-lang.org repo master branch:

/home/pedro/Desktop/projects/rescript-compiler/_build/default/analysis/bin/main.exe references /home/pedro/Desktop/projects/rescript-lang.org/apps/docs/app/DocsRoot.res 3 9
[1]    2261129 segmentation fault (core dumped)   references  3 9

It's a break because the compiler repo is on v13 and rescript-lang.org uses v12.2.0, but it's an important point for migration. It is necessary to remove all lib folders with cmt files.

Codex suggestions

Suspected cause

f97609381 changes the marshalled typedtree representation by adding new constructors, but Config.cmt_magic_number remains unchanged.

Since editor analysis reads .cmt files through Cmt_format.read_cmt, stale or ABI-incompatible .cmt files can pass the magic-number check and then crash during unmarshalling or typedtree traversal.

Possible fix

Bump the CMT magic number when changing typedtree constructors. Since this commit also changes parsetree constructors, AST magic may need to be reviewed as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions