Skip to content

Commit

Permalink
fix(codegen): source map builder panicked because it attempted to sub…
Browse files Browse the repository at this point in the history
…tract with overflow in `search_original_line_and_column` (#8185)

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`
  • Loading branch information
Dunqing authored Dec 31, 2024
1 parent 56b7f13 commit 8ed9766
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions crates/oxc_codegen/src/sourcemap_builder.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 8ed9766

Please sign in to comment.