Reject '.git' as a tree name in ObjectChecker
Using .git as a name in a tree is invalid for most Git repositories. This can confuse clients into thinking there is a submodule or another repository deeper in the tree, which is incorrect. Change-Id: I90a1eaf25d45e91557f3f548b69cdcd8f7cddce1
This commit is contained in:
parent
77cd1c8cdc
commit
09f513cb37
|
@ -1272,6 +1272,19 @@ public void testInvalidTreeNameIsDotDot() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInvalidTreeNameIsGit() {
|
||||||
|
StringBuilder b = new StringBuilder();
|
||||||
|
entry(b, "100644 .git");
|
||||||
|
byte[] data = Constants.encodeASCII(b.toString());
|
||||||
|
try {
|
||||||
|
checker.checkTree(data);
|
||||||
|
fail("incorrectly accepted an invalid tree");
|
||||||
|
} catch (CorruptObjectException e) {
|
||||||
|
assertEquals("invalid name '.git'", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testInvalidTreeTruncatedInName() {
|
public void testInvalidTreeTruncatedInName() {
|
||||||
final StringBuilder b = new StringBuilder();
|
final StringBuilder b = new StringBuilder();
|
||||||
|
|
|
@ -53,6 +53,7 @@
|
||||||
import org.eclipse.jgit.errors.CorruptObjectException;
|
import org.eclipse.jgit.errors.CorruptObjectException;
|
||||||
import org.eclipse.jgit.internal.JGitText;
|
import org.eclipse.jgit.internal.JGitText;
|
||||||
import org.eclipse.jgit.util.MutableInteger;
|
import org.eclipse.jgit.util.MutableInteger;
|
||||||
|
import org.eclipse.jgit.util.RawParseUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verifies that an object is formatted correctly.
|
* Verifies that an object is formatted correctly.
|
||||||
|
@ -372,13 +373,25 @@ private static void checkPathSegment(byte[] raw, int ptr, int end)
|
||||||
if (ptr == end)
|
if (ptr == end)
|
||||||
throw new CorruptObjectException("zero length name");
|
throw new CorruptObjectException("zero length name");
|
||||||
if (raw[ptr] == '.') {
|
if (raw[ptr] == '.') {
|
||||||
int nameLen = end - ptr;
|
switch (end - ptr) {
|
||||||
if (nameLen == 1)
|
case 1:
|
||||||
throw new CorruptObjectException("invalid name '.'");
|
throw new CorruptObjectException("invalid name '.'");
|
||||||
if (nameLen == 2 && raw[ptr + 1] == '.')
|
case 2:
|
||||||
|
if (raw[ptr + 1] == '.')
|
||||||
throw new CorruptObjectException("invalid name '..'");
|
throw new CorruptObjectException("invalid name '..'");
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if (isDotGit(raw, ptr + 1))
|
||||||
|
throw new CorruptObjectException(String.format(
|
||||||
|
"invalid name '%s'",
|
||||||
|
RawParseUtils.decode(raw, ptr, end)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isDotGit(byte[] buf, int p) {
|
||||||
|
return buf[p] == 'g' && buf[p + 1] == 'i' && buf[p + 2] == 't';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check a blob for errors.
|
* Check a blob for errors.
|
||||||
|
|
Loading…
Reference in New Issue