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

Tar: ustar entries with long name unable to roundtrip #75360

Closed
jozkee opened this issue Sep 9, 2022 · 4 comments · Fixed by #75902
Closed

Tar: ustar entries with long name unable to roundtrip #75360

jozkee opened this issue Sep 9, 2022 · 4 comments · Fixed by #75902
Assignees
Milestone

Comments

@jozkee
Copy link
Member

jozkee commented Sep 9, 2022

When you use new UstarTarEntry(TarEntryType entryType, string entryName) there's no exception about the entryName length, so I would expect that the format could handle any name but when I try to write a name larger than 100, the chars past 100 are written to the prefix.
When you read back the entry, we concat prefix + '/' + name, which makes the name different to what you wrote.

MemoryStream ms = new();
using (TarWriter writer = new(ms, true))
{
    TarEntry entry = new UstarTarEntry(TarEntryType.RegularFile, new string('a', 100) + new string('b', 155));
    Console.WriteLine("Entry name on write: " + entry.Name); // prints aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
    writer.WriteEntry(entry);
}

ms.Position =  0;
using (TarReader reader = new TarReader(ms))
{
    TarEntry entry = reader.GetNextEntry();
    Console.WriteLine("Entry name on reading: " + entry.Name); // prints bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
}

We need to align name and prefix behavior on read and write on ustar entries.
Aditionally, one way to set expectations about name lengths is to raise exceptions for names that would be truncated. For example, for V7 we can throw for names > 100 and for ustar we can throw for names > 255.

cc @carlossanlop

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Sep 9, 2022
@ghost
Copy link

ghost commented Sep 9, 2022

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

When you use new UstarTarEntry(TarEntryType entryType, string entryName) there's no exception about the entryName length, so I would expect that the format could handle any name but when I try to write a name larger than 100, the chars past 100 are written to the prefix.
When you read back the entry, we concat prefix + '/' + name, which makes the name different to what you wrote.

MemoryStream ms = new();
using (TarWriter writer = new(ms, true))
{
    TarEntry entry = new UstarTarEntry(TarEntryType.RegularFile, new string('a', 100) + new string('b', 155));
    Console.WriteLine("Entry name on write: " + entry.Name); // prints aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
    writer.WriteEntry(entry);
}

ms.Position =  0;
using (TarReader reader = new TarReader(ms))
{
    TarEntry entry = reader.GetNextEntry();
    Console.WriteLine("Entry name on reading: " + entry.Name); // prints bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
}

We need to align name and prefix behavior on read and write on ustar entries.
Aditionally, one way to set expectations about name lengths is to raise exceptions for names that would be truncated. For example, for V7 we can throw for names > 100 and for ustar we can throw for names > 255.

cc @carlossanlop

Author: Jozkee
Assignees: -
Labels:

area-System.IO

Milestone: -

@carlossanlop carlossanlop removed the untriaged New issue has not been triaged by the area owner label Sep 9, 2022
@carlossanlop carlossanlop self-assigned this Sep 9, 2022
@jozkee jozkee added this to the 8.0.0 milestone Sep 9, 2022
@jozkee
Copy link
Member Author

jozkee commented Sep 9, 2022

Moving to 8.0 as ustar is not a very popular format and the workaround is to use Pax or Gnu format instead.

@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Sep 26, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Sep 28, 2022
@kasperk81
Copy link
Contributor

fix is being backported #76322, so milestone 7?

@jozkee
Copy link
Member Author

jozkee commented Oct 3, 2022

@kasperk81 still needs approval to be merged into 7.0

@jozkee jozkee modified the milestones: 8.0.0, 7.0.0 Oct 6, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Nov 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants