mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-10-04 04:38:45 +00:00
While enumerating the entries of a tar file and writing their contents to disk using TarArchive, it was discovered TarArchive was not properly discarding padding bytes in the last block of each entry. TarArchive was sometimes able to recover depending on the number of padding bytes due to the logic it uses to find the next entry header, but not always. TarArchive was changed to use TarReadOnlySubStream when opening entries and TarReadOnlySubstream was changed to ensure all an entry's blocks are read when it is being disposed. Fixes adamhathcock/sharpcompress#524
37 lines
984 B
C#
37 lines
984 B
C#
using System.IO;
|
|
using SharpCompress.Common.Tar.Headers;
|
|
using SharpCompress.IO;
|
|
|
|
namespace SharpCompress.Common.Tar
|
|
{
|
|
internal sealed class TarFilePart : FilePart
|
|
{
|
|
private readonly Stream _seekableStream;
|
|
|
|
internal TarFilePart(TarHeader header, Stream seekableStream)
|
|
: base(header.ArchiveEncoding)
|
|
{
|
|
_seekableStream = seekableStream;
|
|
Header = header;
|
|
}
|
|
|
|
internal TarHeader Header { get; }
|
|
|
|
internal override string FilePartName => Header.Name;
|
|
|
|
internal override Stream GetCompressedStream()
|
|
{
|
|
if (_seekableStream != null)
|
|
{
|
|
_seekableStream.Position = Header.DataStartPosition!.Value;
|
|
return new TarReadOnlySubStream(_seekableStream, Header.Size);
|
|
}
|
|
return Header.PackedStream;
|
|
}
|
|
|
|
internal override Stream? GetRawStream()
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
} |