Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: "index out of bounds: the len is 20 but the index is 20" #694

Closed
Krinkle opened this issue Apr 5, 2024 · 4 comments
Closed

Error: "index out of bounds: the len is 20 but the index is 20" #694

Krinkle opened this issue Apr 5, 2024 · 4 comments

Comments

@Krinkle
Copy link

Krinkle commented Apr 5, 2024

Description

After several useful diffs, the output stops with this error. It's unclear to me whether this is a trailing error, or whether there would have been more output without this error. I worry the latter.

<cut>

thread 'main' panicked at src/display/side_by_side.rs:488:58:
index out of bounds: the len is 281 but the index is 281
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread '<unnamed>' panicked at src/main.rs:284:38:
Receiver should be connected: SendError { .. }

Test case

cd /tmp
git clone https://github.com/jquery/blog.jquery.com-theme blog && cd blog/ && git checkout -q 6710984735eb && cd ../
git clone --depth 1 -b v4.9.14 https://github.com/jquery/jquery-wp-content
difft blog/jquery jquery-wp-content/themes/jquery

Version

macOS 13. Using Homebrew to install difft. Details at https://formulae.brew.sh/formula/difftastic and https://github.com/Homebrew/homebrew-core/blob/b5b224ebe92c94a69806ca1c3b90b9fbe7739e11/Formula/d/difftastic.rb.

$ difft --version
Difftastic 0.57.0 (built with rustc 1.77.1)
@Krinkle
Copy link
Author

Krinkle commented Apr 5, 2024

RUST_BACKTRACE=1 RUST_BACKTRACE=full difft blog/jquery/ jquery-wp-content/themes/jquery/
thread 'main' panicked at src/display/side_by_side.rs:488:58:
index out of bounds: the len is 281 but the index is 281
stack backtrace:
   0:        0x102e85ae4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h6e13e5c1f43a2491
   1:        0x102c9625c - core::fmt::write::ha2c1956860377338
   2:        0x102e8bf80 - std::io::Write::write_fmt::ha4b28c52ceab65a6
   3:        0x102e858d8 - std::sys_common::backtrace::print::h479f79ccc1585c96
   4:        0x102e9b09c - std::panicking::default_hook::{{closure}}::h3432bfbcced8e86b
   5:        0x102e9adb8 - std::panicking::default_hook::h0a224004d0f52354
   6:        0x102e9b4ec - std::panicking::rust_panic_with_hook::h0a46a8ecc3586611
   7:        0x102e8606c - std::panicking::begin_panic_handler::{{closure}}::hafb87b136ffd6947
   8:        0x102e85d28 - std::sys_common::backtrace::__rust_end_short_backtrace::h35ccaf072a47767f
   9:        0x102e9b288 - _rust_begin_unwind
  10:        0x103666b78 - core::panicking::panic_fmt::h11c5b4b324cc1c7c
  11:        0x103666cd0 - core::panicking::panic_bounds_check::hc32fa3cf74afc646
  12:        0x102d158f8 - difft::display::side_by_side::print::h89ef2d4f6f4c33bb
  13:        0x102cc7c14 - difft::print_diff_result::hacca16cc5ae65f90
  14:        0x102cc0488 - std::panicking::try::h05eefcd74c88f1da
  15:        0x102cb6a40 - std::thread::scoped::scope::he2f7263efb18026e
  16:        0x102cc48dc - difft::main::hc24eec628cb9e943
  17:        0x102ccecc0 - std::sys_common::backtrace::__rust_begin_short_backtrace::hb7290b100c936322
  18:        0x102cea768 - std::rt::lang_start::{{closure}}::h4506ff0be546a910
  19:        0x102e9b190 - std::panicking::try::h339e50e350ac9bf3
  20:        0x102e87bc0 - std::rt::lang_start_internal::ha7854c9dc8ed1474
  21:        0x102cc7f9c - _main
thread '<unnamed>' panicked at src/main.rs:284:38:
Receiver should be connected: SendError { .. }
stack backtrace:
   0:        0x102e85ae4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h6e13e5c1f43a2491
   1:        0x102c9625c - core::fmt::write::ha2c1956860377338
   2:        0x102e8bf80 - std::io::Write::write_fmt::ha4b28c52ceab65a6
   3:        0x102e858d8 - std::sys_common::backtrace::print::h479f79ccc1585c96
   4:        0x102e9b09c - std::panicking::default_hook::{{closure}}::h3432bfbcced8e86b
   5:        0x102e9adb8 - std::panicking::default_hook::h0a224004d0f52354
   6:        0x102e9b4ec - std::panicking::rust_panic_with_hook::h0a46a8ecc3586611
   7:        0x102e8606c - std::panicking::begin_panic_handler::{{closure}}::hafb87b136ffd6947
   8:        0x102e85d28 - std::sys_common::backtrace::__rust_end_short_backtrace::h35ccaf072a47767f
   9:        0x102e9b288 - _rust_begin_unwind
  10:        0x103666b78 - core::panicking::panic_fmt::h11c5b4b324cc1c7c
  11:        0x103666ff0 - core::result::unwrap_failed::h24fe7f07a22cd818
  12:        0x102ccec5c - std::sys_common::backtrace::__rust_begin_short_backtrace::h270b367dbe1c5372
  13:        0x102cd0524 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hb2772cc423f7dcb4
  14:        0x102ea7dd8 - std::sys::pal::unix::thread::Thread::new::thread_start::he51aaef8aee5f8eb
  15:        0x19ae0ffa8 - __pthread_joiner_wake

@Krinkle
Copy link
Author

Krinkle commented Apr 5, 2024

I can reproduce this with just the two license.txt files (the last file it diff'ed before the panic). Including when using --display=inline. I added this because there was oddly no right-hand side to the diff. Thinking it might make a difference in this mode.

If this has the same root cause, then this should narrow it down considerably. The trace does look a bit different.

$ RUST_BACKTRACE=1 RUST_BACKTRACE=full difft --display=inline -- blog/jquery/license.txt jquery-wp-content/themes/jquery/license.txt 
jquery/license.txt --- 1/2 --- Text
1                GNU GENERAL PUBLIC LICENSE
2                   Version 2, June 1991
3    
<cut>
279    
280                 END OF TERMS AND CONDITIONS
281    
thread 'main' panicked at src/display/inline.rs:115:38:
index out of bounds: the len is 281 but the index is 281
stack backtrace:
   0:        0x100d21ae4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h6e13e5c1f43a2491
   1:        0x100b3225c - core::fmt::write::ha2c1956860377338
   2:        0x100d27f80 - std::io::Write::write_fmt::ha4b28c52ceab65a6
   3:        0x100d218d8 - std::sys_common::backtrace::print::h479f79ccc1585c96
   4:        0x100d3709c - std::panicking::default_hook::{{closure}}::h3432bfbcced8e86b
   5:        0x100d36db8 - std::panicking::default_hook::h0a224004d0f52354
   6:        0x100d374ec - std::panicking::rust_panic_with_hook::h0a46a8ecc3586611
   7:        0x100d2206c - std::panicking::begin_panic_handler::{{closure}}::hafb87b136ffd6947
   8:        0x100d21d28 - std::sys_common::backtrace::__rust_end_short_backtrace::h35ccaf072a47767f
   9:        0x100d37288 - _rust_begin_unwind
  10:        0x101502b78 - core::panicking::panic_fmt::h11c5b4b324cc1c7c
  11:        0x101502cd0 - core::panicking::panic_bounds_check::hc32fa3cf74afc646
  12:        0x100b5a4c8 - difft::display::inline::print::h2ee45b9e0c3ddfb0
  13:        0x100b63db4 - difft::print_diff_result::hacca16cc5ae65f90
  14:        0x100b6086c - difft::main::hc24eec628cb9e943
  15:        0x100b6acc0 - std::sys_common::backtrace::__rust_begin_short_backtrace::hb7290b100c936322
  16:        0x100b86768 - std::rt::lang_start::{{closure}}::h4506ff0be546a910
  17:        0x100d37190 - std::panicking::try::h339e50e350ac9bf3
  18:        0x100d23bc0 - std::rt::lang_start_internal::ha7854c9dc8ed1474
  19:        0x100b63f9c - _main

JonathanxD added a commit to JonathanxD/difftastic that referenced this issue Apr 5, 2024
JonathanxD added a commit to JonathanxD/difftastic that referenced this issue Apr 5, 2024
JonathanxD added a commit to JonathanxD/difftastic that referenced this issue Apr 5, 2024
JonathanxD added a commit to JonathanxD/difftastic that referenced this issue Apr 6, 2024
Fixes Wilfred#688, fixes Wilfred#694, fixes Wilfred#682 and fixes Wilfred#681.

This works around the fact that `str::lines` does not include last
newline character.
This means that `"a\n".lines().count() == "a".lines().count()`, which
breaks the 1:1 assumption made by display implementations.
JonathanxD added a commit to JonathanxD/difftastic that referenced this issue Apr 6, 2024
Fixes Wilfred#688, fixes Wilfred#694, fixes Wilfred#682 and fixes Wilfred#681.

This works around the fact that `str::lines` does not include last
newline character.
This means that `"a\n".lines().count() == "a".lines().count()`, which
breaks the 1:1 assumption made by display implementations.
@jenrik
Copy link

jenrik commented Apr 19, 2024

I have encountered the same issue and made this small reproducer:

file a.yaml:

---
asdf: |-
  foo:
    foo:
      bar: b
      foo: a

  foo:

file b.yaml:

---
asdf: |-
  foo:
    foo:
      foo: a

  foo:

command used to provoke the error: difft a.yaml b.yaml

@Wilfred
Copy link
Owner

Wilfred commented May 12, 2024

Merging into #688, thanks for the report!

@Wilfred Wilfred closed this as completed May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants