summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlmars Poikans <ilmars@delibero.lv>2014-12-01 00:14:50 +0200
committerIlmars Poikans <ilmars@delibero.lv>2014-12-01 00:14:50 +0200
commit786ad999cdd48a952ef6f270e3e76040259e6f67 (patch)
tree69f1ab4bee5e94e7c6c8bc063b1b0cc3945b4b7a
parentc9a5fdb3cd92d5774aa7041b9fc9fc579dc26edc (diff)
downloadjgit-786ad999cdd48a952ef6f270e3e76040259e6f67.tar.gz
jgit-786ad999cdd48a952ef6f270e3e76040259e6f67.zip
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>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java8
1 files changed, 4 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
index a4b6ab1278..d339d6a65a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
+++ b/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);