Skip to content

Regression/new segfault with module loading #4570

@rhuanjl

Description

@rhuanjl

@fatcerberus and I have found a new hard crash related to module loading in the latest 1.8, 1.9 and master branches.

I think this may have unfortunately been produced by #4551 I can't see how it would have caused it - but it's the only relevant change as far as I can see - @obastemur thoughts?

The issue as far as I can see is that if you have 1 module referenced via more than 1 path the parent is set with more than 1 name:
https://github.com/Microsoft/ChakraCore/blob/release/1.9/lib/Runtime/Language/SourceTextModuleRecord.cpp#L771

Putting an if and a printf into ModuleEvaluation around line 949
https://github.com/Microsoft/ChakraCore/blob/release/1.9/lib/Runtime/Language/SourceTextModuleRecord.cpp#L949

Shows that rootFunction appears to be nullptr for all paths other than the first one used.

The test case below reproduces this by having module2.js imported from module1.js in the same folder as it and module3.js in a different folder.

Whilst it's possible to paper over this error by just checking for rootFunction ==nullptr and if it is then calling GenerateRootFunction from line 949 I don't think that's the correct fix.

Repro

//test.js
WScript.LoadScriptFile("module1.js","module");
//module1.js
import mod2 from "./module2.js";
import {mod3} from "./folder/module3.js";

export function mod1()
{
	print("mod1");
}

mod2();
mod3();
//module2.js
export default function()
{
	print("mod2");
}
//folder/module3.js
import mod3 from "../module2.js";

export {mod3};

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions