diff options
author | Shawn Pearce <spearce@spearce.org> | 2014-03-11 17:42:01 -0700 |
---|---|---|
committer | Shawn Pearce <spearce@spearce.org> | 2014-03-12 15:43:38 -0700 |
commit | 77cd1c8cdccffa9b9cef0ec620fbfc91691bab24 (patch) | |
tree | f1885856c9a17a44cf394acd1e1dc4d70770a195 /org.eclipse.jgit/src/org/eclipse | |
parent | 2f1bd3618da20886b12b8132e9307bc61f5fe039 (diff) | |
download | jgit-77cd1c8cdccffa9b9cef0ec620fbfc91691bab24.tar.gz jgit-77cd1c8cdccffa9b9cef0ec620fbfc91691bab24.zip |
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
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java index 14cb528984..6e470c9b2b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectChecker.java @@ -346,15 +346,7 @@ public class ObjectChecker { 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 class ObjectChecker { } } + 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. * |