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
Panic index out of bounds in side_by_side.rs on go.sum #688
Comments
Have similar error on the same difftastic version (using macOS 14.4.1 on M2 MacBook). My backtrace looks like:
|
FYI, the crash is still here with |
I've just bisected the problem to this commit: 3be8e80. To trigger this issue you only need to have enough words to cross the To reproduce the issue just use those files and run difft against them: $ curl -o bad_left 'https://gist.githubusercontent.com/JonathanxD/450595f7a25cca43076ca5083ee73e33/raw/85ac535c67fb40c30006e5622b015c387c06cbe4/bad_left'
$ curl -o bad_right 'https://gist.githubusercontent.com/JonathanxD/450595f7a25cca43076ca5083ee73e33/raw/85ac535c67fb40c30006e5622b015c387c06cbe4/bad_right'
$ difft bad_left bad_right And I just found out that the order does not really matter (you can swap left and right and it still panics). After further investigation, and looking around the code a bit, I found out that this line should actually be: index d54731d59..562d327d1 100644
--- a/src/line_parser.rs
+++ b/src/line_parser.rs
@@ -152,7 +152,7 @@ pub(crate) fn change_positions(lhs_src: &str, rhs_src: &str) -> Vec<MatchedPos>
// have a very large number of words, don't diff
// individual words.
if lhs_words.len() > MAX_WORDS_IN_LINE || rhs_words.len() > MAX_WORDS_IN_LINE {
- for lhs_pos in lhs_lp.from_region(lhs_offset, lhs_offset + lhs_part.len()) {
+ for lhs_pos in lhs_lp.from_region(lhs_offset, lhs_offset + line_len_in_bytes(&lhs_part)) {
mps.push(MatchedPos {
kind: MatchKind::NovelWord {
highlight: TokenKind::Atom(AtomKind::Normal), I ran all the tests with this patch and every seems fine. |
Fixes Wilfred#688, fixes Wilfred#694, fixes Wilfred#682, and fixes Wilfred#681.
Fixes Wilfred#688, fixes Wilfred#694 and fixes Wilfred#682.
Fixes Wilfred#688, fixes Wilfred#694 and fixes Wilfred#681.
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.
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.
While running
git show --ext-diff
I noticed the following at the end of the diff:And sure enough, the diff output was not complete for the
go.sum
file and there should also be other files after it.I reproduced the issue by running
difft go.sum.old.txt go.sum.new.txt
on the following two files: go.sum.old.txt and go.sum.new.txtHere is the output with complete stacktrace:
My difft version:
By the way, great tool! 💪
The text was updated successfully, but these errors were encountered: