From 3d17be85bac795d7da3caa15b5b09adb46052584 Mon Sep 17 00:00:00 2001 From: Christian Halstrick Date: Mon, 26 Jan 2015 11:12:27 +0100 Subject: Handle invalid tree extensions In case the index contains wrong tree extensions don't throw a ArrayIndexOutOfBounds exception but revalidate the tree extension. It happened that the git index written by Git for Windows contained valid (means entryCount>0) tree extensions for pathes which are not existing in the index. Native git handles this inconsistency silently but JGit was crashing with a ArrayIndexOutOfBounds exception. Teach JGit to better recognize such cases and revalidate such extensions. It's hard to write a test because JGit doesn't write such extensions. It only reads, validates and makes use of them. But the bug tells how to create such situations. Bug: 457152 Change-Id: Id3ffd7dc7ae1c55674d88bf1b43953234fe0b68d --- org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'org.eclipse.jgit/src/org/eclipse') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java index 5acde4385e..30932e8274 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheTree.java @@ -425,7 +425,7 @@ public class DirCacheTree { */ void validate(final DirCacheEntry[] cache, final int cCnt, int cIdx, final int pathOff) { - if (entrySpan >= 0) { + if (entrySpan >= 0 && cIdx + entrySpan <= cCnt) { // If we are valid, our children are also valid. // We have no need to validate them. // -- cgit v1.2.3