-
Notifications
You must be signed in to change notification settings - Fork 5.1k
SkipBlockAlignmentPadding must be executed for all entries #74396
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,5 +250,43 @@ public void GetNextEntry_UnseekableArchive_ReplaceDataStream_ExcludeFromDisposin | |
Assert.Equal("Substituted", streamReader.ReadLine()); | ||
} | ||
} | ||
|
||
[Theory] | ||
[InlineData(512)] | ||
[InlineData(512 + 1)] | ||
[InlineData(512 + 512 - 1)] | ||
public void BlockAlignmentPadding_DoesNotAffectNextEntries(int contentSize) | ||
{ | ||
byte[] fileContents = new byte[contentSize]; | ||
Array.Fill<byte>(fileContents, 0x1); | ||
|
||
using var archive = new MemoryStream(); | ||
using (var writer = new TarWriter(archive, leaveOpen: true)) | ||
{ | ||
var entry1 = new PaxTarEntry(TarEntryType.RegularFile, "file"); | ||
entry1.DataStream = new MemoryStream(fileContents); | ||
writer.WriteEntry(entry1); | ||
|
||
var entry2 = new PaxTarEntry(TarEntryType.RegularFile, "next-file"); | ||
writer.WriteEntry(entry2); | ||
} | ||
|
||
archive.Position = 0; | ||
using var unseekable = new WrappedStream(archive, archive.CanRead, archive.CanWrite, canSeek: false); | ||
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. Total nit. I would've used the arguments |
||
using var reader = new TarReader(unseekable); | ||
|
||
TarEntry e = reader.GetNextEntry(); | ||
Assert.Equal(contentSize, e.Length); | ||
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. I would've added a couple other asserts when checking both entries: Assert.Equal("file", e.Name);
Assert.Equal(TarEntryType.RegularFile, e.EntryType); The |
||
|
||
byte[] buffer = new byte[contentSize]; | ||
while (e.DataStream.Read(buffer) > 0) ; | ||
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. I would've added an |
||
AssertExtensions.SequenceEqual(fileContents, buffer); | ||
|
||
e = reader.GetNextEntry(); | ||
Assert.Equal(0, e.Length); | ||
|
||
e = reader.GetNextEntry(); | ||
Assert.Null(e); | ||
Comment on lines
+288
to
+289
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. I would usually put these together. But this is fine too. No need to restart the CI for this. Assert.Null(reader.GetNextEntry()); And the async variant: Assert.Null(await reader.GetNextEntryAsync()); |
||
} | ||
} | ||
} |
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.
This is good. A 0x1 char is not a valid char in any of the header fields, so if the archive is not reading entries from the correct position, this char would cause an exception when collecting the header fields.