Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault with cyclic imports #567

Closed
malbarbo opened this issue Sep 30, 2024 · 1 comment · Fixed by #568
Closed

Segmentation fault with cyclic imports #567

malbarbo opened this issue Sep 30, 2024 · 1 comment · Fixed by #568
Labels
bug Something isn't working

Comments

@malbarbo
Copy link

This bug was initially reported in bellard/quickjs#329, but it seams that there it didn't get any attention, so I'm reporting it here too.

To reproduce create two files a.mjs and b.mjs and run qjs a.mjs.

a.mjs:

import { fb } from "./b.mjs";
export { fb };

b.mjs:

import * as $a from "a.mjs";
export function fb() {};

There is no crash if export { fb }; is removed from a.mjs or the import in b.mjs is changed to import {} from "a.mjs";.

AddressSanitizer:DEADLYSIGNAL
=================================================================
==277778==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x0000004fbc1c bp 0x7ffcc9070200 sp 0x7ffcc90700c0 T0)
==277778==The signal is caused by a WRITE memory access.
==277778==Hint: address points to the zero page.
    #0 0x4fbc1c in js_build_module_ns /quickjs/quickjs.c:28041
    #1 0x4fc144 in JS_GetModuleNamespace /quickjs/quickjs.c:28076
    #2 0x58bf20 in js_inner_module_linking /quickjs/quickjs.c:28333
    #3 0x58b7e3 in js_inner_module_linking /quickjs/quickjs.c:28268
    #4 0x5a175d in js_link_module /quickjs/quickjs.c:28441
    #5 0x5a175d in JS_EvalFunctionInternal /quickjs/quickjs.c:34409
    #6 0x5a2487 in JS_EvalFunction /quickjs/quickjs.c:34425
    #7 0x40bec9 in eval_buf /quickjs/qjs.c:67
    #8 0x40bff5 in eval_file /quickjs/qjs.c:103
    #9 0x40b050 in main /quickjs/qjs.c:516
    #10 0x7ff77b15a10d in __libc_start_call_main (/nix/store/k7zgvzp2r31zkg9xqgjim7mbknryv6bs-glibc-2.39-52/lib/libc.so.6+0x2a10d) (BuildId: bc8ec5f3ac2561de8f08b232685038c7167bf4b7)
    #11 0x7ff77b15a1c8 in __libc_start_main_alias_1 (/nix/store/k7zgvzp2r31zkg9xqgjim7mbknryv6bs-glibc-2.39-52/lib/libc.so.6+0x2a1c8) (BuildId: bc8ec5f3ac2561de8f08b232685038c7167bf4b7)
    #12 0x40b584 in _start (/quickjs/qjs+0x40b584)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /quickjs/quickjs.c:28041 in js_build_module_ns
==277778==ABORTING
bnoordhuis added a commit to bnoordhuis/quickjs that referenced this issue Sep 30, 2024
Consider the following two files:

    // a.js
    import {f} from "b.js"
    export {f}

And:

    // b.js
    import * as a from "a.js"
    export function f() {}

Before this commit, it crashed with a nullptr dereference. Throw a
"circular reference when looking for export" SyntaxError.

No test because the test suite currently isn't equipped for tests
that throw exceptions at import time.

Fixes: quickjs-ng#567
@bnoordhuis bnoordhuis added the bug Something isn't working label Sep 30, 2024
@bnoordhuis
Copy link
Contributor

Fix in #568.

bnoordhuis added a commit to bnoordhuis/quickjs that referenced this issue Oct 5, 2024
Consider the following two files:

    // a.js
    import {f} from "b.js"
    export {f}

And:

    // b.js
    import * as a from "a.js"
    export function f() {}

Before this commit, it crashed with a nullptr dereference. Throw a
"circular reference when looking for export" SyntaxError.

No test because the test suite currently isn't equipped for tests
that throw exceptions at import time.

Fixes: quickjs-ng#567
bnoordhuis added a commit to bnoordhuis/quickjs that referenced this issue Oct 14, 2024
Before this commit it segfaulted, now it throws a SyntaxError.
That's still not correct behavior but better than segfaulting.
To be continued.

Refs: quickjs-ng#567
bnoordhuis added a commit to bnoordhuis/quickjs that referenced this issue Oct 16, 2024
Before this commit it segfaulted, now it throws a SyntaxError.
That's still not correct behavior but better than segfaulting.
To be continued.

Refs: quickjs-ng#567
bnoordhuis added a commit to bnoordhuis/quickjs that referenced this issue Oct 16, 2024
Before this commit it segfaulted, now it throws a SyntaxError.
That's still not correct behavior but better than segfaulting.
To be continued.

Refs: quickjs-ng#567
bnoordhuis added a commit that referenced this issue Oct 16, 2024
Before this commit it segfaulted, now it throws a SyntaxError.
That's still not correct behavior but better than segfaulting.
To be continued.

Includes a small run-test262 fix to handle Windows line endings.

Refs: #567
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants