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

index out of bounds: the len is X but the index is X', src/display/inline.rs:115:21 #702

Open
olivergondza opened this issue Apr 22, 2024 · 7 comments

Comments

@olivergondza
Copy link

Giving this interesting tool a try as an external git diff tool, I have stumbled upon thich crash.

Note this only happen with difft --display inline, works fine with difft.

A description of the issue. A screenshot is often helpful too.

Diffing staged changes with file removal (private code and repo):

thread 'main' panicked at 'index out of bounds: the len is 135 but the index is 135', src/display/inline.rs:115:21
stack backtrace:
   0:     0x6444c126e2a5 - std::backtrace_rs::backtrace::libunwind::trace::h32eb3e08e874dd27
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x6444c126e2a5 - std::backtrace_rs::backtrace::trace_unsynchronized::haa3f451d27bc11a5
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x6444c126e2a5 - std::sys_common::backtrace::_print_fmt::h5b94a01bb4289bb5
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x6444c126e2a5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb070b7fa7e3175df
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x6444c103504e - core::fmt::write::hd5207aebbb9a86e9
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/fmt/mod.rs:1202:17
   5:     0x6444c126a7f5 - std::io::Write::write_fmt::h3bd699bbd129ab8a
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/io/mod.rs:1679:15
   6:     0x6444c126fa13 - std::sys_common::backtrace::_print::h7a21be552fdf58da
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x6444c126fa13 - std::sys_common::backtrace::print::ha85c41fe4dd80b13
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x6444c126fa13 - std::panicking::default_hook::{{closure}}::h04cca40023d0eeca
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:295:22
   9:     0x6444c126f71f - std::panicking::default_hook::haa3ca8c310ed5402
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:314:9
  10:     0x6444c127003c - std::panicking::rust_panic_with_hook::h7b190ce1a948faac
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:698:17
  11:     0x6444c126ff44 - std::panicking::begin_panic_handler::{{closure}}::hbafbfdc3e1b97f68
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:588:13
  12:     0x6444c126e7ac - std::sys_common::backtrace::__rust_end_short_backtrace::hda93e5fef243b4c0
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:138:18
  13:     0x6444c126fc92 - rust_begin_unwind
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5
  14:     0x6444c0f913a3 - core::panicking::panic_fmt::h8d17ca1073d9a733
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14
  15:     0x6444c0f912e2 - core::panicking::panic_bounds_check::h8a412b863558c16a
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:84:5
  16:     0x6444c1087293 - <usize as core::slice::index::SliceIndex<[T]>>::index::h969c72604e95251d
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/slice/index.rs:250:10
  17:     0x6444c1087293 - core::slice::index::<impl core::ops::index::Index<I> for [T]>::index::hc4f5c2a6c59993f8
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/slice/index.rs:18:9
  18:     0x6444c1087293 - <alloc::vec::Vec<T,A> as core::ops::index::Index<I>>::index::h7097a03de58189a7
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/alloc/src/vec/mod.rs:2628:9
  19:     0x6444c1087293 - difft::display::inline::print::h2cb9f2dbb5b971b1
                               at /usr/src/debug/difftastic-git/difftastic-git/src/display/inline.rs:115:21
  20:     0x6444c10bd254 - difft::print_diff_result::hb3ee8d1585cccc72
                               at /usr/src/debug/difftastic-git/difftastic-git/src/main.rs:817:21
  21:     0x6444c10b91fe - difft::main::h5bf17de676bb4b83
                               at /usr/src/debug/difftastic-git/difftastic-git/src/main.rs:318:29
  22:     0x6444c1062d46 - core::ops::function::FnOnce::call_once::h747e67ba6954cd76
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:248:5
  23:     0x6444c1062d46 - std::sys_common::backtrace::__rust_begin_short_backtrace::h5cec4ed45e1eddf6
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/sys_common/backtrace.rs:122:18
  24:     0x6444c10a975c - std::rt::lang_start::{{closure}}::h1987d5ae5c4370c0
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:166:18
  25:     0x6444c12644fa - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hb69be6e0857c6cfb
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:283:13
  26:     0x6444c12644fa - std::panicking::try::do_call::h396dfc441ee9c786
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492:40
  27:     0x6444c12644fa - std::panicking::try::h6cdda972d28b3a4f
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456:19
  28:     0x6444c12644fa - std::panic::catch_unwind::h376039ec264e8ef9
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137:14
  29:     0x6444c12644fa - std::rt::lang_start_internal::{{closure}}::hc94720ca3d4cb727
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:148:48
  30:     0x6444c12644fa - std::panicking::try::do_call::h2422fb95933fa2d5
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:492:40
  31:     0x6444c12644fa - std::panicking::try::h488286b5ec8333ff
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:456:19
  32:     0x6444c12644fa - std::panic::catch_unwind::h81636549836d2a25
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panic.rs:137:14
  33:     0x6444c12644fa - std::rt::lang_start_internal::h6ba1bb743c1e9df9
                               at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/rt.rs:148:20
  34:     0x6444c10bd3f7 - main
  35:     0x73463dd57cd0 - <unknown>
  36:     0x73463dd57d8a - __libc_start_main
  37:     0x6444c0fb03e5 - _start
  38:                0x0 - <unknown>
fatal: external diff died, stopping at filename

The version of difftastic you're using (see difft --version) and your operating system.

Difftastic 0.58.0 (f52ca70 2024-04-09, built with rustc 1.65.0)
Linux arch 6.8.4-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 05 Apr 2024 00:14:23 +0000 x86_64 GNU/Linux

yuja added a commit to yuja/difftastic that referenced this issue Jun 13, 2024
This fixes crash in inline printer, which assumes that hunk lines are within
range. I'm not pretty sure if this assumption holds anytime, but myers_diff
appears not emitting the last blank line, so I made the fall-back path do the
same.

This will hopefully fix Wilfred#702.
yuja added a commit to yuja/difftastic that referenced this issue Jul 22, 2024
myers_diff doesn't emit the last blank line, so I made the fall-back path do
the same.

This was originally intended to fix Wilfred#702, but fixes crash with
sample_files/big_text_hunk_?.txt on 0.59.0. It probably fixes Wilfred#739.
yuja added a commit to yuja/difftastic that referenced this issue Jul 24, 2024
myers_diff doesn't emit the last blank line, so I made the fall-back path do
the same.

This was originally intended to fix Wilfred#702, but fixes crash with
sample_files/big_text_hunk_?.txt on 0.59.0. It probably fixes Wilfred#739.
@king-11
Copy link

king-11 commented Aug 8, 2024

It happens without --display inline as well for me. I was using with git config as below

[diff]
  external = difft
  algorithm = histogram
  submodule = log

rust backtrace

RUST_BACKTRACE=full git diff general.sh
thread 'main' panicked at /home/linuxbrew/.cache/Homebrew/cargo_cache/registry/src/index.crates.io-6f17d22bba15001f/line-numbers-0.3.0/src/lib.rs:105:13:
Offset 3785 is out of bounds for a string of length 3784
stack backtrace:
   0:     0x55a7d0635bb5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8509e56aa833bca9
   1:     0x55a7d0483e1b - core::fmt::write::hf5c910d03bc8dbf1
   2:     0x55a7d0658d2f - std::io::Write::write_fmt::hf7a7b10682047123
   3:     0x55a7d063590e - std::sys_common::backtrace::print::h24e73ad26ef9381c
   4:     0x55a7d06470fd - std::panicking::default_hook::{{closure}}::h15e916a5730b3716
   5:     0x55a7d0646d73 - std::panicking::default_hook::h782a92d1deb58d3a
   6:     0x55a7d06474e6 - std::panicking::rust_panic_with_hook::hbc7722faf2b1f3d1
   7:     0x55a7d0635fa4 - std::panicking::begin_panic_handler::{{closure}}::h50d571706df74b03
   8:     0x55a7d0635dd9 - std::sys_common::backtrace::__rust_end_short_backtrace::h136840a4e5b47d6e
   9:     0x55a7d0647217 - rust_begin_unwind
  10:     0x55a7d03df713 - core::panicking::panic_fmt::h6e32fa4169cba42b
  11:     0x55a7d0562c93 - line_numbers::LinePositions::from_offset::h71b2c9a90f0285e1
  12:     0x55a7d0562ce4 - line_numbers::LinePositions::from_region::h9402a4d149d61917
  13:     0x55a7d04a3b59 - difft::line_parser::change_positions::h91c59ea0f95273a2
  14:     0x55a7d04b0d9a - difft::diff_file_content::hcc13e8418cfa8f01
  15:     0x55a7d04af181 - difft::diff_file::h8f46ca05c3b39472
  16:     0x55a7d04ae1eb - difft::main::h6ca2ddd277b1b6ad
  17:     0x55a7d04cfbb3 - std::sys_common::backtrace::__rust_begin_short_backtrace::h9329a7648fc3fff0
  18:     0x55a7d04fa939 - std::rt::lang_start::{{closure}}::h6ad521249c937cd4
  19:     0x55a7d06220b9 - std::rt::lang_start_internal::h6ce3a22367cf13b2
  20:     0x55a7d04b2d55 - main
  21:     0x7fbcaf84614a - __libc_start_call_main
  22:     0x7fbcaf84620b - __libc_start_main_alias_2
  23:     0x55a7d03fef15 - _start
  24:                0x0 - <unknown>
fatal: external diff died, stopping at general.sh

git diff of the same

diff --git a/general.sh b/general.sh
index 336b28a..6d9a0c2 100644
--- a/general.sh
+++ b/general.sh
@@ -48,8 +48,8 @@ function fnm_install(){
 }
 
 function nodejs_install() {
-  fnm install v18
-  fnm default v18
+  fnm install v20
+  fnm default v20
 }
 
 function pnpm_install(){
@@ -59,8 +59,9 @@ function pnpm_install(){
 
 function python_install() {
   curl -L https://pyenv.run | zsh
-  pyenv install 3.11
-  pyenv global 3.11
+  # install build deps https://github.com/pyenv/pyenv/wiki#suggested-build-environment
+  pyenv install 3.12
+  pyenv global 3.12
 }
 
 function poetry_install() {
@@ -98,11 +99,12 @@ function brew_install_packages() {
     zoxide \
     atuin \
     fzf \
-    teaxyz/pkgs/pkgx
+    pkgxdev/made/pkgx \
+    pipx
 }
 
 function install_tlp_ui() {
-  flatpak install flathub tlpui discord
+  flatpak install flathub tlpui com.discordapp.Discord im.riot.Riot md.obsidian.Obsidian
 }
 
 function nvchad_config() {
@@ -111,11 +113,32 @@ function nvchad_config() {
 }
 
 function kitty_install() {
-  curl -L https://sw.kovidgoyal.net/kitty/installer.sh | sh /dev/stdin
-  ln -sf ~/.local/kitty.app/bin/kitty ~/.local/kitty.app/bin/kitten ~/.local/bin/\
-  cp ~/.local/kitty.app/share/applications/kitty.desktop ~/.local/share/applications/\
-  cp ~/.local/kitty.app/share/applications/kitty-open.desktop ~/.local/share/applications/\
-  sed -i "s|Icon=kitty|Icon=/home/$USER/.local/kitty.app/share/icons/hicolor/256x256/apps/kitty.png|g" ~/.local/share/applications/kitty*.desktop\
-  sed -i "s|Exec=kitty|Exec=/home/$USER/.local/kitty.app/bin/kitty|g" ~/.local/share/applications/kitty*.desktop
+  # Create symbolic links to add kitty and kitten to PATH (assuming ~/.local/bin is install_tlp_ui
+  # your system-wide PATH)
+  ln -sf ~/.local/kitty.app/bin/kitty ~/.local/kitty.app/bin/kitten ~/.local/bin/
+  # Place the kitty.desktop file somewhere it can be found by the OS
+  cp ~/.local/kitty.app/share/applications/kitty.desktop ~/.local/share/applications/
+  # Update the paths to the kitty and its icon in the kitty desktop file(s)
+  sed -i "s|Icon=kitty|Icon=$(readlink -f ~)/.local/kitty.app/share/icons/hicolor/256x256/apps/kitty.png|g" ~/.local/share/applications/kitty*.desktop
+  sed -i "s|Exec=kitty|Exec=$(readlink -f ~)/.local/kitty.app/bin/kitty|g" ~/.local/share/applications/kitty*.desktop
+  # Make xdg-terminal-exec (and hence desktop environments that support it use kitty)
+  echo 'kitty.desktop' > ~/.config/xdg-terminals.list
   cp ~/projects/dotrc/config/kitty ~/.config/kitty
 }
+
+function zed_install() {
+  curl -f https://zed.dev/install.sh | sh
+}
+
+function udev_rules() {
+  sudo curl https://raw.githubusercontent.com/LedgerHQ/udev-rules/master/20-hw1.rules -o /etc/udev/rules.d/20-hw1.rules
+  sudo curl https://raw.githubusercontent.com/trezor/trezor-common/master/udev/51-trezor.rules -o /etc/udev/rules.d/51-trezor.rules
+  sudo curl https://raw.githubusercontent.com/Yubico/libfido2/main/udev/70-u2f.rules -o /etc/udev/rules.d/70-u2f.rules
+}
+
+function docker_access() {
+  sudo groupadd docker;
+  sudo usermod -aG docker $USER;
+  newgrp docker
+  sudo enable --now docker.service containerd.service
+}
able --now docker.service containerd.service
+}

Difftastic 0.60.0 (built with rustc 1.79.0)
Fedora release 39

@provokateurin
Copy link

Same here on Arch Linux with difftastic 0.60.0-1. Only started happening today, until yesterday everything was fine.

@minijackson
Copy link

I have the same issue with Difftastic 0.60.0 for a specific commit, but the issue disappears if I use Difftastic 0.56.1. I haven't tested with other versions than those two.

@autolyticus
Copy link

autolyticus commented Oct 15, 2024

I'm not sure if this is related but seems quite related so I wanted to check before opening a new issue.

When running git diff with difftastic, I'm getting the following stack trace (after outputting the correct diffs for all of the previous files)

thread 'main' panicked at src/display/side_by_side.rs:505:34:
index out of bounds: the len is 5 but the index is 5
stack backtrace:
   0:        0x1042aeb30 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha0d87d7183fc688b
   1:        0x104143b84 - core::fmt::write::hfc4517b0c144e631
   2:        0x1042ae11c - std::io::Write::write_fmt::hafc3b61cd4bc7432
   3:        0x1042ae924 - std::sys_common::backtrace::print::he20b5aebd2593e81
   4:        0x1042c17f0 - std::panicking::default_hook::{{closure}}::ha825d0a487396873
   5:        0x1042c14d4 - std::panicking::default_hook::h858a154b2eadcc95
   6:        0x1042c1dc8 - std::panicking::rust_panic_with_hook::ha327ded1962e21fe
   7:        0x1042aef1c - std::panicking::begin_panic_handler::{{closure}}::h8a13411fce720f32
   8:        0x1042aed74 - std::sys_common::backtrace::__rust_end_short_backtrace::ha2879a5d7250b73a
   9:        0x1042c19dc - _rust_begin_unwind
  10:        0x104a8f3c0 - core::panicking::panic_fmt::he04eea5e05cf1928
  11:        0x104a8f518 - core::panicking::panic_bounds_check::h53b8ed5b86751bd3
  12:        0x1041688bc - difft::display::side_by_side::print::h166c355c399ee29f
  13:        0x104198dcc - difft::print_diff_result::h2a348a73b9072882
  14:        0x104195a1c - difft::main::h6c160af24648ddaa
  15:        0x104173d60 - std::sys_common::backtrace::__rust_begin_short_backtrace::hdd961866bfe6f6ad
  16:        0x10418b9dc - std::rt::lang_start::{{closure}}::h5320221d8cf77115
  17:        0x1042c18e4 - std::panicking::try::h1215cc29895b473a
  18:        0x1042a46d0 - std::rt::lang_start_internal::hcaa2353a52dd5e56
  19:        0x10419912c - _main
fatal: external diff died, stopping at src/stream2energy.bib

@k4lizen
Copy link

k4lizen commented Oct 19, 2024

Same:

thread 'main' panicked at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/difftastic-0.58.0/src/display/side_by_side.rs:509:34:
index out of bounds: the len is 206 but the index is 206
stack backtrace:
   0:     0x5fb5130301cf - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hffecb437d922f988
   1:     0x5fb512df546c - core::fmt::write::hd9a8d7d029f9ea1a
   2:     0x5fb51302ad93 - std::io::Write::write_fmt::h0e1226b2b8d973fe
   3:     0x5fb51302ff54 - std::sys_common::backtrace::print::he907f6ad7eee41cb
   4:     0x5fb513031878 - std::panicking::default_hook::{{closure}}::h3926193b61c9ca9b
   5:     0x5fb51303155c - std::panicking::default_hook::h25ba2457dea68e65
   6:     0x5fb513031d7e - std::panicking::rust_panic_with_hook::h0ad14d90dcf5224f
   7:     0x5fb513031c72 - std::panicking::begin_panic_handler::{{closure}}::h4a1838a06f542647
   8:     0x5fb513030696 - std::sys_common::backtrace::__rust_end_short_backtrace::h77cc4dc3567ca904
   9:     0x5fb5130319b4 - rust_begin_unwind
  10:     0x5fb512d498f5 - core::panicking::panic_fmt::h940d4fd01a4b4fd1
  11:     0x5fb512d49ad2 - core::panicking::panic_bounds_check::h9bb22f08a42e1ac8
  12:     0x5fb512e75d39 - difft::display::side_by_side::print::h1ea6837b816653ab
  13:     0x5fb512e2c558 - difft::print_diff_result::h02866f52f12db36f
  14:     0x5fb512e270f9 - difft::main::h22a23a0f9dc9ab90
  15:     0x5fb512e76743 - std::sys_common::backtrace::__rust_begin_short_backtrace::hde79b91d194773f7
  16:     0x5fb512e6d789 - std::rt::lang_start::{{closure}}::h2fed08fe717f2596
  17:     0x5fb513023295 - std::rt::lang_start_internal::h103c42a9c4e95084
  18:     0x5fb512e2c975 - main
  19:     0x75f408637d6e - <unknown>
  20:     0x75f408637e2a - __libc_start_main
  21:     0x5fb512d6b225 - _start
  22:                0x0 - <unknown>
fatal: external diff died, stopping at tests/loader.test.cpp

Difftastic 0.58.0 (built with rustc 1.78.0)
Not using inline, just via hooked git diff.

@k4lizen
Copy link

k4lizen commented Oct 19, 2024

@autolyticus Seems like this is the issue we have? #688 It's closed though?

@lnicola
Copy link

lnicola commented Nov 4, 2024

I see this in 0.61.0:

image

The strange part is that I can't reproduce it outside of git diff. There are no other modified files. You can try to reproduce in the rust-analyzer repository, at commit 1d65cd466fbd57e84bfff1e2d0d8ac960e780f9b.

bug.zip

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

Successfully merging a pull request may close this issue.

7 participants