-
Notifications
You must be signed in to change notification settings - Fork 219
Index out of range panic in DiffCharsToLines on large JSON diff #89
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
Comments
Hi, I've also met this issue while iterating on large repositories (wanting to analyze diffs) with github.com/src-d/go-git |
@clafoutis42 no sorry I haven't figured that one out. Eventually I switched to https://github.com/libgit2/git2go |
We encountered the same problem at source{d}, and @mcuadros is currently debugging it and looking for the fix. |
I limited the scope of the problem with one file (64k lines), it contains serveral language from Thai Script to Arabic. This is the fixture: https://gist.github.com/mcuadros/6369103d4838a9042613596ee212f32c#file-fixture-go And the code to replicate the issues is: package main
import (
"io/ioutil"
"log"
"github.com/sergi/go-diff/diffmatchpatch"
)
func main() {
sNew, err := ioutil.ReadFile("/tmp/dst")
if err != nil {
panic(err)
}
dmp := diffmatchpatch.New()
t1, t2, t := dmp.DiffLinesToChars("", string(sNew))
diffs := dmp.DiffMain(t1, t2, false)
diffs = dmp.DiffCharsToLines(diffs, t)
for _, diff := range diffs {
log.Println(diff.Type, diff.Text)
}
} |
Anyone know if @sergi is still active? I was hoping to submit a PR for this fix (unless someone else is or has a fix). I'm running into this now consistently :( |
We are not working on it right now, so if you want to fix it go ahead, this
will be great.
…On Thu, May 23, 2019, 4:00 PM Corefracture ***@***.***> wrote:
Anyone know if @sergi <https://github.com/sergi> is still active? I was
hoping to submit a PR for this fix (unless someone else is or has a fix).
I'm running into this now consistently :(
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#89?email_source=notifications&email_token=AAMAB6WPPNVXUMIWMRRQZXLPW2PPXA5CNFSM4EL5UEO2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWCKBNY#issuecomment-495231159>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAMAB6WSH6DOU75MZSVQ7QLPW2PPXANCNFSM4EL5UEOQ>
.
|
I too faced the issue and had a look on why the issue is occurring. I was able to know what the issue but for the fix its not that easy as you need to know most of the logic. Its better people who wrote it can fix it better than me. Please have a look on this example.
Output :
Issue: In go-diff the lineArray index is stored in the rune array ( In diff.go , diffLinesToRunesMunge() function ). I hope , I had put some light on this issue. :) Thank You.... P@i |
Hi folks, Sorry about the silence. I'm back and I'll be looking into this issue soon, but I'd definitely appreciate it if one of you wants to contribute a PR to it. |
Hi All, I have done a fix for this issue and with my testing its working. Issue: The fix is in the last two commits of my go-diff fork. I have also changed the test cases and added test to check the a huge line diff testcase . Branch: https://github.com/r-pai/go-diff/ Any comments before I create a PR. Thanks |
Hi all, tl;dr I have a solution for this issue, but it requires lots of changes and also increase memory consumption by a factor of 2-4. Long analysis: As I see it, there are two possible ways to solve it:
This explanation sounds much more complicated than the real changes... BTW, it might be possible to choose option 1 without code duplication (at least not human-written code duplication...) by generating the two versions of the function automatically. |
For comparison, here are the benchmark results on both current master and my branch (running on my Windows 10 Intel i7-6700HQ laptop): My branch: It seems like some of the operations are actually faster, but memory allocations are much higher. |
We just ran into this in the Go language server ( |
Hi @stamblerre, I have a potential fix for this that I plan to apply later today if all tests pass. |
Awesome, thank you for the quick update! |
Thank you for the quick fix on this, @sergi! Do you plan to tag a new release with this fix? |
…e diffs (#425) Adds a test case to verify the fix. The test data is taken from sergi/go-diff#89 data.txt --------- Co-authored-by: Lucas Shadler <[email protected]>
… add extra test for rune conversion. Fixes sergi#89.
I've encountered this issue while using https://github.com/src-d/go-git, but the bug is easily reproducible with the code snippet below and the JSON file in attachment.
Output:
data.txt
The text was updated successfully, but these errors were encountered: