Conversation
A module whose top-level binding is declared with `var`/`function` and then re-declared by a namespace import (`import * as name`) is accepted, although ECMA-262 makes duplicate top-level module binding names an early SyntaxError. The scanner already records `SCANNER_TYPE_ERR_REDECLARED` for the imported name and the named-import clause rejects it, but the namespace-import branch of `parser_parse_import_statement()` never performed that check. The name is then referenced from the module scope while absent from `module_p->imports_p`, and during linking `ecma_module_resolve_export()` falls through to `ecma_module_resolve_import()`. That function walks `imports_p` with an unbounded `while (true)` loop whose only terminating guard is a `JERRY_ASSERT` (compiled out in release builds), so it dereferences `import_node_p->module_names_p` after `import_node_p` has reached NULL. The namespace-import path now performs the same redeclaration check that `parser_module_parse_import_clause()` already uses, so the duplicate binding is rejected as a SyntaxError while the module is parsed. As defence in depth, `ecma_module_resolve_import()` now stops when it runs out of import nodes and returns `false` (resolution failure) instead of relying on an assertion; the caller already handles an unsuccessful resolution. Fixes jerryscript-project#5292 JerryScript-DCO-1.0-Signed-off-by: PGZXB <pgzxb@qq.com>
This branch has not been deployed
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.
A module whose top-level binding is declared with
var/functionand thenre-declared by a namespace import (
import * as name) is accepted, althoughECMA-262 makes duplicate top-level module binding names an early SyntaxError.
The scanner already records
SCANNER_TYPE_ERR_REDECLAREDfor the imported nameand the named-import clause rejects it, but the namespace-import branch of
parser_parse_import_statement()never performed that check. The name is thenreferenced from the module scope while absent from
module_p->imports_p, andduring linking
ecma_module_resolve_export()falls through toecma_module_resolve_import(). That function walksimports_pwith anunbounded
while (true)loop whose only terminating guard is aJERRY_ASSERT(compiled out in release builds), so it dereferences
import_node_p->module_names_pafterimport_node_phas reached NULL:The namespace-import path now performs the same redeclaration check that
parser_module_parse_import_clause()already uses, so the duplicate binding isrejected as a SyntaxError while the module is parsed. As defence in depth,
ecma_module_resolve_import()now stops when it runs out of import nodes andreturns
false(resolution failure) instead of relying on an assertion; thecaller already handles an unsuccessful resolution.
Verified with the shipped CLI in module mode (
jerry -m):SUMMARY: AddressSanitizer: SEGV ... in ecma_module_resolve_importUnhandled exception: SyntaxError, no sanitizer reportimport * as z from "./m1.mjs") still links andevaluates cleanly, so existing module programs are unaffected
Fixes #5292
JerryScript-DCO-1.0-Signed-off-by: PGZXB pgzxb@qq.com