Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions DebUOS/Packaging.Targets/IO/TarHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ internal unsafe struct TarHeader : IArchiveHeader
public string FileName
{
get => this.GetString(this.name, 100);
set => this.name = this.CreateString(value, 100);
set => this.name = this.CreateString(value, 100, reason: TarLimitReason);
}

private const string TarLimitReason = "From http://ibgwww.colorado.edu/~lessem/psyc5112/usail/man/solaris/tar.1.html , The file name (or leaf) length cannot exceed 100 characters. It is the limit of tar.";

public LinuxFileMode FileMode
{
get => (LinuxFileMode)Convert.ToUInt32(this.GetString(this.mode, 8), 8);
Expand Down Expand Up @@ -124,7 +126,7 @@ public TarTypeFlag TypeFlag
public string LinkName
{
get => this.GetString(this.linkname, 100);
set => this.linkname = this.CreateString(value, 100);
set => this.linkname = this.CreateString(value, 100, TarLimitReason);
}

public string Magic
Expand Down Expand Up @@ -242,7 +244,8 @@ private byte[] GetUIntTo8(uint? data, int len = 8)
return this.CreateString(Convert.ToString(data.Value, 8).PadLeft(len - 1, '0'), len);
}

private byte[] CreateString(string s, int len)
#nullable enable
private byte[] CreateString(string? s, int len, string? reason = null)
{
var target = new byte[len];
if (s == null)
Expand All @@ -253,7 +256,7 @@ private byte[] CreateString(string s, int len)
var buffer = Encoding.UTF8.GetBytes(s);
if (buffer.Length > len)
{
throw new Exception($"String {s} exceeds the limit of {len}");
throw new Exception($"String {s} exceeds the limit of {len}.{reason}");
}

for (var c = 0; c < len; c++)
Expand Down
Loading