Closed wsy2220 closed 1 month ago
I ran into this issue as well, here is a simplified test case that can reproducibly toggle this bug with a line break.
> echo -en "abc" > test1.txt
> echo -en "abc\nabc" > test2.txt
> difft test1.txt test2.txt
thread 'main' panicked at /private/tmp/nix-build-difftastic-0.60.0.drv-0/cargo-vendor-dir/line-numbers-0.3.0/src/lib.rs:105:13:
Offset 8 is out of bounds for a string of length 7
> echo -en "\n" >> test2.txt
> difft test1.txt test2.txt
test2.txt --- Text
1 1 abc
. 2 abc
. 3
> difft --version
Difftastic 0.60.0 (built with rustc 1.80.1)
Thanks for the report, and especially for the small repro. The problem is here:
myers_diff::slice_unique_by_hash
is free to return a different value if it's "equal", which is broken by the equality on StringIgnoringNewline
, so we end up thinking that both lines are abc\n
and try to index assuming the second line is also abc\n
.
This is an annoying problem in general, where we want foo
to be different to foo\n
, but foo
and foo\nbar
should consider the first line to be the same.
I think the correct fix here is to unconditionally split on newlines, discarding them, but highlight whether or not the last line has a trailing newline (in text mode), following git's diff style.
I'm having a similar crash when diffing a YML file, using difft
as the git difftool
.
Version: Difftastic 0.60.0 (built with rustc 1.79.0)
from homebrew
thread 'main' panicked at /Users/brew/Library/Caches/Homebrew/cargo_cache/registry/src/index.crates.io-6f17d22bba15001f/line-numbers-0.3.0/src/lib.rs:105:13:
Offset 17716 is out of bounds for a string of length 17715
stack backtrace:
0: _rust_begin_unwind
1: core::panicking::panic_fmt
2: line_numbers::LinePositions::from_offset
3: line_numbers::LinePositions::from_region
4: difft::line_parser::change_positions
5: difft::diff_file_content
6: difft::diff_file
7: difft::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
fatal: external diff died, stopping at schemas/api.yml
Thanks for reporting a bug! Please include all of the following:
(1) A description of the issue. A screenshot is often helpful too.
(2) A copy of what you're diffing. If you're diffing files, include the before and after files. If you're using difftastic with a VCS repository (e.g. git), include the URL and commit hash. panic.zip
(3) The version of difftastic you're using (see
difft --version
) and your operating system.