Skip to content

Commit

Permalink
Merge pull request #610 from cyr/master
Browse files Browse the repository at this point in the history
Bugfix for TarWriter - too much padding in large files
  • Loading branch information
adamhathcock authored Sep 12, 2021
2 parents b425659 + 61802ea commit 7bd9711
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/SharpCompress/Writers/Tar/TarWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,15 @@ public void Write(string filename, Stream source, DateTime? modificationTime, lo
header.Name = NormalizeFilename(filename);
header.Size = realSize;
header.Write(OutputStream);

size = source.TransferTo(OutputStream);
PadTo512(size.Value, false);
PadTo512(size.Value);
}

private void PadTo512(long size, bool forceZeros)
private void PadTo512(long size)
{
int zeros = (int)size % 512;
if (zeros == 0 && !forceZeros)
{
return;
}
zeros = 512 - zeros;
int zeros = unchecked((int)(((size + 511L) & ~511L) - size));

OutputStream.Write(stackalloc byte[zeros]);
}

Expand All @@ -108,8 +105,7 @@ protected override void Dispose(bool isDisposing)
{
if (finalizeArchiveOnClose)
{
PadTo512(0, true);
PadTo512(0, true);
OutputStream.Write(stackalloc byte[1024]);
}
switch (OutputStream)
{
Expand Down

0 comments on commit 7bd9711

Please sign in to comment.