Wilfred / difftastic

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

"index out of bounds" error, panic in side_by_side.rs #705

Closed timmattison closed 1 month ago

timmattison commented 2 months ago

TL;DR - steps to reproduce at the bottom. I'm running this version:

Difftastic 0.57.0 (built with rustc 1.77.1)

I'm diffing two files with no command-line options. One file has 547,616 lines the other has 546,196 lines.

When I run this command:

difft a.txt b.txt

I get this error after 546,196 lines:

thread 'main' panicked at src/display/side_by_side.rs:488:58:
index out of bounds: the len is 547616 but the index is 547616
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Running with RUST_BACKTRACE=1 gives me this:

thread 'main' panicked at src/display/side_by_side.rs:488:58:
index out of bounds: the len is 547616 but the index is 547616
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: difft::display::side_by_side::print
   4: difft::print_diff_result
   5: difft::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Running with RUST_BACKTRACE=full gives me this:

thread 'main' panicked at src/display/side_by_side.rs:488:58:
index out of bounds: the len is 547616 but the index is 547616
stack backtrace:
   0:        0x1026747ac - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h6e13e5c1f43a2491
   1:        0x102484f24 - core::fmt::write::ha2c1956860377338
   2:        0x10267ac48 - std::io::Write::write_fmt::ha4b28c52ceab65a6
   3:        0x1026745a0 - std::sys_common::backtrace::print::h479f79ccc1585c96
   4:        0x102689d64 - std::panicking::default_hook::{{closure}}::h3432bfbcced8e86b
   5:        0x102689a80 - std::panicking::default_hook::h0a224004d0f52354
   6:        0x10268a1b4 - std::panicking::rust_panic_with_hook::h0a46a8ecc3586611
   7:        0x102674d34 - std::panicking::begin_panic_handler::{{closure}}::hafb87b136ffd6947
   8:        0x1026749f0 - std::sys_common::backtrace::__rust_end_short_backtrace::h35ccaf072a47767f
   9:        0x102689f50 - _rust_begin_unwind
  10:        0x102e56b04 - core::panicking::panic_fmt::h11c5b4b324cc1c7c
  11:        0x102e56c5c - core::panicking::panic_bounds_check::hc32fa3cf74afc646
  12:        0x1025045c0 - difft::display::side_by_side::print::h89ef2d4f6f4c33bb
  13:        0x1024b68dc - difft::print_diff_result::hacca16cc5ae65f90
  14:        0x1024b3534 - difft::main::hc24eec628cb9e943
  15:        0x1024bd988 - std::sys_common::backtrace::__rust_begin_short_backtrace::hb7290b100c936322
  16:        0x1024d9430 - std::rt::lang_start::{{closure}}::h4506ff0be546a910
  17:        0x102689e58 - std::panicking::try::h339e50e350ac9bf3
  18:        0x102676888 - std::rt::lang_start_internal::ha7854c9dc8ed1474
  19:        0x1024b6c64 - _main

Working comparison:

shuf -i 82237159591344-154195313684130 --random-source=/dev/urandom -n 100 > 100.txt
shuf -i 82237159591344-154195313684130 --random-source=/dev/urandom -n 500 > 500.txt
difft 100.txt 500.txt

To reproduce:

Adding one more line makes it fail:

shuf -i 82237159591344-154195313684130 --random-source=/dev/urandom -n 501 > 501.txt
difft 100.txt 501.txt

And this is the new output:

thread 'main' panicked at src/display/side_by_side.rs:488:58:
index out of bounds: the len is 100 but the index is 100
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
drewbitt commented 2 months ago

Dupe of several others. Thanks for reproduction.

72750
Wilfred commented 1 month ago

Merging into #688, thanks for the report!