aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java44
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheEntry.java11
2 files changed, 55 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java
index 08957d7fb3..0c1baab2b8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java
@@ -47,12 +47,19 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.File;
+import java.text.MessageFormat;
+import org.eclipse.jgit.errors.CorruptObjectException;
+import org.eclipse.jgit.internal.JGitText;
+import org.eclipse.jgit.junit.MockSystemReader;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
+import org.eclipse.jgit.lib.ObjectInserter;
+import org.eclipse.jgit.util.SystemReader;
import org.junit.Test;
public class DirCacheBasicTest extends RepositoryTestCase {
@@ -234,4 +241,41 @@ public class DirCacheBasicTest extends RepositoryTestCase {
final byte[] path = Constants.encode("a");
assertEquals(-1, dc.findEntry(path, path.length));
}
+
+ @Test
+ public void testRejectInvalidWindowsPaths() throws Exception {
+ SystemReader.setInstance(new MockSystemReader() {
+ {
+ setUnix();
+ }
+ });
+
+ String path = "src/con.txt";
+ DirCache dc = db.lockDirCache();
+ DirCacheBuilder b = dc.builder();
+ DirCacheEntry e = new DirCacheEntry(path);
+ e.setFileMode(FileMode.REGULAR_FILE);
+ e.setObjectId(new ObjectInserter.Formatter().idFor(
+ Constants.OBJ_BLOB,
+ Constants.encode(path)));
+ b.add(e);
+ b.commit();
+ db.readDirCache();
+
+ SystemReader.setInstance(new MockSystemReader() {
+ {
+ setWindows();
+ }
+ });
+
+ try {
+ db.readDirCache();
+ fail("should have rejected " + path);
+ } catch (CorruptObjectException err) {
+ assertEquals(MessageFormat.format(JGitText.get().invalidPath, path),
+ err.getMessage());
+ assertNotNull(err.getCause());
+ assertEquals("invalid name 'CON'", err.getCause().getMessage());
+ }
+ }
}
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.
//