ag553 / google-diff-match-patch

Automatically exported from code.google.com/p/google-diff-match-patch
Apache License 2.0
0 stars 0 forks source link

Substring length check missing in C# implementation #88

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
There's an issue with the diff_CleanupMerge function around line 1280.  It 
attempts to do a .Substring with the start index being outside the range of the 
string.

I changed the following line:

          } else if (diffs[pointer].text.StartsWith(diffs[pointer + 1].text,
              StringComparison.Ordinal)) {

to: 

          } else if (diffs[pointer].text.StartsWith(diffs[pointer + 1].text,
              StringComparison.Ordinal) &&
              diffs[pointer + 1].text.Length < diffs[pointer].text.Length) {

to prevent this call from happening:

            diffs[pointer].text =
                diffs[pointer].text.Substring(diffs[pointer + 1].text.Length)
                + diffs[pointer + 1].text;

Now for all I know, the change I've made could invalidate the patch (I don't 
really understand what I'm changing, but I needed to get rid of the exception 
that was being thrown at all costs), but I'm guessing based on comments and 
that it seems to have a "changes = true;" line in there that it's just doing 
some optimizations on patch size and failing.

Original issue reported on code.google.com by jrho...@redpointgames.com.au on 27 May 2013 at 1:12