From faf448fcee3f566d925f0f6c51dbda4f10eecce7 Mon Sep 17 00:00:00 2001 From: carlossanlop Date: Wed, 31 Aug 2022 13:28:14 -0700 Subject: [PATCH 1/5] Disallow TarWriter from writing link entries without LinkName set --- .../src/System/Formats/Tar/TarHeader.Write.cs | 3 +++ .../src/System/Formats/Tar/TarWriter.cs | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Write.cs b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Write.cs index 2afcfb8a9f23df..e1166a066814b3 100644 --- a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Write.cs +++ b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Write.cs @@ -391,6 +391,9 @@ private int WritePosixName(Span buffer) // Writes all the common fields shared by all formats into the specified spans. private int WriteCommonFields(Span buffer, long actualLength, TarEntryType actualEntryType) { + // Don't write an empty LinkName if the entry is a hardlink or symlink + Debug.Assert(!string.IsNullOrEmpty(_linkName) ^ (_typeFlag is not TarEntryType.SymbolicLink and not TarEntryType.HardLink)); + int checksum = 0; if (_mode > 0) diff --git a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs index 7d3977eda68df4..78f89951dd0c29 100644 --- a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs +++ b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs @@ -216,6 +216,7 @@ public void WriteEntry(TarEntry entry) { ObjectDisposedException.ThrowIf(_isDisposed, this); ArgumentNullException.ThrowIfNull(entry); + ValidateEntryLinkName(entry._header._typeFlag, entry._header._linkName); WriteEntryInternal(entry); } @@ -262,6 +263,7 @@ public Task WriteEntryAsync(TarEntry entry, CancellationToken cancellationToken ObjectDisposedException.ThrowIf(_isDisposed, this); ArgumentNullException.ThrowIfNull(entry); + ValidateEntryLinkName(entry._header._typeFlag, entry._header._linkName); return WriteEntryAsyncInternal(entry, cancellationToken); } @@ -365,5 +367,16 @@ private async ValueTask WriteFinalRecordsAsync() return (fullPath, actualEntryName); } + + private static void ValidateEntryLinkName(TarEntryType entryType, string? linkName) + { + if (entryType is TarEntryType.HardLink or TarEntryType.SymbolicLink) + { + if (string.IsNullOrEmpty(linkName)) + { + throw new InvalidDataException(SR.TarEntryHardLinkOrSymlinkLinkNameEmpty); + } + } + } } } From e0cffcae3d0509930bd6deb52d511f9a8ba08595 Mon Sep 17 00:00:00 2001 From: carlossanlop Date: Wed, 31 Aug 2022 13:28:20 -0700 Subject: [PATCH 2/5] Tests --- .../TarWriter.WriteEntry.Entry.Gnu.Tests.cs | 14 ++++++++++++++ .../TarWriter.WriteEntry.Entry.Pax.Tests.cs | 10 ++++++++++ .../TarWriter.WriteEntry.Entry.Ustar.Tests.cs | 10 ++++++++++ .../TarWriter.WriteEntry.Entry.V7.Tests.cs | 10 ++++++++++ .../TarWriter.WriteEntryAsync.Entry.Gnu.Tests.cs | 14 ++++++++++++++ .../TarWriter.WriteEntryAsync.Entry.Pax.Tests.cs | 10 ++++++++++ .../TarWriter.WriteEntryAsync.Entry.Ustar.Tests.cs | 10 ++++++++++ .../TarWriter.WriteEntryAsync.Entry.V7.Tests.cs | 10 ++++++++++ 8 files changed, 88 insertions(+) diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Gnu.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Gnu.Tests.cs index d591ba9b6542a6..7595acc2bbae1a 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Gnu.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Gnu.Tests.cs @@ -167,6 +167,10 @@ public void Write_Long_Name(TarEntryType entryType) using (TarWriter writer = new TarWriter(archiveStream, TarEntryFormat.Gnu, leaveOpen: true)) { GnuTarEntry entry = new GnuTarEntry(entryType, longName); + if (entryType is TarEntryType.HardLink or TarEntryType.SymbolicLink) + { + entry.LinkName = "linktarget"; + } writer.WriteEntry(entry); } @@ -231,5 +235,15 @@ public void Write_LongName_And_LongLinkName(TarEntryType entryType) Assert.Equal(longLinkName, entry.LinkName); } } + + [Theory] + [InlineData(TarEntryType.HardLink)] + [InlineData(TarEntryType.SymbolicLink)] + public void Write_LinkEntry_EmptyLinkName_Throws(TarEntryType entryType) + { + using MemoryStream archiveStream = new MemoryStream(); + using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); + Assert.Throws(() => writer.WriteEntry(new GnuTarEntry(entryType, "link"))); + } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Pax.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Pax.Tests.cs index 6c9e79d83a1eff..c435562fbb4221 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Pax.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Pax.Tests.cs @@ -485,5 +485,15 @@ public void WriteTimestampsBeyondOctalLimitInPax() Assert.Equal(overLimitTimestamp, actualCTime); } } + + [Theory] + [InlineData(TarEntryType.HardLink)] + [InlineData(TarEntryType.SymbolicLink)] + public void Write_LinkEntry_EmptyLinkName_Throws(TarEntryType entryType) + { + using MemoryStream archiveStream = new MemoryStream(); + using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); + Assert.Throws(() => writer.WriteEntry(new PaxTarEntry(entryType, "link"))); + } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Ustar.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Ustar.Tests.cs index da3b69051ab347..ef8852eac0df26 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Ustar.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Ustar.Tests.cs @@ -152,5 +152,15 @@ public void WriteFifo() VerifyFifo(fifo); } } + + [Theory] + [InlineData(TarEntryType.HardLink)] + [InlineData(TarEntryType.SymbolicLink)] + public void Write_LinkEntry_EmptyLinkName_Throws(TarEntryType entryType) + { + using MemoryStream archiveStream = new MemoryStream(); + using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); + Assert.Throws(() => writer.WriteEntry(new UstarTarEntry(entryType, "link"))); + } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.V7.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.V7.Tests.cs index fb0cbb980ee6e2..cb1a7c5613bfca 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.V7.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.V7.Tests.cs @@ -92,5 +92,15 @@ public void WriteDirectory() VerifyDirectory(directory); } } + + [Theory] + [InlineData(TarEntryType.HardLink)] + [InlineData(TarEntryType.SymbolicLink)] + public void Write_LinkEntry_EmptyLinkName_Throws(TarEntryType entryType) + { + using MemoryStream archiveStream = new MemoryStream(); + using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); + Assert.Throws(() => writer.WriteEntry(new V7TarEntry(entryType, "link"))); + } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Gnu.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Gnu.Tests.cs index b33e2bf7add22a..dcd264959c713b 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Gnu.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Gnu.Tests.cs @@ -183,6 +183,10 @@ public async Task Write_Long_Name_Async(TarEntryType entryType) await using (TarWriter writer = new TarWriter(archiveStream, TarEntryFormat.Gnu, leaveOpen: true)) { GnuTarEntry entry = new GnuTarEntry(entryType, longName); + if (entryType is TarEntryType.HardLink or TarEntryType.SymbolicLink) + { + entry.LinkName = "linktarget"; + } await writer.WriteEntryAsync(entry); } @@ -252,5 +256,15 @@ public async Task Write_LongName_And_LongLinkName_Async(TarEntryType entryType) } } } + + [Theory] + [InlineData(TarEntryType.HardLink)] + [InlineData(TarEntryType.SymbolicLink)] + public async Task Write_LinkEntry_EmptyLinkName_Throws_Async(TarEntryType entryType) + { + await using MemoryStream archiveStream = new MemoryStream(); + await using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); + await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new GnuTarEntry(entryType, "link"))); + } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Pax.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Pax.Tests.cs index 688c918baedf15..eb4ca3e9dad09c 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Pax.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Pax.Tests.cs @@ -505,5 +505,15 @@ public async Task WriteTimestampsBeyondOctalLimitInPax_Async() Assert.Equal(overLimitTimestamp, actualCTime); } } + + [Theory] + [InlineData(TarEntryType.HardLink)] + [InlineData(TarEntryType.SymbolicLink)] + public async Task Write_LinkEntry_EmptyLinkName_Throws_Async(TarEntryType entryType) + { + await using MemoryStream archiveStream = new MemoryStream(); + await using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); + await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new PaxTarEntry(entryType, "link"))); + } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Ustar.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Ustar.Tests.cs index 1266e7216a0126..6e76b090655613 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Ustar.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Ustar.Tests.cs @@ -153,5 +153,15 @@ public async Task WriteFifo_Async() VerifyFifo(fifo); } } + + [Theory] + [InlineData(TarEntryType.HardLink)] + [InlineData(TarEntryType.SymbolicLink)] + public async Task Write_LinkEntry_EmptyLinkName_Throws_Async(TarEntryType entryType) + { + await using MemoryStream archiveStream = new MemoryStream(); + await using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); + await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new UstarTarEntry(entryType, "link"))); + } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.V7.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.V7.Tests.cs index 4408477ee00006..d26dbcb0a6d453 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.V7.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.V7.Tests.cs @@ -93,5 +93,15 @@ public async Task WriteDirectory_Async() VerifyDirectory(directory); } } + + [Theory] + [InlineData(TarEntryType.HardLink)] + [InlineData(TarEntryType.SymbolicLink)] + public async Task Write_LinkEntry_EmptyLinkName_Throws_Async(TarEntryType entryType) + { + await using MemoryStream archiveStream = new MemoryStream(); + await using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); + await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new V7TarEntry(entryType, "link"))); + } } } From c4252b3dbb647eae53ce7a124396c685ea0b46c3 Mon Sep 17 00:00:00 2001 From: carlossanlop Date: Wed, 31 Aug 2022 13:47:39 -0700 Subject: [PATCH 3/5] Docs --- .../System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs index 78f89951dd0c29..d9686edffbc4a3 100644 --- a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs +++ b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs @@ -209,6 +209,7 @@ private async Task ReadFileFromDiskAndWriteToArchiveStreamAsEntryAsync(string fu /// /// /// + /// The entry type is or and the is or empty. /// The archive stream is disposed. /// The entry type of the is not supported for writing. /// An I/O problem occurred. @@ -251,6 +252,7 @@ public void WriteEntry(TarEntry entry) /// /// /// + /// The entry type is or and the is or empty. /// The archive stream is disposed. /// The entry type of the is not supported for writing. /// An I/O problem occurred. From 45e35f50e83044e37f92a260856ef99759a7478d Mon Sep 17 00:00:00 2001 From: Carlos Sanchez <1175054+carlossanlop@users.noreply.github.com> Date: Wed, 31 Aug 2022 16:37:48 -0700 Subject: [PATCH 4/5] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David CantĂș --- .../System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs | 2 +- .../tests/TarWriter/TarWriter.WriteEntry.Entry.Gnu.Tests.cs | 2 +- .../tests/TarWriter/TarWriter.WriteEntry.Entry.Pax.Tests.cs | 2 +- .../tests/TarWriter/TarWriter.WriteEntry.Entry.Ustar.Tests.cs | 2 +- .../tests/TarWriter/TarWriter.WriteEntry.Entry.V7.Tests.cs | 2 +- .../TarWriter/TarWriter.WriteEntryAsync.Entry.Gnu.Tests.cs | 2 +- .../TarWriter/TarWriter.WriteEntryAsync.Entry.Pax.Tests.cs | 2 +- .../TarWriter/TarWriter.WriteEntryAsync.Entry.Ustar.Tests.cs | 2 +- .../tests/TarWriter/TarWriter.WriteEntryAsync.Entry.V7.Tests.cs | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs index d9686edffbc4a3..3914557905151b 100644 --- a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs +++ b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs @@ -376,7 +376,7 @@ private static void ValidateEntryLinkName(TarEntryType entryType, string? linkNa { if (string.IsNullOrEmpty(linkName)) { - throw new InvalidDataException(SR.TarEntryHardLinkOrSymlinkLinkNameEmpty); + throw new ArgumentException(SR.TarEntryHardLinkOrSymlinkLinkNameEmpty, "entry"); } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Gnu.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Gnu.Tests.cs index 7595acc2bbae1a..1a3322c3dc4b09 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Gnu.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Gnu.Tests.cs @@ -243,7 +243,7 @@ public void Write_LinkEntry_EmptyLinkName_Throws(TarEntryType entryType) { using MemoryStream archiveStream = new MemoryStream(); using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - Assert.Throws(() => writer.WriteEntry(new GnuTarEntry(entryType, "link"))); + Assert.Throws(() => writer.WriteEntry(new GnuTarEntry(entryType, "link"))); } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Pax.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Pax.Tests.cs index c435562fbb4221..354d3e9a5b1214 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Pax.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Pax.Tests.cs @@ -493,7 +493,7 @@ public void Write_LinkEntry_EmptyLinkName_Throws(TarEntryType entryType) { using MemoryStream archiveStream = new MemoryStream(); using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - Assert.Throws(() => writer.WriteEntry(new PaxTarEntry(entryType, "link"))); + Assert.Throws(() => writer.WriteEntry(new PaxTarEntry(entryType, "link"))); } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Ustar.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Ustar.Tests.cs index ef8852eac0df26..0f3cd7c3361e55 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Ustar.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Ustar.Tests.cs @@ -160,7 +160,7 @@ public void Write_LinkEntry_EmptyLinkName_Throws(TarEntryType entryType) { using MemoryStream archiveStream = new MemoryStream(); using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - Assert.Throws(() => writer.WriteEntry(new UstarTarEntry(entryType, "link"))); + Assert.Throws(() => writer.WriteEntry(new UstarTarEntry(entryType, "link"))); } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.V7.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.V7.Tests.cs index cb1a7c5613bfca..94843b3ca68a7f 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.V7.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.V7.Tests.cs @@ -100,7 +100,7 @@ public void Write_LinkEntry_EmptyLinkName_Throws(TarEntryType entryType) { using MemoryStream archiveStream = new MemoryStream(); using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - Assert.Throws(() => writer.WriteEntry(new V7TarEntry(entryType, "link"))); + Assert.Throws(() => writer.WriteEntry(new V7TarEntry(entryType, "link"))); } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Gnu.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Gnu.Tests.cs index dcd264959c713b..eb7a0b013758a8 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Gnu.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Gnu.Tests.cs @@ -264,7 +264,7 @@ public async Task Write_LinkEntry_EmptyLinkName_Throws_Async(TarEntryType entryT { await using MemoryStream archiveStream = new MemoryStream(); await using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new GnuTarEntry(entryType, "link"))); + await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new GnuTarEntry(entryType, "link"))); } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Pax.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Pax.Tests.cs index eb4ca3e9dad09c..6de27adb92d61d 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Pax.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Pax.Tests.cs @@ -513,7 +513,7 @@ public async Task Write_LinkEntry_EmptyLinkName_Throws_Async(TarEntryType entryT { await using MemoryStream archiveStream = new MemoryStream(); await using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new PaxTarEntry(entryType, "link"))); + await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new PaxTarEntry(entryType, "link"))); } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Ustar.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Ustar.Tests.cs index 6e76b090655613..ba12d52f06fada 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Ustar.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Ustar.Tests.cs @@ -161,7 +161,7 @@ public async Task Write_LinkEntry_EmptyLinkName_Throws_Async(TarEntryType entryT { await using MemoryStream archiveStream = new MemoryStream(); await using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new UstarTarEntry(entryType, "link"))); + await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new UstarTarEntry(entryType, "link"))); } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.V7.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.V7.Tests.cs index d26dbcb0a6d453..fddc39b976c94f 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.V7.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.V7.Tests.cs @@ -101,7 +101,7 @@ public async Task Write_LinkEntry_EmptyLinkName_Throws_Async(TarEntryType entryT { await using MemoryStream archiveStream = new MemoryStream(); await using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new V7TarEntry(entryType, "link"))); + await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new V7TarEntry(entryType, "link"))); } } } From a1eec88640d1c04ad2b6f295f9f45551a6163729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Cant=C3=BA?= Date: Wed, 31 Aug 2022 20:50:48 -0700 Subject: [PATCH 5/5] Apply suggestions from code review --- .../System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs | 4 ++-- .../tests/TarWriter/TarWriter.WriteEntry.Entry.Gnu.Tests.cs | 2 +- .../tests/TarWriter/TarWriter.WriteEntry.Entry.Pax.Tests.cs | 2 +- .../tests/TarWriter/TarWriter.WriteEntry.Entry.Ustar.Tests.cs | 2 +- .../tests/TarWriter/TarWriter.WriteEntry.Entry.V7.Tests.cs | 2 +- .../TarWriter/TarWriter.WriteEntryAsync.Entry.Gnu.Tests.cs | 2 +- .../TarWriter/TarWriter.WriteEntryAsync.Entry.Pax.Tests.cs | 2 +- .../TarWriter/TarWriter.WriteEntryAsync.Entry.Ustar.Tests.cs | 2 +- .../TarWriter/TarWriter.WriteEntryAsync.Entry.V7.Tests.cs | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs index 3914557905151b..ee5da966c29947 100644 --- a/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs +++ b/src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs @@ -209,7 +209,7 @@ private async Task ReadFileFromDiskAndWriteToArchiveStreamAsEntryAsync(string fu /// /// /// - /// The entry type is or and the is or empty. + /// The entry type is or and the is or empty. /// The archive stream is disposed. /// The entry type of the is not supported for writing. /// An I/O problem occurred. @@ -252,7 +252,7 @@ public void WriteEntry(TarEntry entry) /// /// /// - /// The entry type is or and the is or empty. + /// The entry type is or and the is or empty. /// The archive stream is disposed. /// The entry type of the is not supported for writing. /// An I/O problem occurred. diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Gnu.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Gnu.Tests.cs index 1a3322c3dc4b09..925daef99d5167 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Gnu.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Gnu.Tests.cs @@ -243,7 +243,7 @@ public void Write_LinkEntry_EmptyLinkName_Throws(TarEntryType entryType) { using MemoryStream archiveStream = new MemoryStream(); using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - Assert.Throws(() => writer.WriteEntry(new GnuTarEntry(entryType, "link"))); + Assert.Throws("entry", () => writer.WriteEntry(new GnuTarEntry(entryType, "link"))); } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Pax.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Pax.Tests.cs index 354d3e9a5b1214..1e81fb7b1e8a01 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Pax.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Pax.Tests.cs @@ -493,7 +493,7 @@ public void Write_LinkEntry_EmptyLinkName_Throws(TarEntryType entryType) { using MemoryStream archiveStream = new MemoryStream(); using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - Assert.Throws(() => writer.WriteEntry(new PaxTarEntry(entryType, "link"))); + Assert.Throws("entry", () => writer.WriteEntry(new PaxTarEntry(entryType, "link"))); } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Ustar.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Ustar.Tests.cs index 0f3cd7c3361e55..c1f2d07562d388 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Ustar.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.Ustar.Tests.cs @@ -160,7 +160,7 @@ public void Write_LinkEntry_EmptyLinkName_Throws(TarEntryType entryType) { using MemoryStream archiveStream = new MemoryStream(); using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - Assert.Throws(() => writer.WriteEntry(new UstarTarEntry(entryType, "link"))); + Assert.Throws("entry", () => writer.WriteEntry(new UstarTarEntry(entryType, "link"))); } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.V7.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.V7.Tests.cs index 94843b3ca68a7f..51be90c74b07c9 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.V7.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntry.Entry.V7.Tests.cs @@ -100,7 +100,7 @@ public void Write_LinkEntry_EmptyLinkName_Throws(TarEntryType entryType) { using MemoryStream archiveStream = new MemoryStream(); using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - Assert.Throws(() => writer.WriteEntry(new V7TarEntry(entryType, "link"))); + Assert.Throws("entry", () => writer.WriteEntry(new V7TarEntry(entryType, "link"))); } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Gnu.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Gnu.Tests.cs index eb7a0b013758a8..1e77e548d4a6f7 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Gnu.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Gnu.Tests.cs @@ -264,7 +264,7 @@ public async Task Write_LinkEntry_EmptyLinkName_Throws_Async(TarEntryType entryT { await using MemoryStream archiveStream = new MemoryStream(); await using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new GnuTarEntry(entryType, "link"))); + await Assert.ThrowsAsync("entry", () => writer.WriteEntryAsync(new GnuTarEntry(entryType, "link"))); } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Pax.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Pax.Tests.cs index 6de27adb92d61d..b0c9d636420b52 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Pax.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Pax.Tests.cs @@ -513,7 +513,7 @@ public async Task Write_LinkEntry_EmptyLinkName_Throws_Async(TarEntryType entryT { await using MemoryStream archiveStream = new MemoryStream(); await using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new PaxTarEntry(entryType, "link"))); + await Assert.ThrowsAsync("entry", () => writer.WriteEntryAsync(new PaxTarEntry(entryType, "link"))); } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Ustar.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Ustar.Tests.cs index ba12d52f06fada..b3e207d434f78e 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Ustar.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.Ustar.Tests.cs @@ -161,7 +161,7 @@ public async Task Write_LinkEntry_EmptyLinkName_Throws_Async(TarEntryType entryT { await using MemoryStream archiveStream = new MemoryStream(); await using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new UstarTarEntry(entryType, "link"))); + await Assert.ThrowsAsync("entry", () => writer.WriteEntryAsync(new UstarTarEntry(entryType, "link"))); } } } diff --git a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.V7.Tests.cs b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.V7.Tests.cs index fddc39b976c94f..3e41f263ef02e4 100644 --- a/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.V7.Tests.cs +++ b/src/libraries/System.Formats.Tar/tests/TarWriter/TarWriter.WriteEntryAsync.Entry.V7.Tests.cs @@ -101,7 +101,7 @@ public async Task Write_LinkEntry_EmptyLinkName_Throws_Async(TarEntryType entryT { await using MemoryStream archiveStream = new MemoryStream(); await using TarWriter writer = new TarWriter(archiveStream, leaveOpen: false); - await Assert.ThrowsAsync(async () => await writer.WriteEntryAsync(new V7TarEntry(entryType, "link"))); + await Assert.ThrowsAsync("entry", () => writer.WriteEntryAsync(new V7TarEntry(entryType, "link"))); } } }