sergi / go-diff

Diff, match and patch text in Go
MIT License
1.81k stars 207 forks source link

runtime error: index out of range while processing diff #102

Closed qzaidi closed 4 years ago

qzaidi commented 4 years ago

Hi, I am not using this library directly, but via another package (go-git). I have found that in certain cases, there is panic on this line

https://github.com/sergi/go-diff/blob/da645544ed44df016359bd4c0e3dc60ee3a0da43/diffmatchpatch/diff.go#L452

At the time of panic, the values are

1 iteration ago: i=179592 r=55295 len(chars)=190439 len(lineArray)=58902 next iteration: i=179595 r=65533 len(chars)=190439 len(lineArray)=58902

so clearly lineArray[r] seems to exceed the allocated memory. I still have to understand the code to understand why this happens, but any ideas would be appreciated. Interestingly, in both cases, the diff being processed when panic was unicode.

r-pai commented 4 years ago

Duplicate of #89

sergi commented 4 years ago

Please follow the discussion in #89