Compare commits

...

1 Commits

Author SHA1 Message Date
Claude Bot
87f7377373 Fix integer overflow in longestCommonPath
Fixed an integer underflow bug in longestCommonPathGeneric that occurred
when index == min_length && index == 0. The code would do index -= 1,
causing index to underflow to maxInt(usize), which then caused an integer
overflow panic when accessing array elements.

The fix adds a check to ensure index > 0 before decrementing, and adds
a bounds check before accessing input[0][index] to prevent out-of-bounds
access.

This bug was reported on Windows in a BuildCommand scenario, but is
difficult to reproduce through integration tests as it requires very
specific path conditions (9+ paths with min_length == 0).

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-22 02:03:10 +00:00

View File

@@ -242,8 +242,8 @@ pub fn longestCommonPathGeneric(input: []const []const u8, comptime platform: Pl
}
}
}
if (index == min_length) index -= 1;
if (@call(bun.callmod_inline, isPathSeparator, .{input[0][index]})) {
if (index == min_length and index > 0) index -= 1;
if (index < input[0].len and @call(bun.callmod_inline, isPathSeparator, .{input[0][index]})) {
last_common_separator = index;
}
}