module: don't read a phantom name on the last mapping segment#63801
Open
dusanstanojeviccs wants to merge 1 commit into
Open
module: don't read a phantom name on the last mapping segment#63801dusanstanojeviccs wants to merge 1 commit into
dusanstanojeviccs wants to merge 1 commit into
Conversation
SourceMap#parseMap reads the optional name VLQ guarded only by !isSeparator(peek()). At the end of the mappings string peek() returns '', which is not a separator, so the parser decodes a phantom VLQ (0), keeps the previous nameIndex, and assigns names[nameIndex] to a segment that has no name field. SourceMap.findEntry() then returns a stale name, which surfaces as the wrong function name on the bottom global frame of --enable-source-maps stack traces. Guard the name read with hasNext() so the phantom field is not read at end of string. A trailing segment that genuinely carries a name still has characters left to read, so it is unaffected. Refs: nodejs#63795 Signed-off-by: Dusan Stanojevic <dusan.stanojevic.cs@gmail.com>
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.
Fixes a stale-name bug in
SourceMap's mappings parser. The optional name field is read with!isSeparator(peek())and nohasNext()guard, so at end-of-string the parser reads a phantom VLQ (0) and stamps the previousnameIndex's name onto a segment that has none.User-visible effect: with
--enable-source-maps, the bottom global frame of a stack trace inherits the last-named function name. Introduced by #36042 (first released in v15.4.0 / v14.17.1); confirmed absent in v14.17.0.Includes a regression test covering both a nameless trailing segment and a legitimately-named one.
Fixes: #63795