Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TarWriter writes badly formatted size field for a zero sized regular file #95354

@sobczyk

Description

@sobczyk

Description

TarWriter writes badly formatted size field for a zero sized regular file

Reproduction Steps

using System;
using System.IO;
using System.Linq;
using System.Formats.Tar;

MemoryStream emptyData = new(0);
MemoryStream output = new();
TarWriter archive = new(output, TarEntryFormat.Pax);
PaxTarEntry te = new(TarEntryType.RegularFile, "zero_size")
{DataStream = emptyData};
archive.WriteEntry(te);
// get the size[12] field, after two unrelated blocks[512] and name[100], mode[8], uid[8], gid[8]
var offset = 2*512+100+3*8;
var sizeBuffer=output.GetBuffer()[offset..(offset+12)];
// it's "00000000000\0"
byte[] expected = new byte[] {0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0};
Console.WriteLine($"Proper size field: {sizeBuffer.SequenceEqual(expected)}");

Expected behavior

get all "0" in field (0x32) followed by "\0"

Actual behavior

get binary zero

Regression?

No

Known Workarounds

None

Configuration

Affected: (any with TarWriter)

  • .net 7
  • .net 8

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions