Skip to content

Commit babc5e7

Browse files
authored
Tar: Extra tests to confirm extra long paths are not treated as duplicate entries when the full path is in the extended attributes. (#78744)
Co-authored-by: carlossanlop <[email protected]>
1 parent 6a047a9 commit babc5e7

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/libraries/System.Formats.Tar/tests/TarFile/TarFile.ExtractToDirectory.Stream.Tests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,32 @@ public void Extract_UnseekableStream_BlockAlignmentPadding_DoesNotAffectNextEntr
177177

178178
Assert.Equal(2, Directory.GetFileSystemEntries(destination.Path, "*", SearchOption.AllDirectories).Count());
179179
}
180+
181+
[Fact]
182+
public void PaxNameCollision_DedupInExtendedAttributes()
183+
{
184+
using TempDirectory root = new();
185+
186+
string sharedRootFolders = Path.Join(root.Path, "folder with spaces", new string('a', 100));
187+
string path1 = Path.Join(sharedRootFolders, "entry 1 with spaces.txt");
188+
string path2 = Path.Join(sharedRootFolders, "entry 2 with spaces.txt");
189+
190+
using MemoryStream stream = new();
191+
using (TarWriter writer = new(stream, TarEntryFormat.Pax, leaveOpen: true))
192+
{
193+
// Paths don't fit in the standard 'name' field, but they differ in the filename,
194+
// which is fully stored as an extended attribute
195+
PaxTarEntry entry1 = new(TarEntryType.RegularFile, path1);
196+
writer.WriteEntry(entry1);
197+
PaxTarEntry entry2 = new(TarEntryType.RegularFile, path2);
198+
writer.WriteEntry(entry2);
199+
}
200+
stream.Position = 0;
201+
202+
TarFile.ExtractToDirectory(stream, root.Path, overwriteFiles: true);
203+
204+
Assert.True(File.Exists(path1));
205+
Assert.True(Path.Exists(path2));
206+
}
180207
}
181208
}

src/libraries/System.Formats.Tar/tests/TarFile/TarFile.ExtractToDirectoryAsync.Stream.Tests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,32 @@ public async Task Extract_UnseekableStream_BlockAlignmentPadding_DoesNotAffectNe
242242

243243
Assert.Equal(2, Directory.GetFileSystemEntries(destination.Path, "*", SearchOption.AllDirectories).Count());
244244
}
245+
246+
[Fact]
247+
public async Task PaxNameCollision_DedupInExtendedAttributesAsync()
248+
{
249+
using TempDirectory root = new();
250+
251+
string sharedRootFolders = Path.Join(root.Path, "folder with spaces", new string('a', 100));
252+
string path1 = Path.Join(sharedRootFolders, "entry 1 with spaces.txt");
253+
string path2 = Path.Join(sharedRootFolders, "entry 2 with spaces.txt");
254+
255+
await using MemoryStream stream = new();
256+
await using (TarWriter writer = new(stream, TarEntryFormat.Pax, leaveOpen: true))
257+
{
258+
// Paths don't fit in the standard 'name' field, but they differ in the filename,
259+
// which is fully stored as an extended attribute
260+
PaxTarEntry entry1 = new(TarEntryType.RegularFile, path1);
261+
await writer.WriteEntryAsync(entry1);
262+
PaxTarEntry entry2 = new(TarEntryType.RegularFile, path2);
263+
await writer.WriteEntryAsync(entry2);
264+
}
265+
stream.Position = 0;
266+
267+
await TarFile.ExtractToDirectoryAsync(stream, root.Path, overwriteFiles: true);
268+
269+
Assert.True(File.Exists(path1));
270+
Assert.True(Path.Exists(path2));
271+
}
245272
}
246273
}

0 commit comments

Comments
 (0)