Extract path segment check function in ObjectChecker
Start pulling out the path segment checking. This will be used later to support DirCacheCheckout verification of paths, after folding that logic into this location. Change-Id: I66eaee5c988eb7d425fb7a708ef6f5419ab77348
This commit is contained in:
parent
2f1bd3618d
commit
77cd1c8cdc
|
@ -346,15 +346,7 @@ public void checkTree(final byte[] raw) throws CorruptObjectException {
|
|||
if (c == '/')
|
||||
throw new CorruptObjectException("name contains '/'");
|
||||
}
|
||||
if (thisNameB + 1 == ptr)
|
||||
throw new CorruptObjectException("zero length name");
|
||||
if (raw[thisNameB] == '.') {
|
||||
final int nameLen = (ptr - 1) - thisNameB;
|
||||
if (nameLen == 1)
|
||||
throw new CorruptObjectException("invalid name '.'");
|
||||
if (nameLen == 2 && raw[thisNameB + 1] == '.')
|
||||
throw new CorruptObjectException("invalid name '..'");
|
||||
}
|
||||
checkPathSegment(raw, thisNameB, ptr - 1);
|
||||
if (duplicateName(raw, thisNameB, ptr - 1))
|
||||
throw new CorruptObjectException("duplicate entry names");
|
||||
|
||||
|
@ -375,6 +367,19 @@ public void checkTree(final byte[] raw) throws CorruptObjectException {
|
|||
}
|
||||
}
|
||||
|
||||
private static void checkPathSegment(byte[] raw, int ptr, int end)
|
||||
throws CorruptObjectException {
|
||||
if (ptr == end)
|
||||
throw new CorruptObjectException("zero length name");
|
||||
if (raw[ptr] == '.') {
|
||||
int nameLen = end - ptr;
|
||||
if (nameLen == 1)
|
||||
throw new CorruptObjectException("invalid name '.'");
|
||||
if (nameLen == 2 && raw[ptr + 1] == '.')
|
||||
throw new CorruptObjectException("invalid name '..'");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a blob for errors.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue