Skip to content

Conversation

@jozkee
Copy link
Member

@jozkee jozkee commented Sep 29, 2022

Fixes #75215

Minimal fix for the reported scenario.

Note: There's another issue with how we deal with ExtendedAttributes and public properties. There's no syncronization between both, which may lead to unexpected results when writing a PaxTarEntry, see #76405.

@jozkee jozkee added this to the 8.0.0 milestone Sep 29, 2022
@jozkee jozkee self-assigned this Sep 29, 2022
@ghost
Copy link

ghost commented Sep 29, 2022

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

Issue Details

Fixes #75215

Minimal fix for the reported scenario.

Note: There's another issue with how we deal with ExtendedAttributes and public properties. There's no syncronization between both, which may lead to unexpected results when writing a PaxTarEntry but I think we can defer that issue and maybe even just fix it for 8.0.

e.g:

[Fact]
public void QuickTest()
{
    Dictionary<string, string> ea = new();
    ea["path"] = "foo";

    PaxTarEntry paxEntry = new PaxTarEntry(TarEntryType.RegularFile, "bar", ea);

    Console.WriteLine(paxEntry.Name); // prints bar
    Console.WriteLine(paxEntry.ExtendedAttributes["path"]); // prints foo
}
Author: Jozkee
Assignees: Jozkee
Labels:

area-System.IO

Milestone: 8.0.0

@jozkee jozkee changed the title Use indexer setter instead of Add on ExtendedAttributes dictionary Tar: Use indexer setter instead of Add on ExtendedAttributes dictionary Sep 29, 2022
Comment on lines 725 to 728
if (!ExtendedAttributes.ContainsKey(PaxEaMTime))
{
ExtendedAttributes.Add(PaxEaMTime, TarHelpers.GetTimestampStringFromDateTimeOffset(_mTime));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pointing out some other issues in this code:

  1. someone uses the copy ctor. passing the extended attributes from the other entry.
  2. on the new entry, you set ModificationTime.
  3. pass the new entry to TarWriter.WriteEntry.

The modification time will be neglected due to this check. @carlossanlop please advice if this is something we should address in this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please advice if this is something we should address in this PR.

Yes. We must always update the dictionary value for mtime using the value from the ModificationTime property. So the if condition should be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you recall why was added in the first place?

{
ExtendedAttributes.Add(PaxEaSize, _size.ToString());
ExtendedAttributes[PaxEaSize] = _size.ToString();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add an else here, in case the data stream gets reduced below the max allowed size, in which case, we can remove the PaxEaSize value from the dictionary entry.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my other PR which was replaced by this one, I had a fake stream implementation that simulated having 99_999_999 length. You can reuse that to test this.

@jozkee jozkee requested a review from carlossanlop September 30, 2022 21:49

if (!string.IsNullOrEmpty(_linkName))
{
Debug.Assert(_typeFlag is TarEntryType.SymbolicLink or TarEntryType.HardLink);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

Copy link
Contributor

@carlossanlop carlossanlop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for adding the tests and addressing the mtime suggestion.

CI failure unrelated: iOSSimulator timeout cancellation during build (longer than 60 min).

##[error]The operation was canceled.

@jozkee jozkee merged commit 221717b into dotnet:main Oct 3, 2022
@jozkee jozkee deleted the tar_75215 branch October 3, 2022 20:45
@jozkee
Copy link
Member Author

jozkee commented Oct 3, 2022

/backport to release/7.0

@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2022

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3177692797

@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2022

@jozkee backporting to release/7.0 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Use indexer setter instead of Add on ExtendedAttributes dictionary
Using index info to reconstruct a base tree...
M	src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Write.cs
M	src/libraries/System.Formats.Tar/tests/TarTestsBase.cs
M	src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Tests.cs
M	src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Tests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Tests.cs
CONFLICT (content): Merge conflict in src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Tests.cs
Auto-merging src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Tests.cs
CONFLICT (content): Merge conflict in src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Tests.cs
Auto-merging src/libraries/System.Formats.Tar/tests/TarTestsBase.cs
CONFLICT (content): Merge conflict in src/libraries/System.Formats.Tar/tests/TarTestsBase.cs
Auto-merging src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Write.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Use indexer setter instead of Add on ExtendedAttributes dictionary
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

jozkee added a commit that referenced this pull request Oct 3, 2022
…ry (#76404)

* Use indexer setter instead of Add on ExtendedAttributes dictionary

* Add roundtrip tests

* Fix TryAddStringField and always set mtime
@carlossanlop carlossanlop added Servicing-consider Issue for next servicing release review and removed Servicing-consider Issue for next servicing release review labels Oct 3, 2022
carlossanlop pushed a commit that referenced this pull request Oct 4, 2022
* Use UTF8 encoding on Tar string fields

* Slice destination on Checksum

* Use Encoding.GetByteCount as fast path

* Use escape sequences on hardcoded UTF8 characters

* Fix ustar prefix logic and throw if name would be truncated

* Address feedback

* Fix truncation and prefix logic

* Fix nits

* Add async tests

* Add tests for unseekable streams

* Address feedback

* Tar: Use indexer setter instead of Add on ExtendedAttributes dictionary (#76404)

* Use indexer setter instead of Add on ExtendedAttributes dictionary

* Add roundtrip tests

* Fix TryAddStringField and always set mtime

Co-authored-by: David Cantu <[email protected]>
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tar: Not able to write a PaxTarEntry from a TarReader.

3 participants