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

Trim file type bits from mode header #77151

Merged

Conversation

am11
Copy link
Member

@am11 am11 commented Oct 18, 2022

Fixes #77096.

Depends on dotnet/runtime-assets#279.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Oct 18, 2022
@ghost
Copy link

ghost commented Oct 18, 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 #77107.

Depends on dotnet/runtime-assets#279.

Author: am11
Assignees: -
Labels:

area-System.IO

Milestone: -

@tmds
Copy link
Member

tmds commented Oct 18, 2022

Fixes #77107.

I think you meant to link to: #77096

@am11
Copy link
Member Author

am11 commented Oct 18, 2022

I think you meant to link to: #77096

Yes, fixed. Too many tabs and PRs are opened. 😅

@adamsitnik
Copy link
Member

Depends on dotnet/runtime-assets#279.

Merged ;)

@am11 am11 marked this pull request as ready for review October 18, 2022 10:03
Copy link
Member

@tmds tmds 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!

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

LGTM, thank you very much for your help @am11 !

@am11
Copy link
Member Author

am11 commented Oct 19, 2022

@danmoseley, can we backport to 7.0? (bugfix in new library)

@danmoseley
Copy link
Member

danmoseley commented Oct 19, 2022

@am11 I moved to the ASPNET team so it's not my call. Generally test coverage doesn't need any special approvals to back port though. 7.0 branch might be closed for a bit for GA.

@danmoseley
Copy link
Member

Oh this is a product change. It would need all the regular process. The bar is roughly the servicing bar right now. It would be up to the folks in this repo though.

@am11
Copy link
Member Author

am11 commented Oct 19, 2022

@danmoseley this is the fix for the issue #77096 in which you were coordinating with the author. Seeing other fixes being backported to 7.0, so there may still be some time.

@danmoseley
Copy link
Member

danmoseley commented Oct 19, 2022

Yup, but this is @adamsitnik / @jeffhandley area now.

The test failure is another hit on #77087

00 (Inline) -------- coreclr!WKS::gc_heap::mark_array_marked+0x1a [D:\a_work\1\s\src\coreclr\gc\gc.cpp @ 8471]
01 (Inline) -------- coreclr!WKS::gc_heap::background_mark1+0x1a [D:\a_work\1\s\src\coreclr\gc\gc.cpp @ 23743]
02 1273f8e0 738482f8 coreclr!WKS::gc_heap::background_mark_simple+0x1b [D:\a_work\1\s\src\coreclr\gc\gc.cpp @ 25142]
03 (Inline) -------- coreclr!WKS::gc_heap::background_mark_object+0x22 [D:\a_work\1\s\src\coreclr\gc\gc.cpp @ 25162]
04 1273f8e0 73847b01 coreclr!WKS::gc_heap::revisit_written_page+0x3c8 [D:\a_work\1\s\src\coreclr\gc\gc.cpp @ 35631]
05 1273f938 73885ffc coreclr!WKS::gc_heap::revisit_written_pages+0xf1 [D:\a_work\1\s\src\coreclr\gc\gc.cpp @ 35832]
06 1273f980 7383195b coreclr!WKS::gc_heap::background_mark_phase+0x1b2 [D:\a_work\1\s\src\coreclr\gc\gc.cpp @ 35093]
07 1273f9b8 738a0d4c coreclr!WKS::gc_heap::gc1+0x49e [D:\a_work\1\s\src\coreclr\gc\gc.cpp @ 21184]
08 1273f9d0 738a0cef coreclr!WKS::gc_heap::bgc_thread_function+0x5a [D:\a_work\1\s\src\coreclr\gc\gc.cpp @ 36283]
09 1273f9f8 738b8e50 coreclr!WKS::gc_heap::bgc_thread_stub+0x1f [D:\a_work\1\s\src\coreclr\gc\gc.cpp @ 34225]
0a 1273f9f8 75a46709 coreclr!<lambda_410a0441ee61a5b8ed4f18f53fb141bc>::operator()+0x70 [D:\a_work\1\s\src\coreclr\vm\gcenv.ee.cpp @ 1415]

Copy link
Member

@jozkee jozkee left a comment

Choose a reason for hiding this comment

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

LGTM!

set
{
if ((int)value is < 0 or > 4095) // 4095 in decimal is 7777 in octal
if ((value & ~TarHelpers.ValidUnixFileModes) != 0) // throw on invalid UnixFileModes
Copy link
Member

Choose a reason for hiding this comment

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

nit: There's another reference to 4095 on the tests which we could change to a const UnixFileMode ValidUnixFileModes.

UnixFileMode expectedMode = (UnixFileMode)(status.Mode & 4095); // First 12 bits

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently we don't have access to the helpers in the tests.

Copy link
Member

Choose a reason for hiding this comment

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

I was suggesting copying the const to the tests, not making the one on src accessible to tests. Is just a nit, so you can disregard it.

Comment on lines +141 to +142
// Some paths do not use the setter, and we want to return valid UnixFileMode.
// This mask only keeps the least significant 12 bits.
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if not using the setter everywhere is correct. it seems somewhat inconsistent and we could've thrown earlier.

Copy link
Member Author

@am11 am11 Oct 20, 2022

Choose a reason for hiding this comment

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

Good point, I am not sure if this is intentional. I didn't wanted to go for larger refactoring at this point. There is also an existing helper:

internal static void CreateDirectory(string fullPath, UnixFileMode? mode, SortedDictionary<string, UnixFileMode>? pendingModes)
which takes care of permissions but for some reason we don't use it in the path OP was hitting the exception.

@@ -97,6 +97,19 @@ await using (TarWriter writer = new TarWriter(archive, TarEntryFormat.Ustar, lea
}
}

[Fact]
public async Task ExtractEntry_DockerImageTarWithFileTypeInDirectoriesInMode_SuccessfullyExtracts_Async()
Copy link
Member

Choose a reason for hiding this comment

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

I would also include a version of this test using a compressed archive since that's what the customer reported. Also, add the sync test. But this is up to you, not a big deal tbh.

Copy link
Member Author

Choose a reason for hiding this comment

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

That will require setting up token to fetch gzipped tar archive from docker api and posting a PR like dotnet/runtime-assets#279. I don't have access to those tokens (and don't think it is super important for 7.0 minimal fix).

@jozkee jozkee merged commit e242819 into dotnet:main Oct 20, 2022
@jozkee
Copy link
Member

jozkee commented Oct 20, 2022

Thanks.

@am11
Copy link
Member Author

am11 commented Oct 21, 2022

@jozkee, thanks. Can you please backport it to 7.0? This is matching the behavior of other tar reader implementations (tar xf docker-hello-world.tar on mac or linux works).

@am11 am11 deleted the feature/libs/System.Formats.Tar/docker-image-tar branch October 21, 2022 02:54
@jeffhandley
Copy link
Member

@am11 I'm going to initiate the backport. This will put the fix into consideration for a servicing release--most of the other backports you've observed have also been for the first servicing release. Thanks for this fix!

@jeffhandley
Copy link
Member

/backport to release/7.0

@github-actions
Copy link
Contributor

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

@github-actions
Copy link
Contributor

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

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

Applying: Trim file type bits from mode header
Applying: Define and use ValidUnixFileModes
Applying: Rev System.Formats.Tar.TestData version
Using index info to reconstruct a base tree...
M	eng/Version.Details.xml
M	eng/Versions.props
Falling back to patching base and 3-way merge...
Auto-merging eng/Versions.props
CONFLICT (content): Merge conflict in eng/Versions.props
Auto-merging eng/Version.Details.xml
CONFLICT (content): Merge conflict in eng/Version.Details.xml
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0003 Rev System.Formats.Tar.TestData version
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!

jeffhandley pushed a commit that referenced this pull request Oct 28, 2022
* Trim file type bits from mode header

* Define and use ValidUnixFileModes

* Rev System.Formats.Tar.TestData version

* Move ValidUnixFileModes to shared helpers
carlossanlop added a commit that referenced this pull request Nov 11, 2022
* Trim file type bits from mode header (#77151)

* Trim file type bits from mode header

* Define and use ValidUnixFileModes

* Rev System.Formats.Tar.TestData version

* Move ValidUnixFileModes to shared helpers

* Bump package version for TAR test assets

Co-authored-by: Adeel Mujahid <3840695+am11@users.noreply.github.com>
Co-authored-by: Carlos Sanchez <1175054+carlossanlop@users.noreply.github.com>
@ghost ghost locked as resolved and limited conversation to collaborators Dec 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Formats.Tar community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid UnixFileMode value when using the TarFile API
6 participants