Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
module: don't read a phantom name on the last mapping segment
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: #63795
Signed-off-by: Dusan Stanojevic <dusan.stanojevic.cs@gmail.com>
  • Loading branch information
dusanstanojeviccs committed Jun 8, 2026
commit 69543f48458d8439e3da9e737dbce1b8060cfb12
3 changes: 2 additions & 1 deletion lib/internal/source_map/source_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,8 @@ class SourceMap {
sourceColumnNumber += decodeVLQ(stringCharIterator);

let name;
if (!isSeparator(stringCharIterator.peek())) {
if (stringCharIterator.hasNext() &&
!isSeparator(stringCharIterator.peek())) {
nameIndex += decodeVLQ(stringCharIterator);
name = map.names?.[nameIndex];
}
Expand Down
34 changes: 34 additions & 0 deletions test/parallel/test-source-map-trailing-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';
require('../common');
const assert = require('assert');
const { SourceMap } = require('node:module');

// Refs: https://github.com/nodejs/node/issues/63795

// A mapping whose final segment has 4 fields (no name index) must not
// inherit the previous segment's name.
{
const sm = new SourceMap({
version: 3,
sources: ['a.js'],
names: ['foo'],
mappings: 'AAAAA,CAAC',
});

assert.strictEqual(sm.findEntry(0, 0).name, 'foo');
assert.strictEqual(sm.findEntry(0, 1).name, undefined);
}

// A mapping whose final segment legitimately carries a name index must still
// resolve it: the end-of-string guard must not suppress a real trailing name.
{
const sm = new SourceMap({
version: 3,
sources: ['a.js'],
names: ['foo'],
mappings: 'AAAA,CAAAA',
});

assert.strictEqual(sm.findEntry(0, 0).name, undefined);
assert.strictEqual(sm.findEntry(0, 1).name, 'foo');
}
Loading