devserver: fix index out of bounds on windows (#21657)

### What does this PR do?

Fixes #21638

Code was assuming there would always be >= 2 lines but this was not true
and causing a crash.
This commit is contained in:
Zack Radisic
2025-08-06 18:55:37 -07:00
committed by GitHub
parent 3652008b0d
commit 4deeadd53a

View File

@@ -124,9 +124,21 @@ pub fn runWithBody(ctx: *ErrorReportRequest, body: []const u8, r: AnyResponse) !
}
const result: *const SourceMapStore.GetResult = &(gop.value_ptr.* orelse continue);
// When before the first generated line, remap to the HMR runtime
// When before the first generated line, remap to the HMR runtime.
//
// Reminder that the HMR runtime is *not* sourcemapped. And appears
// first in the bundle. This means that the mappings usually looks like
// this:
//
// AAAA;;;;;;;;;;;ICGA,qCAA4B;
// ^ ^ generated_mappings[1], actual code
// ^
// ^ generated_mappings[0], we always start it with this
//
// So we can know if the frame is inside the HMR runtime if
// `frame.position.line < generated_mappings[1].lines`.
const generated_mappings = result.mappings.generated();
if (frame.position.line.oneBased() < generated_mappings[1].lines) {
if (generated_mappings.len <= 1 or frame.position.line.zeroBased() < generated_mappings[1].lines) {
frame.source_url = .init(runtime_name); // matches value in source map
frame.position = .invalid;
continue;