@@ -147,6 +147,11 @@ public class TarHeader : ICloneable
147147 /// </summary>
148148 public const int DEVLEN = 8 ;
149149
150+ /// <summary>
151+ /// The length of the name prefix field in a header buffer.
152+ /// </summary>
153+ public const int PREFIXLEN = 155 ;
154+
150155 //
151156 // LF_ constants represent the "type" of an entry
152157 //
@@ -597,21 +602,26 @@ public void ParseBuffer(byte[] header)
597602 Magic = ParseName ( header , offset , MAGICLEN ) . ToString ( ) ;
598603 offset += MAGICLEN ;
599604
600- Version = ParseName ( header , offset , VERSIONLEN ) . ToString ( ) ;
601- offset += VERSIONLEN ;
605+ if ( Magic == "ustar" )
606+ {
607+ Version = ParseName ( header , offset , VERSIONLEN ) . ToString ( ) ;
608+ offset += VERSIONLEN ;
602609
603- UserName = ParseName ( header , offset , UNAMELEN ) . ToString ( ) ;
604- offset += UNAMELEN ;
610+ UserName = ParseName ( header , offset , UNAMELEN ) . ToString ( ) ;
611+ offset += UNAMELEN ;
605612
606- GroupName = ParseName ( header , offset , GNAMELEN ) . ToString ( ) ;
607- offset += GNAMELEN ;
613+ GroupName = ParseName ( header , offset , GNAMELEN ) . ToString ( ) ;
614+ offset += GNAMELEN ;
608615
609- DevMajor = ( int ) ParseOctal ( header , offset , DEVLEN ) ;
610- offset += DEVLEN ;
616+ DevMajor = ( int ) ParseOctal ( header , offset , DEVLEN ) ;
617+ offset += DEVLEN ;
611618
612- DevMinor = ( int ) ParseOctal ( header , offset , DEVLEN ) ;
619+ DevMinor = ( int ) ParseOctal ( header , offset , DEVLEN ) ;
620+ offset += DEVLEN ;
613621
614- // Fields past this point not currently parsed or used...
622+ string prefix = ParseName ( header , offset , PREFIXLEN ) . ToString ( ) ;
623+ if ( ! string . IsNullOrEmpty ( prefix ) ) Name = prefix + '/' + Name ;
624+ }
615625
616626 isChecksumValid = Checksum == TarHeader . MakeCheckSum ( header ) ;
617627 }
0 commit comments