Fix crash on cyclic re-export of an imported binding#1583
Merged
Conversation
littledivy
force-pushed
the
fix/cyclic-reexport-crash
branch
3 times, most recently
from
July 17, 2026 15:02
f59b4bc to
c711c78
Compare
saghul
reviewed
Jul 17, 2026
| @@ -1,10 +1,3 @@ | |||
| /*--- | |||
Contributor
There was a problem hiding this comment.
While you're here, can you please rename the test to bugXXX.js ?
Contributor
Author
There was a problem hiding this comment.
Renamed to bug567.js
littledivy
force-pushed
the
fix/cyclic-reexport-crash
branch
from
July 17, 2026 15:11
c711c78 to
ddc13c5
Compare
saghul
approved these changes
Jul 17, 2026
Re-exporting an imported binding (`import { x } from "m"; export { x }`)
from a module that participates in an import cycle could dereference a NULL
JSVarRef and crash. While a peer in the cycle is still unlinked its import
slot is NULL, and both js_build_module_ns() and js_inner_module_linking()
used that slot directly.
Resolve such a binding by following the import alias to its source module
(js_get_local_export_var_ref). When the binding is genuinely unresolvable,
e.g. a pure re-export cycle with no concrete binding, throw a SyntaxError
instead of crashing.
This makes a valid cyclic re-export evaluate correctly, so the
test_cyclic_import.js case that previously threw a stopgap SyntaxError now
passes. Fixes quickjs-ng#567.
littledivy
force-pushed
the
fix/cyclic-reexport-crash
branch
from
July 17, 2026 15:44
ddc13c5 to
51f6e8e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re-exporting an imported binding (
import { x } from "m"; export { x }) from a module in an import cycle could dereference a NULLJSVarRefand crash (SIGSEGV). While a peer in the cycle is still unlinked its import slot is NULL, and bothjs_build_module_ns()andjs_inner_module_linking()used that slot directly.Minimal reproducer (segfaults on master):
js_get_local_export_var_ref()resolves such a binding by following the import alias to its source module, reusingjs_resolve_export1'sJSResolveStatevisited-set to detect re-export cycles. When the binding is genuinely unresolvable (a pure re-export cycle with no concrete binding) it throws aSyntaxErrorinstead of crashing.SyntaxErrorSyntaxErrorSyntaxErrorThis also lets the
test_cyclic_import.jscase that carried aFIXME(bnoordhuis)work as intended. Fixes #567.Disclaimer: This is an AI-assisted patch from the v8x project.