From bafa1f2efe4070d68c14b285466784ec8064df7e Mon Sep 17 00:00:00 2001 From: Claude Bot Date: Wed, 13 Aug 2025 08:11:37 +0000 Subject: [PATCH] Fix panic in compact sourcemap caused by negative VLQ values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/sourcemap/sourcemap.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/sourcemap/sourcemap.zig b/src/sourcemap/sourcemap.zig index 84076711bd..a95b46d621 100644 --- a/src/sourcemap/sourcemap.zig +++ b/src/sourcemap/sourcemap.zig @@ -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),