From 8ed976661a4f2f0a243f729b3c8fd9a4f9ab2c5a Mon Sep 17 00:00:00 2001 From: Dunqing Date: Tue, 31 Dec 2024 20:00:41 +0800 Subject: [PATCH] fix(codegen): source map builder panicked because it attempted to subtract with overflow in `search_original_line_and_column` (#8185) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See: https://github.com/oxc-project/monitor-oxc/actions/runs/12531534720/job/34949348092 Related: #7926 This line causes panic. https://github.com/oxc-project/oxc/blob/46fc1a8b7d26f1971d1809d68060cb0259dc4b53/crates/oxc_codegen/src/sourcemap_builder.rs#L147-L148 After investigation, I found that the root cause was the code removed in this PR. I don’t understand what the code was used for, but it was obviously wrong. Because `idx` is always smaller than `cap` --- crates/oxc_codegen/src/sourcemap_builder.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/oxc_codegen/src/sourcemap_builder.rs b/crates/oxc_codegen/src/sourcemap_builder.rs index 06fb2a4643e65..08f59ffa533c1 100644 --- a/crates/oxc_codegen/src/sourcemap_builder.rs +++ b/crates/oxc_codegen/src/sourcemap_builder.rs @@ -1,4 +1,4 @@ -use std::{cmp::max, path::Path, sync::Arc}; +use std::{path::Path, sync::Arc}; use nonmax::NonMaxU32; use oxc_index::{Idx, IndexVec}; @@ -235,9 +235,7 @@ impl SourcemapBuilder { let lines = &self.line_offset_tables.lines; let mut idx = self.last_line_lookup as usize; - let cap = idx.saturating_sub(16); - idx = max(idx.saturating_sub(1), cap); - while idx > cap && lines[idx].byte_offset_to_start_of_line > position { + while lines[idx].byte_offset_to_start_of_line > position { idx -= 1; }