SourceMap.findEntry() returns a stale name for a final mapping segment that has no name index
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 新手友好度
- 25/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 停滯
- 技術堆疊
- javascript
- 領域
- tooling
研究方向
使用報告中的 JavaScript 程式碼片段重現問題,然後檢查 SourceMap 在 #parseMap 中對選用 name 欄位的處理。完成標準是:僅包含位置的最終映射會回傳 undefined 名稱,而不是重新使用前一個名稱,並為最小映射範例補上回歸測試涵蓋。
由索引模型根據 Issue 內容生成。
描述
Version
v24.8.0 (present on main; introduced in v15.4.0 / v14.17.1)
Platform
all
Subsystem
module / source maps
What steps will reproduce the bug?
The simplest way to recreate the issue is:
const { SourceMap } = require('node:module');
const sm = new SourceMap({
version: 3, sources: ['a.js'], names: ['foo'], mappings: 'AAAAA,CAAC',
});
console.log(sm.findEntry(0, 1).name); // prints 'foo'
How often does it reproduce? Is there a required condition?
Fails on every run, deterministically.
Required condition: the source map's mappings string must end with a location-only segment (4 fields, no name index), and some earlier segment must have set a name index (i.e. names is non-empty and was referenced before theend). When both hold, findEntry() on that final segment returns the last-seen name instead of undefined
Both conditions are the norm for real minified bundles, so in practice it triggers on essentially every production source map. The minimal repro above (mappings: 'AAAAA,CAAC') is the smallest case that satisfies it.
With --enable-source-maps, the bottom global frame of a stack trace inherits the last-named function instead of being anonymous. Empirically: absent in v14.17.0, appears in v14.17.1 (and v15.4.0), introduced by #36042.
What is the expected behavior? Why is that the expected behavior?
The second segment (CAAC) has only 4 fields and no name index, so findEntry(0, 1).name should be undefined.
What do you see instead?
It returns 'foo', the name from the previous segment.
Additional information
In practice this leads to stack traces being subtly wrong: under --enable-source-maps, the bottom global/anonymous frame is labeled with the last-named function instead of being anonymous. The wrong name is a real identifier from the program, so it looks correct and misleads during debugging rather than being noticed as a defect.
The bug is in SourceMap's #parseMap, it reads the optional 5th (name) VLQ guarded only by !isSeparator(stringCharIterator.peek()). At the end of the mappings string peek() returns '', which is not a separator, so it decodes a phantom VLQ (0), keeps the previous nameIndex, and assigns names[nameIndex] to a segment with no name.
I've implemented a one line fix and I'll open a PR and link it here as soon as it's ready.
- 主要語言
- JavaScript
- 星號
- 122k
- 分支
- 37.4k
- 平均合併
- 4 天 12 小時
- 30 天內合併 PR
- 296
環境準備
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
nodejs/node 的其他 Issue
-
flaky-test test v26.x
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
-
doc
難度 1/5 1 小時以內 新手友好度 90/100
維護者通常 1 天內回覆
-
doc
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
build
難度 1/5 1 小時以內 新手友好度 88/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
nodejs/node#65994 · 2 則留言 · 2 個 reaction ·
維護者通常 1 天內回覆
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 68/100
-
難度 2/5 1-3 小時 新手友好度 74/100
solana-foundation/solana-com#2202 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 92/100
yegor256/copyrights-action#216 ·
-
[BUG] onScroll never refreshes the window container's height after a vertical-only viewport resize未關閉
難度 2/5 1-3 小時 新手友好度 88/100
juliangarnier/anime#1192 ·
-
難度 2/5 1-3 小時 新手友好度 84/100
PedestrianDynamics/pyFDS-Evac#226 ·
維護者通常 1 天內回覆