Fix panic in compact sourcemap caused by negative VLQ values

The panic was caused by VLQ decoding producing negative accumulated values
(e.g., original_line = -17) which were then passed to addScalar(), causing
an assertion failure in Ordinal.fromZeroBased().

Root cause: VLQ sourcemap format uses delta encoding, so negative deltas
can result in negative accumulated line/column values.

Fix: Added validation to return null for mappings with any negative
line/column values instead of attempting to create invalid Ordinals.

Stack trace showed:
- bun.OrdinalT(c_int).fromZeroBased (int=-17)
- bun.OrdinalT(c_int).addScalar (ord=start, inc=-17)
- sourcemap.sourcemap.MappingsData.find

Test /workspace/bun/test/js/node/test/parallel/test-string-decoder.js
now passes without panicking.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2025-08-13 08:11:37 +00:00
parent 5133cce905
commit bafa1f2efe

View File

@@ -868,6 +868,13 @@ pub const MappingsData = union(enum) {
.list => |*list| return list.find(line, column),
.compact => |compact| {
if (compact.findMapping(line, column)) |sm| {
// Validate that values are non-negative before using addScalar
// VLQ decoding can result in negative accumulated values due to negative deltas
if (sm.generated_line < 0 or sm.generated_column < 0 or
sm.original_line < 0 or sm.original_column < 0) {
return null; // Invalid mapping data - return null instead of panicking
}
return Mapping{
.generated = .{
.lines = bun.Ordinal.start.addScalar(sm.generated_line),