Wilfred / difftastic

a structural diff that understands syntax 🟥🟩
https://difftastic.wilfred.me.uk/
MIT License
21.14k stars 346 forks source link

Panic when diffing a Gradle file #766

Closed tomwhoiscontrary closed 1 month ago

tomwhoiscontrary commented 2 months ago

Diffing a small change to a bulid.gradle file gets a panic:

$ difft build.baseline.gradle.txt build.changed.gradle.txt 
thread 'main' panicked at /home/tomwhoiscontrary/.cargo/registry/src/index.crates.io-6f17d22bba15001f/line-numbers-0.3.0/src/lib.rs:105:13:
Offset 1505 is out of bounds for a string of length 1504
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$ RUST_BACKTRACE=full difft build.baseline.gradle.txt build.changed.gradle.txt 
thread 'main' panicked at /home/tomwhoiscontrary/.cargo/registry/src/index.crates.io-6f17d22bba15001f/line-numbers-0.3.0/src/lib.rs:105:13:
Offset 1505 is out of bounds for a string of length 1504
stack backtrace:
   0:     0x5fde0988761b - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h1b9dad2a88e955ff
   1:     0x5fde096c661b - core::fmt::write::h4b5a1270214bc4a7
   2:     0x5fde09881e53 - std::io::Write::write_fmt::hd04af345a50c312d
   3:     0x5fde09888a1a - std::panicking::default_hook::{{closure}}::h96ab15e9936be7ed
   4:     0x5fde09888667 - std::panicking::default_hook::h3cacb9c27561ad33
   5:     0x5fde09889079 - std::panicking::rust_panic_with_hook::hfe205f6954b2c97b
   6:     0x5fde09888f87 - std::panicking::begin_panic_handler::{{closure}}::h6cb44b3a50f28c44
   7:     0x5fde09887ae9 - std::sys::backtrace::__rust_end_short_backtrace::hf1c1f2a92799bb0e
   8:     0x5fde09888c14 - rust_begin_unwind
   9:     0x5fde0961bd73 - core::panicking::panic_fmt::h3d8fc78294164da7
  10:     0x5fde097a03e3 - line_numbers::LinePositions::from_offset::h19422187a3a91f5e
  11:     0x5fde097a0434 - line_numbers::LinePositions::from_region::hf8df7cab0e1fab78
  12:     0x5fde0970adb9 - difft::line_parser::change_positions::h3d0350d2111c90fb
  13:     0x5fde0972f9d0 - difft::diff_file_content::h11a5bc571819fd23
  14:     0x5fde0972e32b - difft::diff_file::h2a47ea77ba4adb1f
  15:     0x5fde0972d447 - difft::main::hb2a3518d26a3d62a
  16:     0x5fde0971aa33 - std::sys::backtrace::__rust_begin_short_backtrace::h97a7bda8b18ed0e1
  17:     0x5fde0973e909 - std::rt::lang_start::{{closure}}::h55bf7464f8cd40cd
  18:     0x5fde09879c05 - std::rt::lang_start_internal::h5e7c81cecd7f0954
  19:     0x5fde09731ba5 - main
  20:     0x7b79b7029d90 - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  21:     0x7b79b7029e40 - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:392:3
  22:     0x5fde096378d5 - _start
  23:                0x0 - <unknown>

With these files:

build.changed.gradle.txt build.baseline.gradle.txt

$ difft --version
Difftastic 0.60.0 (built with rustc 1.81.0)
Wilfred commented 1 month ago

Duplicate of #755, thanks for the report :)