Browse Source

Fix integer overflow in DiffFormatter when context is set to large int

In original code, if you call the DiffFormatter's setContext() method
with Integer.MAX_VALUE (to get full-context diffs) the format() method
will get into an infinite loop.

Bug: 382680
Change-Id: I804e82cde9b84b8ff232a20fb5cbde04478315e7
Signed-off-by: Ilmars Poikans <ilmars@delibero.lv>
stable-3.7
Ilmars Poikans 10 years ago
parent
commit
786ad999cd
  1. 8
      org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java

8
org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java

@ -737,10 +737,10 @@ public class DiffFormatter {
final int endIdx = findCombinedEnd(edits, curIdx);
final Edit endEdit = edits.get(endIdx);
int aCur = Math.max(0, curEdit.getBeginA() - context);
int bCur = Math.max(0, curEdit.getBeginB() - context);
final int aEnd = Math.min(a.size(), endEdit.getEndA() + context);
final int bEnd = Math.min(b.size(), endEdit.getEndB() + context);
int aCur = (int) Math.max(0, (long) curEdit.getBeginA() - context);
int bCur = (int) Math.max(0, (long) curEdit.getBeginB() - context);
final int aEnd = (int) Math.min(a.size(), (long) endEdit.getEndA() + context);
final int bEnd = (int) Math.min(b.size(), (long) endEdit.getEndB() + context);
writeHunkHeader(aCur, aEnd, bCur, bEnd);

Loading…
Cancel
Save