From 8d36fa343c689d1334ddc1f722c153203c1d13f7 Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Tue, 25 Nov 2014 11:43:32 -0800 Subject: DirCache: Refuse to read files with invalid paths If the DirCache contains a path that is known to be invalid, refuse to read the DirCache into memory. This avoids confusing errors later if an invalid path read from the DirCache were to be passed into a new DirCacheEntry constructor. Change-Id: Ic033d81e23a5fbd554cc4dff80a232504562ffa8 --- .../src/org/eclipse/jgit/dircache/DirCacheEntry.java | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java') diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java index b6b376ae8a..eef2e6d3c3 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java @@ -56,6 +56,7 @@ import java.security.MessageDigest; import java.text.MessageFormat; import java.util.Arrays; +import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Constants; @@ -189,6 +190,16 @@ public class DirCacheEntry { md.update((byte) 0); } + try { + DirCacheCheckout.checkValidPath(toString(path)); + } catch (InvalidPathException e) { + CorruptObjectException p = + new CorruptObjectException(e.getMessage()); + if (e.getCause() != null) + p.initCause(e.getCause()); + throw p; + } + // Index records are padded out to the next 8 byte alignment // for historical reasons related to how C Git read the files. // -- cgit v1.2.3