-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fix some corner cases in TarReader #74329
Merged
carlossanlop
merged 1 commit into
dotnet:main
from
am11:feature/system.formats.tar/hardlinks-support
Aug 22, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,5 +124,31 @@ public void Read_Archive_LongFileName_Over100_Under255(TarEntryFormat format, Te | |
[InlineData(TarEntryFormat.Gnu, TestTarFormat.oldgnu)] | ||
public void Read_Archive_LongPath_Over255(TarEntryFormat format, TestTarFormat testFormat) => | ||
Read_Archive_LongPath_Over255_Internal(format, testFormat); | ||
|
||
[Fact] | ||
public void Read_NodeTarArchives_Successfully() | ||
{ | ||
string nodeTarPath = Path.Join(Directory.GetCurrentDirectory(), "tar", "node-tar"); | ||
foreach (string file in Directory.EnumerateFiles(nodeTarPath, "*.tar", SearchOption.AllDirectories)) | ||
{ | ||
using FileStream sourceStream = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read); | ||
using var reader = new TarReader(sourceStream); | ||
|
||
TarEntry? entry = null; | ||
while (true) | ||
{ | ||
Exception ex = Record.Exception(() => entry = reader.GetNextEntry()); | ||
Assert.Null(ex); | ||
|
||
if (entry is null) break; | ||
|
||
ex = Record.Exception(() => entry.Name); | ||
Assert.Null(ex); | ||
|
||
ex = Record.Exception(() => entry.Length); | ||
Assert.Null(ex); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Read content into a MemoryStream perhaps, as I did in my test code? |
||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First time I see Record.Exception being used.
What advantage does it have over simply letting this throw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent of
Record.Exception()
followed byAssert.Null()
is to be explicit about asserting that 'the method call is not throwing with this fix' (which were throwing without the fix). It also avoids seemingly unused statements to be optimized out by the JIT.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're consuming or asserting something about entry, Name, and Type the jit cannot remove them, and you're implicitly testing that they don't throw.
Eg you can assert that Name is never null, and that if type is Directory then length is zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eg you could do more or less what the test code did and then you won't need to record the exception explicitly