Compare commits

...

1 Commits

Author SHA1 Message Date
Claude
eef3a438e0 Fix potential panic from negative source_index in sourcemap lookups
Add missing negative value checks before @intCast operations on source_index
in Mapping.Lookup functions. While the parser validates source_index >= 0 during
parsing, defensive programming requires checking for negative values before
casting i32 to usize to prevent panics in edge cases or corrupted data.

Changes:
- displaySourceURLIfNeeded: Check source_index < 0 before array access
- getSourceCode: Add checks before two @intCast operations

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-29 03:48:36 +00:00

View File

@@ -231,7 +231,7 @@ pub const Lookup = struct {
// See doc comment on `external_source_names`
if (source_map.external_source_names.len == 0)
return null;
if (lookup.mapping.source_index >= source_map.external_source_names.len)
if (lookup.mapping.source_index < 0 or lookup.mapping.source_index >= source_map.external_source_names.len)
return null;
const name = source_map.external_source_names[@intCast(lookup.mapping.source_index)];
@@ -271,7 +271,7 @@ pub const Lookup = struct {
// They are decompressed on demand.
if (source_map.is_standalone_module_graph) {
const serialized = source_map.standaloneModuleGraphData();
if (index >= source_map.external_source_names.len)
if (index < 0 or index >= source_map.external_source_names.len)
return null;
const code = serialized.sourceFileContents(@intCast(index));
@@ -279,6 +279,9 @@ pub const Lookup = struct {
return bun.jsc.ZigString.Slice.fromUTF8NeverFree(code orelse return null);
}
if (index < 0 or index >= source_map.external_source_names.len)
return null;
if (provider.getSourceMap(
base_filename,
source_map.underlying_provider.load_hint,
@@ -287,9 +290,6 @@ pub const Lookup = struct {
if (parsed.source_contents) |contents|
break :bytes contents;
if (index >= source_map.external_source_names.len)
return null;
const name = source_map.external_source_names[@intCast(index)];
var buf: bun.PathBuffer = undefined;