Browse Source

Always ignore case when forbidding .git in ObjectChecker

The component name ".GIT" inside a tree entry could confuse a
case insensitive filesystem into looking at a submodule and
not a directory entry.

Disallow any case permutations of ".git" to prevent this
confusion from entering a repository and showing up at a
later date on a case insensitive system.

Change-Id: Iaa3f768931d0d5764bf07ac5f6f3ff2b1fdda01b
stable-3.4
Shawn Pearce 10 years ago committed by Matthias Sohn
parent
commit
07612a610f
  1. 17
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java
  2. 10
      org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java

17
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ObjectCheckerTest.java

@ -1295,26 +1295,11 @@ public class ObjectCheckerTest {
}
@Test
public void testInvalidTreeNameIsMixedCaseGitWindows() {
public void testInvalidTreeNameIsMixedCaseGit() {
StringBuilder b = new StringBuilder();
entry(b, "100644 .GiT");
byte[] data = Constants.encodeASCII(b.toString());
try {
checker.setSafeForWindows(true);
checker.checkTree(data);
fail("incorrectly accepted an invalid tree");
} catch (CorruptObjectException e) {
assertEquals("invalid name '.GiT'", e.getMessage());
}
}
@Test
public void testInvalidTreeNameIsMixedCaseGitMacOS() {
StringBuilder b = new StringBuilder();
entry(b, "100644 .GiT");
byte[] data = Constants.encodeASCII(b.toString());
try {
checker.setSafeForMacOS(true);
checker.checkTree(data);
fail("incorrectly accepted an invalid tree");
} catch (CorruptObjectException e) {

10
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java

@ -540,12 +540,10 @@ public class ObjectChecker {
return 1 <= c && c <= 31;
}
private boolean isDotGit(byte[] buf, int p) {
if (windows || macosx)
return toLower(buf[p]) == 'g'
&& toLower(buf[p + 1]) == 'i'
&& toLower(buf[p + 2]) == 't';
return buf[p] == 'g' && buf[p + 1] == 'i' && buf[p + 2] == 't';
private static boolean isDotGit(byte[] buf, int p) {
return toLower(buf[p]) == 'g'
&& toLower(buf[p + 1]) == 'i'
&& toLower(buf[p + 2]) == 't';
}
private static char toLower(byte b) {

Loading…
Cancel
Save