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

Added test for extracting zip files with invalid characters in Windows #67332

Merged
merged 23 commits into from
Apr 11, 2022
Merged

Added test for extracting zip files with invalid characters in Windows #67332

merged 23 commits into from
Apr 11, 2022

Conversation

Danyy427
Copy link
Contributor

Relates to #67201

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

ghost commented Mar 30, 2022

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

Issue Details

Relates to #67201

Author: Danyy427
Assignees: -
Labels:

area-System.IO.Compression, community-contribution

Milestone: -

@danmoseley danmoseley marked this pull request as draft March 30, 2022 16:30
@danmoseley
Copy link
Member

Thanks. We will need the fix as well before we can merge this 😸

@Danyy427
Copy link
Contributor Author

@danmoseley I removed all of the [InlineData] and changed the test to a [Fact] and tested for all three of the files by hardcoding them. I hopefully didn't make a mistake because I wrote the code directly on GitHub. Once the tests are complete and fail, I will start working on the sanitization.

{
var testDirectory = GetTestFilePath();
ZipFile.ExtractToDirectory(compat("InvalidWindowsFileNameChars.zip"), testDirectory);
Assert.True(File.Exists(testDirectory + "Test______________________________________.txt"));
Copy link
Member

Choose a reason for hiding this comment

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

Please use Path.Combine not + - see other tests.

@danmoseley
Copy link
Member

Test looks good with comments above. Please also push up the fix now, that makes this test pass locally for you.

@danmoseley
Copy link
Member

BTW, it's fine doing things this way for your first PR 😄 but generally we would push up a PR when it's all done -- meaning tests+fix. We verify that the tests fail without the fix, but we do it locally beforehand.

@Danyy427
Copy link
Contributor Author

Danyy427 commented Mar 30, 2022

@danmoseley Oh, I thought when you said to write the tests first and verify it fails, I thought I was supposed to verify it fails on the GitHub repo rather than my local computer. That was the reason I asked if I should do it one go or separately.

I was going to start writing the fix but I cannot build the repo now due to some technical issue apparently. Once that is fixed and I can build the repo I will start the fix and probably push it by tomorrow.

BTW, thank you for helping, I am quite unfamiliar with all of this. I must have been a headache with all the questions :)

@danmoseley
Copy link
Member

thought I was supposed to verify it fails on the GitHub repo rather than my local computer

Yes, I was unclear 😄

What is the technical issue? Your link is to the install script.

@Danyy427
Copy link
Contributor Author

Danyy427 commented Mar 30, 2022

@danmoseley It doesn't build

GET https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.ps1
The remote server returned an error: (421) Misdirected Request.
Retrying. Waiting for 3 seconds before next attempt (2 of 5).
GET https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.ps1
The remote server returned an error: (421) Misdirected Request.
Retrying. Waiting for 7 seconds before next attempt (3 of 5).
GET https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.ps1
The remote server returned an error: (421) Misdirected Request.
Retrying. Waiting for 15 seconds before next attempt (4 of 5).
GET https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.ps1
The remote server returned an error: (421) Misdirected Request.
Retrying. Waiting for 31 seconds before next attempt (5 of 5).
GET https://dotnet.microsoft.com/download/dotnet/scripts/v1/dotnet-install.ps1
The remote server returned an error: (421) Misdirected Request.
Unable to download file in 5 attempts.

The link says the following

<h2>Our services aren't available right now</h2><p>We're working to restore all services as soon as possible. Please check back soon.</p>0wKJEYgAAAACW4qqrJ8M1QK2oV6FN05MfQU1TMDRFREdFMTkxMQBlMWRmMDcwYS1hZTQ0LTRjMGItYTU0Yi1jNDkzODA0ZTRkOWY=

Update: Install script is back

@Danyy427
Copy link
Contributor Author

@danmoseley I would be more than happy to continue contributing after this one.

@danmoseley
Copy link
Member

@ViktorHofer thanks. Why would we introduce a PNSE TFM when browser+windows+unix covers everything?

Simplest thing then seems to leave the Windows build as the platform agnostic one. I think that means

  • revert the TargetFrameworks line
  • change <ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows' or '$(TargetPlatformIdentifier)' == ''"> to <ItemGroup Condition="'$(TargetPlatformIdentifier)' == ''">

@Danyy427
Copy link
Contributor Author

Danyy427 commented Apr 10, 2022

@danmoseley Asking just out of curiosity, why do we assume windows to be the default when the windows filename rules are the exception? Wouldn't sanitizing only the null character be better when targeting a new platform perhaps?

@danmoseley
Copy link
Member

why do we assume windows to be the default when the windows filename rules are the exception?

As far as I'm aware, the only target that doesn't match browser and Unix is Windows, so it doesn't matter. If we add a new target, we would need to change other things too. I am not sure what the implications are of changing the default one, although @ViktorHofer would know.

@Danyy427
Copy link
Contributor Author

@danmoseley I don't know if it would change anything code-wise but I was thinking as a design.

@ViktorHofer
Copy link
Member

ViktorHofer commented Apr 11, 2022

The question is, how would you default if you would handle this during runtime?

Option A

if (IsWindows)
{
// Windows specific code
}
else if (IsUnix)
{
// Unix specific code
}
else if (IsBrowser)
{
// Browser specific code
}
else
{
    throw new PlatformNotSupportedException(...);
}

In our world where we don't use runtime conditions but build for specific platforms we would implement Option A the following way:

<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)</NetCoreAppCurrent>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<TargetPlatformIdentifier>$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))</TargetPlatformIdentifier>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetPlatformIdentifier)' == ''">SR.PNSEMEssage</GeneratePlatformNotSupportedAssemblyMessage>
</PropertyGroup>

Option B

if (IsWindows)
{
// Windows specific code
}
else if (IsBrowser)
{
// Browser specific code
}
else (IsUnix)
{
// Use Unix as the default implementation. The assumption stands that new platforms can leverage that implementation..
}

That would be implemented this way:

<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-Unix</NetCoreAppCurrent>
</PropertyGroup>

Choosing Option A requires an additional inner build (for the PNSE configuration) which is a significant cost compared to runtime checks. We should aim at not over-building as every additional project evaluation, msbuild target execution and compiler invocation adds to the overall build. That said, if a PNSE makes most sense for the library, it makes sense to choose it.

As far as I'm aware, the only target that doesn't match browser and Unix is Windows, so it doesn't matter. If we add a new target, we would need to change other things too. I am not sure what the implications are of changing the default one, although @ViktorHofer would know.

You can always move around the default as long as you make sure that the right platform gets the right implementation (via conditions on the item groups).

Why would we introduce a PNSE TFM when browser+windows+unix covers everything?

It might cover everything today but whenever we add a new platform we want our libraries to have a good default setting. In the past we chose Unix as the default as the most platforms builds on top of it. Choosing Windows as a default doesn't make much sense IMO as there is only a single platform (Windows) that would work with the implementation (assuming that the current Windows implementation is actually platform specific and not agnostic).

@danmoseley
Copy link
Member

Ok it sounds like we should default to the Unix behavior as you suggested @Danyy427 . Do you want to make that change?

@Danyy427
Copy link
Contributor Author

@danmoseley I tried, hopefully I understood @ViktorHofer's answer correctly.

Copy link
Member

@ViktorHofer ViktorHofer left a comment

Choose a reason for hiding this comment

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

From an infrastructure perspective this looks great. Thanks

…te.cs

Co-authored-by: Viktor Hofer <viktor.hofer@microsoft.com>
@Danyy427
Copy link
Contributor Author

@danmoseley Are we supposed to do anything else to get this thing to merge?

@danmoseley
Copy link
Member

@Danyy427 nope, just letting tests run.

@dotnet/dnceng something happened here with Azdo https://dev.azure.com/dnceng/9ee6d478-d288-47f7-aacc-f6e6d082ae6d/_apis/build/builds/1711221/logs/662

@ulisesh
Copy link
Contributor

ulisesh commented Apr 11, 2022

Thanks for reporting the problem @danmoseley. I haven't seen this error before but I'll create an issue to monitor this error.

I see that you already retried the build, hopefully it succeeds this time

@danmoseley danmoseley merged commit a074a2d into dotnet:main Apr 11, 2022
@danmoseley
Copy link
Member

Thanks @Danyy427. You ran into one or two more problems (on our side) than most PR's encounter!

@Danyy427
Copy link
Contributor Author

@danmoseley It’s okay I guess. Thanks for all the help you have given, it has been most useful. I will most certainly comtinue contributing. And this will certainly not be the last time I will give you a headache from all the questions. :)

@danmoseley
Copy link
Member

Always happy to help. As I mentioned earlier, from experience I highly recommend new folks get a number of easy, short PR's merged before tackling anything larger. Partly just because it takes time to get used to a repo's style, etc.

@Danyy427
Copy link
Contributor Author

@danmoseley Yeah, probably that’s foe the best. I browsed a couple of those easy and up-for-grabs. There are some which are like a year old and almost forgotten. I may continue with those perhaps as early as tomorrow

@Danyy427 Danyy427 deleted the Danyy427-ZipFile-Test branch April 12, 2022 08:44
@ghost ghost locked as resolved and limited conversation to collaborators May 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.IO.Compression 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.

5 participants