diff --git a/src/SharpCompress/Common/Tar/Headers/TarHeader.cs b/src/SharpCompress/Common/Tar/Headers/TarHeader.cs index ef86ab00..0e379e6b 100644 --- a/src/SharpCompress/Common/Tar/Headers/TarHeader.cs +++ b/src/SharpCompress/Common/Tar/Headers/TarHeader.cs @@ -1,4 +1,4 @@ -#nullable disable +#nullable disable using System; using System.Buffers.Binary; @@ -132,8 +132,8 @@ internal bool Read(BinaryReader reader) Mode |= 0b1_000_000_000; } - UserId = ReadAsciiInt64Base8(buffer, 108, 7); - GroupId = ReadAsciiInt64Base8(buffer, 116, 7); + UserId = ReadAsciiInt64Base8oldGnu(buffer, 108, 7); + GroupId = ReadAsciiInt64Base8oldGnu(buffer, 116, 7); var unixTimeStamp = ReadAsciiInt64Base8(buffer, 136, 11); LastModifiedTime = EPOCH.AddSeconds(unixTimeStamp).ToLocalTime(); @@ -249,6 +249,24 @@ private static long ReadAsciiInt64Base8(byte[] buffer, int offset, int count) return Convert.ToInt64(s, 8); } + private static long ReadAsciiInt64Base8oldGnu(byte[] buffer, int offset, int count) + { + if (buffer[offset] == 0x80 && buffer[offset + 1] == 0x00) + { + return buffer[offset + 4] << 24 + | buffer[offset + 5] << 16 + | buffer[offset + 6] << 8 + | buffer[offset + 7]; + } + var s = Encoding.UTF8.GetString(buffer, offset, count).TrimNulls(); + + if (string.IsNullOrEmpty(s)) + { + return 0; + } + return Convert.ToInt64(s, 8); + } + private static long ReadAsciiInt64(byte[] buffer, int offset, int count) { var s = Encoding.UTF8.GetString(buffer, offset, count).TrimNulls(); diff --git a/tests/SharpCompress.Test/Tar/TarReaderTests.cs b/tests/SharpCompress.Test/Tar/TarReaderTests.cs index 218eb43f..4952b702 100644 --- a/tests/SharpCompress.Test/Tar/TarReaderTests.cs +++ b/tests/SharpCompress.Test/Tar/TarReaderTests.cs @@ -56,6 +56,9 @@ public void Tar_Skip() [Fact] public void Tar_Xz_Reader() => Read("Tar.tar.xz", CompressionType.Xz); + [Fact] + public void Tar_GZip_OldGnu_Reader() => Read("Tar.oldgnu.tar.gz", CompressionType.GZip); + [Fact] public void Tar_BZip2_Entry_Stream() { diff --git a/tests/TestArchives/Archives/Tar.oldgnu.tar.gz b/tests/TestArchives/Archives/Tar.oldgnu.tar.gz new file mode 100644 index 00000000..fbffb7a2 Binary files /dev/null and b/tests/TestArchives/Archives/Tar.oldgnu.tar.gz differ