@ -254,25 +254,32 @@ public class ObjectChecker {
int ptr = 0 ;
if ( ( ptr = match ( raw , ptr , tree ) ) < 0 )
throw new CorruptObjectException ( "no tree header" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectNotreeHeader ) ;
if ( ( ptr = id ( raw , ptr ) ) < 0 | | raw [ ptr + + ] ! = '\n' )
throw new CorruptObjectException ( "invalid tree" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectInvalidTree ) ;
while ( match ( raw , ptr , parent ) > = 0 ) {
ptr + = parent . length ;
if ( ( ptr = id ( raw , ptr ) ) < 0 | | raw [ ptr + + ] ! = '\n' )
throw new CorruptObjectException ( "invalid parent" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectInvalidParent ) ;
}
if ( ( ptr = match ( raw , ptr , author ) ) < 0 )
throw new CorruptObjectException ( "no author" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectNoAuthor ) ;
if ( ( ptr = personIdent ( raw , ptr ) ) < 0 | | raw [ ptr + + ] ! = '\n' )
throw new CorruptObjectException ( "invalid author" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectInvalidAuthor ) ;
if ( ( ptr = match ( raw , ptr , committer ) ) < 0 )
throw new CorruptObjectException ( "no committer" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectNoCommitter ) ;
if ( ( ptr = personIdent ( raw , ptr ) ) < 0 | | raw [ ptr + + ] ! = '\n' )
throw new CorruptObjectException ( "invalid committer" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectInvalidCommitter ) ;
}
/ * *
@ -287,21 +294,26 @@ public class ObjectChecker {
int ptr = 0 ;
if ( ( ptr = match ( raw , ptr , object ) ) < 0 )
throw new CorruptObjectException ( "no object header" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectNoObjectHeader ) ;
if ( ( ptr = id ( raw , ptr ) ) < 0 | | raw [ ptr + + ] ! = '\n' )
throw new CorruptObjectException ( "invalid object" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectInvalidObject ) ;
if ( ( ptr = match ( raw , ptr , type ) ) < 0 )
throw new CorruptObjectException ( "no type header" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectNoTypeHeader ) ;
ptr = nextLF ( raw , ptr ) ;
if ( ( ptr = match ( raw , ptr , tag ) ) < 0 )
throw new CorruptObjectException ( "no tag header" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectNoTagHeader ) ;
ptr = nextLF ( raw , ptr ) ;
if ( ( ptr = match ( raw , ptr , tagger ) ) > 0 ) {
if ( ( ptr = personIdent ( raw , ptr ) ) < 0 | | raw [ ptr + + ] ! = '\n' )
throw new CorruptObjectException ( "invalid tagger" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectInvalidTagger ) ;
}
}
@ -382,37 +394,46 @@ public class ObjectChecker {
int thisMode = 0 ;
for ( ; ; ) {
if ( ptr = = sz )
throw new CorruptObjectException ( "truncated in mode" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectTruncatedInMode ) ;
final byte c = raw [ ptr + + ] ;
if ( ' ' = = c )
break ;
if ( c < '0' | | c > '7' )
throw new CorruptObjectException ( "invalid mode character" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectInvalidModeChar ) ;
if ( thisMode = = 0 & & c = = '0' & & ! allowZeroMode )
throw new CorruptObjectException ( "mode starts with '0'" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectInvalidModeStartsZero ) ;
thisMode < < = 3 ;
thisMode + = c - '0' ;
}
if ( FileMode . fromBits ( thisMode ) . getObjectType ( ) = = Constants . OBJ_BAD )
throw new CorruptObjectException ( "invalid mode " + thisMode ) ;
throw new CorruptObjectException ( MessageFormat . format (
JGitText . get ( ) . corruptObjectInvalidMode2 ,
Integer . valueOf ( thisMode ) ) ) ;
final int thisNameB = ptr ;
ptr = scanPathSegment ( raw , ptr , sz ) ;
if ( ptr = = sz | | raw [ ptr ] ! = 0 )
throw new CorruptObjectException ( "truncated in name" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectTruncatedInName ) ;
checkPathSegment2 ( raw , thisNameB , ptr ) ;
if ( normalized ! = null ) {
if ( ! normalized . add ( normalize ( raw , thisNameB , ptr ) ) )
throw new CorruptObjectException ( "duplicate entry names" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectDuplicateEntryNames ) ;
} else if ( duplicateName ( raw , thisNameB , ptr ) )
throw new CorruptObjectException ( "duplicate entry names" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectDuplicateEntryNames ) ;
if ( lastNameB ! = 0 ) {
final int cmp = pathCompare ( raw , lastNameB , lastNameE ,
lastMode , thisNameB , ptr , thisMode ) ;
if ( cmp > 0 )
throw new CorruptObjectException ( "incorrectly sorted" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectIncorrectSorting ) ;
}
lastNameB = thisNameB ;
@ -421,7 +442,8 @@ public class ObjectChecker {
ptr + = 1 + Constants . OBJECT_ID_LENGTH ;
if ( ptr > sz )
throw new CorruptObjectException ( "truncated in object id" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectTruncatedInObjectId ) ;
}
}
@ -432,13 +454,16 @@ public class ObjectChecker {
if ( c = = 0 )
return ptr ;
if ( c = = '/' )
throw new CorruptObjectException ( "name contains '/'" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectNameContainsSlash ) ;
if ( windows & & isInvalidOnWindows ( c ) ) {
if ( c > 31 )
throw new CorruptObjectException ( String . format (
"name contains '%c'" , c ) ) ;
JGitText . get ( ) . corruptObjectNameContainsChar ,
Byte . valueOf ( c ) ) ) ;
throw new CorruptObjectException ( String . format (
"name contains byte 0x%x" , c & 0xff ) ) ;
JGitText . get ( ) . corruptObjectNameContainsByte ,
Integer . valueOf ( c & 0xff ) ) ) ;
}
}
return ptr ;
@ -496,49 +521,55 @@ public class ObjectChecker {
throws CorruptObjectException {
int e = scanPathSegment ( raw , ptr , end ) ;
if ( e < end & & raw [ e ] = = 0 )
throw new CorruptObjectException ( "name contains byte 0x00" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectNameContainsNullByte ) ;
checkPathSegment2 ( raw , ptr , end ) ;
}
private void checkPathSegment2 ( byte [ ] raw , int ptr , int end )
throws CorruptObjectException {
if ( ptr = = end )
throw new CorruptObjectException ( "zero length name" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectNameZeroLength ) ;
if ( raw [ ptr ] = = '.' ) {
switch ( end - ptr ) {
case 1 :
throw new CorruptObjectException ( "invalid name '.'" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectNameDot ) ;
case 2 :
if ( raw [ ptr + 1 ] = = '.' )
throw new CorruptObjectException ( "invalid name '..'" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectNameDotDot ) ;
break ;
case 4 :
if ( isGit ( raw , ptr + 1 ) )
throw new CorruptObjectException ( String . format (
"invalid name '%s'" ,
JGitText . get ( ) . corruptObjectInvalidName ,
RawParseUtils . decode ( raw , ptr , end ) ) ) ;
break ;
default :
if ( end - ptr > 4 & & isNormalizedGit ( raw , ptr + 1 , end ) )
throw new CorruptObjectException ( String . format (
"invalid name '%s'" ,
JGitText . get ( ) . corruptObjectInvalidName ,
RawParseUtils . decode ( raw , ptr , end ) ) ) ;
}
} else if ( isGitTilde1 ( raw , ptr , end ) ) {
throw new CorruptObjectException ( String . format ( "invalid name '%s'" ,
throw new CorruptObjectException ( String . format (
JGitText . get ( ) . corruptObjectInvalidName ,
RawParseUtils . decode ( raw , ptr , end ) ) ) ;
}
if ( macosx & & isMacHFSGit ( raw , ptr , end ) )
throw new CorruptObjectException ( String . format (
"invalid name '%s' contains ignorable Unicode characters" ,
JGitText . get ( ) . corruptObjectInvalidNameIgnorableUnicode ,
RawParseUtils . decode ( raw , ptr , end ) ) ) ;
if ( windows ) {
// Windows ignores space and dot at end of file name.
if ( raw [ end - 1 ] = = ' ' | | raw [ end - 1 ] = = '.' )
throw new CorruptObjectException ( "invalid name ends with '"
+ ( ( char ) raw [ end - 1 ] ) + "'" ) ;
throw new CorruptObjectException ( String . format (
JGitText . get ( ) . corruptObjectInvalidNameEnd ,
Character . valueOf ( ( ( char ) raw [ end - 1 ] ) ) ) ) ;
if ( end - ptr > = 3 )
checkNotWindowsDevice ( raw , ptr , end ) ;
}
@ -615,7 +646,7 @@ public class ObjectChecker {
throws CorruptObjectException {
if ( ( ptr + 2 ) > = end )
throw new CorruptObjectException ( MessageFormat . format (
"invalid name contains byte sequence ''{0}'' which is not a valid UTF-8 character" ,
JGitText . get ( ) . corruptObjectInvalidNameInvalidUtf8 ,
toHexString ( raw , ptr , end ) ) ) ;
}
@ -634,7 +665,8 @@ public class ObjectChecker {
& & toLower ( raw [ ptr + 1 ] ) = = 'u'
& & toLower ( raw [ ptr + 2 ] ) = = 'x'
& & ( end - ptr = = 3 | | raw [ ptr + 3 ] = = '.' ) )
throw new CorruptObjectException ( "invalid name 'AUX'" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectInvalidNameAux ) ;
break ;
case 'c' : // CON, COM[1-9]
@ -642,14 +674,16 @@ public class ObjectChecker {
& & toLower ( raw [ ptr + 2 ] ) = = 'n'
& & toLower ( raw [ ptr + 1 ] ) = = 'o'
& & ( end - ptr = = 3 | | raw [ ptr + 3 ] = = '.' ) )
throw new CorruptObjectException ( "invalid name 'CON'" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectInvalidNameCon ) ;
if ( end - ptr > = 4
& & toLower ( raw [ ptr + 2 ] ) = = 'm'
& & toLower ( raw [ ptr + 1 ] ) = = 'o'
& & isPositiveDigit ( raw [ ptr + 3 ] )
& & ( end - ptr = = 4 | | raw [ ptr + 4 ] = = '.' ) )
throw new CorruptObjectException ( "invalid name 'COM"
+ ( ( char ) raw [ ptr + 3 ] ) + "'" ) ;
throw new CorruptObjectException ( String . format (
JGitText . get ( ) . corruptObjectInvalidNameCom ,
Character . valueOf ( ( ( char ) raw [ ptr + 3 ] ) ) ) ) ;
break ;
case 'l' : // LPT[1-9]
@ -658,8 +692,9 @@ public class ObjectChecker {
& & toLower ( raw [ ptr + 2 ] ) = = 't'
& & isPositiveDigit ( raw [ ptr + 3 ] )
& & ( end - ptr = = 4 | | raw [ ptr + 4 ] = = '.' ) )
throw new CorruptObjectException ( "invalid name 'LPT"
+ ( ( char ) raw [ ptr + 3 ] ) + "'" ) ;
throw new CorruptObjectException ( String . format (
JGitText . get ( ) . corruptObjectInvalidNameLpt ,
Character . valueOf ( ( ( char ) raw [ ptr + 3 ] ) ) ) ) ;
break ;
case 'n' : // NUL
@ -667,7 +702,8 @@ public class ObjectChecker {
& & toLower ( raw [ ptr + 1 ] ) = = 'u'
& & toLower ( raw [ ptr + 2 ] ) = = 'l'
& & ( end - ptr = = 3 | | raw [ ptr + 3 ] = = '.' ) )
throw new CorruptObjectException ( "invalid name 'NUL'" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectInvalidNameNul ) ;
break ;
case 'p' : // PRN
@ -675,7 +711,8 @@ public class ObjectChecker {
& & toLower ( raw [ ptr + 1 ] ) = = 'r'
& & toLower ( raw [ ptr + 2 ] ) = = 'n'
& & ( end - ptr = = 3 | | raw [ ptr + 3 ] = = '.' ) )
throw new CorruptObjectException ( "invalid name 'PRN'" ) ;
throw new CorruptObjectException (
JGitText . get ( ) . corruptObjectInvalidNamePrn ) ;
break ;
}
}