Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for TarWriter - too much padding in large files #610

Merged
merged 2 commits into from Sep 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 6 additions & 10 deletions src/SharpCompress/Writers/Tar/TarWriter.cs
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