bastiantonn / 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

java ArrayIndexOutOfBoundsException: 2 on diff_main #39

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm getting an issue by calling the function diff_main, with the text in the 
file first_arg in first arg and the text in the file second_arg in second arg, 
it displays me the stack trace :

java.lang.ArrayIndexOutOfBoundsException: 2
        diff_match_patch.diff_bisect(diff_match_patch.java:374)
        diff_match_patch.diff_compute(diff_match_patch.java:296)
        diff_match_patch.diff_main(diff_match_patch.java:198)
        diff_match_patch.diff_compute(diff_match_patch.java:274)
        diff_match_patch.diff_main(diff_match_patch.java:198)
        diff_match_patch.diff_main(diff_match_patch.java:153)
        diff_match_patch.diff_main(diff_match_patch.java:132)

Thanks in advance

Francis

Original issue reported on code.google.com by fran6las...@hotmail.fr on 21 Jan 2011 at 9:25

Attachments:

GoogleCodeExporter commented 9 years ago
Confirmed.  This is a classic example of a binary bomb, two algorithms which 
individually are completely benign but which when combined produce unexpected 
behaviour.  In this case it is the linear space refinement interacting with the 
line-mode speedup.

As a temporary fix, call diff_main with a third argument of 'false' which 
deactivates the line-mode speedup:
  diff_main(text1, text2, false)

Affects all language versions.  I'll push out an emergency patch shortly.  But 
in the longer term I need to take a closer look at whether the line-mode 
speedup is worthwhile (Issue 38).

Original comment by neil.fra...@gmail.com on 21 Jan 2011 at 7:46

GoogleCodeExporter commented 9 years ago
A new package has been uploaded to Google Code and to Subversion.  This fixes 
the issue, refactors the code to be cleaner and adds a unit test to check for 
this.

I've also been able to characterize the bug in greater detail.  The Java, 
Python and C# versions would throw an out of bounds exception.  The C++ and 
(unreleased) Objective C versions would quietly encounter a buffer overflow, 
but would usually appear to succeed.  The JavaScript version handled this bug 
without issues.  And there was no bug in Lua since it doesn't have the linemode 
speedup.

The bug was triggered when two lines were diffed that were both greater than 
100 characters and neither contained a line break.  There were certainly other 
inputs that would trigger the bug, but that one is the simplest.

Thanks for reporting this!

Original comment by neil.fra...@gmail.com on 22 Jan 2011 at 1:36

GoogleCodeExporter commented 9 years ago
Very fast fix, thanks.

Francis.

Original comment by fran6las...@hotmail.fr on 24 Jan 2011 at 8:09