Skip to content

Commit 18a0efb

Browse files
committed
Fix division by zero in FASTA region reader
Guard against corrupt .fai with line_bases=0 or line_width=0.
1 parent 7ce6be3 commit 18a0efb

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src-tauri/src/commands.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,10 @@ fn read_fasta_region(fasta_path: &str, chrom: &str, start: u64, end: u64) -> Res
499499
let actual_end = end.min(seq_len);
500500
let window_len = (actual_end - start) as usize;
501501

502+
if line_bases == 0 || line_width == 0 {
503+
return Err(format!("Invalid FASTA index for '{}': line_bases={}, line_width={}", chrom, line_bases, line_width));
504+
}
505+
502506
let start_line = start / line_bases;
503507
let start_byte = offset + start_line * line_width + (start % line_bases);
504508
let end_line = actual_end / line_bases;

0 commit comments

Comments
 (0)