mitsuhiko / similar

A high level diffing library for rust based on diffs
https://insta.rs/similar
Apache License 2.0
949 stars 31 forks source link

LCS crash: `attempt to subtract with overflow` #57

Closed madsmtm closed 8 months ago

madsmtm commented 8 months ago

Hey, I ran a fuzzer on my project using the LCS algorithm, and found that it crashes in the following situation:

use similar::algorithms::{lcs, Capture};
let mut d = Capture::new();
lcs::diff(&mut d, &[0], 0..1, &[0, 0], 0..2).unwrap();

Line it crashes on: https://github.com/mitsuhiko/similar/blob/2b31f65445df9093ba007ca5a5ae6a71b899d491/src/algorithms/lcs.rs#L83