public class ObjectChecker
extends java.lang.Object
Verifications made by this class only check that the fields of an object are formatted correctly. The ObjectId checksum of the object is not verified, and connectivity links between objects are also not verified. Its assumed that the caller can provide both of these validations on its own.
Instances of this class are not thread safe, but they may be reused to
perform multiple object validations, calling reset()
between them to
clear the internal state (e.g. getGitsubmodules()
)
Modifier and Type | Class and Description |
---|---|
static class |
ObjectChecker.ErrorType
Potential issues identified by the checker.
|
Modifier and Type | Field and Description |
---|---|
private boolean |
allowInvalidPersonIdent |
static byte[] |
author
Header "author "
|
private MutableInteger |
bufPtr |
static byte[] |
committer
Header "committer "
|
private static byte[] |
dotGitmodules
Path ".gitmodules"
|
static byte[] |
encoding
Header "encoding "
|
private java.util.EnumSet<ObjectChecker.ErrorType> |
errors |
private java.util.List<GitmoduleEntry> |
gitsubmodules |
private boolean |
macosx |
static byte[] |
object
Header "object "
|
static byte[] |
parent
Header "parent "
|
private ObjectIdSet |
skipList |
static byte[] |
tag
Header "tag "
|
static byte[] |
tagger
Header "tagger "
|
private MutableObjectId |
tempId |
static byte[] |
tree
Header "tree "
|
static byte[] |
type
Header "type "
|
private boolean |
windows |
Constructor and Description |
---|
ObjectChecker() |
Modifier and Type | Method and Description |
---|---|
void |
check(AnyObjectId id,
int objType,
byte[] raw)
Check an object for parsing errors.
|
void |
check(int objType,
byte[] raw)
Check an object for parsing errors.
|
void |
checkBlob(byte[] raw)
Check a blob for errors.
|
void |
checkCommit(AnyObjectId id,
byte[] raw)
Check a commit for errors.
|
void |
checkCommit(byte[] raw)
Check a commit for errors.
|
private boolean |
checkId(byte[] raw) |
private void |
checkNotWindowsDevice(byte[] raw,
int ptr,
int end,
AnyObjectId id) |
void |
checkPath(byte[] raw,
int ptr,
int end)
Check tree path entry for validity.
|
void |
checkPath(java.lang.String path)
Check tree path entry for validity.
|
void |
checkPathSegment(byte[] raw,
int ptr,
int end)
Check tree path entry for validity.
|
private void |
checkPathSegment2(byte[] raw,
int ptr,
int end,
AnyObjectId id) |
private void |
checkPersonIdent(byte[] raw,
AnyObjectId id) |
void |
checkTag(AnyObjectId id,
byte[] raw)
Check an annotated tag for errors.
|
void |
checkTag(byte[] raw)
Check an annotated tag for errors.
|
void |
checkTree(AnyObjectId id,
byte[] raw)
Check a canonical formatted tree for errors.
|
void |
checkTree(byte[] raw)
Check a canonical formatted tree for errors.
|
private boolean |
checkTruncatedIgnorableUTF8(byte[] raw,
int ptr,
int end,
AnyObjectId id) |
private static boolean |
duplicateName(byte[] raw,
int thisNamePos,
int thisNameEnd) |
java.util.List<GitmoduleEntry> |
getGitsubmodules()
Get the list of ".gitmodules" files found in the pack.
|
private ObjectId |
idFor(int objType,
byte[] raw) |
private static boolean |
isGit(byte[] buf,
int p) |
private boolean |
isGitmodules(byte[] buf,
int start,
int end,
AnyObjectId id)
Check if the filename contained in buf[start:end] could be read as a
.gitmodules file when checked out to the working directory.
|
private static boolean |
isGitTilde1(byte[] buf,
int p,
int end) |
private static boolean |
isInvalidOnWindows(byte c) |
private boolean |
isMacHFSGit(byte[] raw,
int ptr,
int end,
AnyObjectId id) |
private boolean |
isMacHFSGitmodules(byte[] raw,
int ptr,
int end,
AnyObjectId id) |
private boolean |
isMacHFSPath(byte[] raw,
int ptr,
int end,
byte[] path,
AnyObjectId id) |
private static boolean |
isNormalizedGit(byte[] raw,
int ptr,
int end) |
private boolean |
isNTFSGitmodules(byte[] buf,
int start,
int end) |
private static boolean |
isPositiveDigit(byte b) |
private boolean |
match(byte[] b,
byte[] src) |
private boolean |
matchLowerCase(byte[] b,
int ptr,
byte[] src) |
BlobObjectChecker |
newBlobObjectChecker()
Create a new
BlobObjectChecker . |
private java.lang.String |
normalize(byte[] raw,
int ptr,
int end) |
private void |
report(ObjectChecker.ErrorType err,
AnyObjectId id,
java.lang.String why) |
void |
reset()
Reset the invocation-specific state from this instance.
|
private int |
scanPathSegment(byte[] raw,
int ptr,
int end,
AnyObjectId id) |
ObjectChecker |
setAllowInvalidPersonIdent(boolean allow)
Enable accepting invalid author, committer and tagger identities.
|
ObjectChecker |
setAllowLeadingZeroFileMode(boolean allow)
Enable accepting leading zero mode in tree entries.
|
ObjectChecker |
setIgnore(ObjectChecker.ErrorType id,
boolean ignore)
Add message type to be ignored across all objects.
|
ObjectChecker |
setIgnore(java.util.Set<ObjectChecker.ErrorType> ids)
Configure error types to be ignored across all objects.
|
ObjectChecker |
setSafeForMacOS(boolean mac)
Restrict trees to only names legal on Mac OS X platforms.
|
ObjectChecker |
setSafeForWindows(boolean win)
Restrict trees to only names legal on Windows platforms.
|
ObjectChecker |
setSkipList(ObjectIdSet objects)
Enable accepting specific malformed (but not horribly broken) objects.
|
private static java.lang.String |
toHexString(byte[] raw,
int ptr,
int end) |
private static char |
toLower(byte b) |
public static final byte[] tree
public static final byte[] parent
public static final byte[] author
public static final byte[] committer
public static final byte[] encoding
public static final byte[] object
public static final byte[] type
public static final byte[] tag
public static final byte[] tagger
private static final byte[] dotGitmodules
private final MutableObjectId tempId
private final MutableInteger bufPtr
private java.util.EnumSet<ObjectChecker.ErrorType> errors
private ObjectIdSet skipList
private boolean allowInvalidPersonIdent
private boolean windows
private boolean macosx
private final java.util.List<GitmoduleEntry> gitsubmodules
public ObjectChecker setSkipList(@Nullable ObjectIdSet objects)
objects
- collection of object names known to be broken in a non-fatal
way that should be ignored by the checker.this
public ObjectChecker setIgnore(@Nullable java.util.Set<ObjectChecker.ErrorType> ids)
ids
- error types to ignore. The caller's set is copied.this
public ObjectChecker setIgnore(ObjectChecker.ErrorType id, boolean ignore)
id
- error type to ignore.ignore
- true to ignore this error; false to treat the error as an
error and throw.this
public ObjectChecker setAllowLeadingZeroFileMode(boolean allow)
Some broken Git libraries generated leading zeros in the mode part of tree entries. This is technically incorrect but gracefully allowed by git-core. JGit rejects such trees by default, but may need to accept them on broken histories.
Same as setIgnore(ZERO_PADDED_FILEMODE, allow)
.
allow
- allow leading zero mode.this
.public ObjectChecker setAllowInvalidPersonIdent(boolean allow)
Some broken Git versions/libraries allowed users to create commits and tags with invalid formatting between the name, email and timestamp.
allow
- if true accept invalid person identity strings.this
.public ObjectChecker setSafeForWindows(boolean win)
Also rejects any mixed case forms of reserved names (.git
).
win
- true if Windows name checking should be performed.this
.public ObjectChecker setSafeForMacOS(boolean mac)
Rejects any mixed case forms of reserved names (.git
)
for users working on HFS+ in case-insensitive (default) mode.
mac
- true if Mac OS X name checking should be performed.this
.public void check(int objType, byte[] raw) throws CorruptObjectException
objType
- type of the object. Must be a valid object type code in
Constants
.raw
- the raw data which comprises the object. This should be in the
canonical format (that is the format used to generate the
ObjectId of the object). The array is never modified.CorruptObjectException
- if an error is identified.public void check(@Nullable AnyObjectId id, int objType, byte[] raw) throws CorruptObjectException
id
- identify of the object being checked.objType
- type of the object. Must be a valid object type code in
Constants
.raw
- the raw data which comprises the object. This should be in the
canonical format (that is the format used to generate the
ObjectId of the object). The array is never modified.CorruptObjectException
- if an error is identified.private boolean checkId(byte[] raw)
private void checkPersonIdent(byte[] raw, @Nullable AnyObjectId id) throws CorruptObjectException
CorruptObjectException
public void checkCommit(byte[] raw) throws CorruptObjectException
raw
- the commit data. The array is never modified.CorruptObjectException
- if any error was detected.public void checkCommit(@Nullable AnyObjectId id, byte[] raw) throws CorruptObjectException
id
- identity of the object being checked.raw
- the commit data. The array is never modified.CorruptObjectException
- if any error was detected.public void checkTag(byte[] raw) throws CorruptObjectException
raw
- the tag data. The array is never modified.CorruptObjectException
- if any error was detected.public void checkTag(@Nullable AnyObjectId id, byte[] raw) throws CorruptObjectException
id
- identity of the object being checked.raw
- the tag data. The array is never modified.CorruptObjectException
- if any error was detected.private static boolean duplicateName(byte[] raw, int thisNamePos, int thisNameEnd)
public void checkTree(byte[] raw) throws CorruptObjectException
raw
- the raw tree data. The array is never modified.CorruptObjectException
- if any error was detected.public void checkTree(@Nullable AnyObjectId id, byte[] raw) throws CorruptObjectException
id
- identity of the object being checked.raw
- the raw tree data. The array is never modified.CorruptObjectException
- if any error was detected.private int scanPathSegment(byte[] raw, int ptr, int end, @Nullable AnyObjectId id) throws CorruptObjectException
CorruptObjectException
private void report(@NonNull ObjectChecker.ErrorType err, @Nullable AnyObjectId id, java.lang.String why) throws CorruptObjectException
CorruptObjectException
public void checkPath(java.lang.String path) throws CorruptObjectException
Unlike checkPathSegment(byte[], int, int)
, this version scans a
multi-directory path string such as "src/main.c"
.
path
- path string to scan.CorruptObjectException
- path is invalid.public void checkPath(byte[] raw, int ptr, int end) throws CorruptObjectException
Unlike checkPathSegment(byte[], int, int)
, this version scans a
multi-directory path string such as "src/main.c"
.
raw
- buffer to scan.ptr
- offset to first byte of the name.end
- offset to one past last byte of name.CorruptObjectException
- path is invalid.public void checkPathSegment(byte[] raw, int ptr, int end) throws CorruptObjectException
raw
- buffer to scan.ptr
- offset to first byte of the name.end
- offset to one past last byte of name.CorruptObjectException
- name is invalid.private void checkPathSegment2(byte[] raw, int ptr, int end, @Nullable AnyObjectId id) throws CorruptObjectException
CorruptObjectException
private boolean isMacHFSPath(byte[] raw, int ptr, int end, byte[] path, @Nullable AnyObjectId id) throws CorruptObjectException
CorruptObjectException
private boolean isMacHFSGit(byte[] raw, int ptr, int end, @Nullable AnyObjectId id) throws CorruptObjectException
CorruptObjectException
private boolean isMacHFSGitmodules(byte[] raw, int ptr, int end, @Nullable AnyObjectId id) throws CorruptObjectException
CorruptObjectException
private boolean checkTruncatedIgnorableUTF8(byte[] raw, int ptr, int end, @Nullable AnyObjectId id) throws CorruptObjectException
CorruptObjectException
private static java.lang.String toHexString(byte[] raw, int ptr, int end)
private void checkNotWindowsDevice(byte[] raw, int ptr, int end, @Nullable AnyObjectId id) throws CorruptObjectException
CorruptObjectException
private static boolean isInvalidOnWindows(byte c)
private static boolean isGit(byte[] buf, int p)
private boolean isGitmodules(byte[] buf, int start, int end, @Nullable AnyObjectId id) throws CorruptObjectException
buf
- byte array to decodestart
- position where a supposed filename is startingend
- position where a supposed filename is endingid
- object id for error reportingCorruptObjectException
private boolean matchLowerCase(byte[] b, int ptr, byte[] src)
private boolean isNTFSGitmodules(byte[] buf, int start, int end)
private static boolean isGitTilde1(byte[] buf, int p, int end)
private static boolean isNormalizedGit(byte[] raw, int ptr, int end)
private boolean match(byte[] b, byte[] src)
private static char toLower(byte b)
private static boolean isPositiveDigit(byte b)
@Nullable public BlobObjectChecker newBlobObjectChecker()
BlobObjectChecker
.public void checkBlob(byte[] raw) throws CorruptObjectException
This may not be called from PackParser in some cases. Use
newBlobObjectChecker()
instead.
raw
- the blob data. The array is never modified.CorruptObjectException
- if any error was detected.private java.lang.String normalize(byte[] raw, int ptr, int end)
public java.util.List<GitmoduleEntry> getGitsubmodules()
public void reset()
getGitsubmodules()
)
Configurations like errors to filter, skip lists or the specified O.S.
(set via setSafeForMacOS(boolean)
or
setSafeForWindows(boolean)
) are NOT cleared.