From 44021b7abc3e215c46ee1647863c91009d6779f7 Mon Sep 17 00:00:00 2001
From: Morilli <35152647+Morilli@users.noreply.github.com>
Date: Sat, 19 Jul 2025 19:30:52 +0200
Subject: [PATCH 1/3] fix DotSettings options to conform to current code style
and editorconfig
---
SharpCompress.sln.DotSettings | 25 +++++++++++++------------
1 file changed, 13 insertions(+), 12 deletions(-)
diff --git a/SharpCompress.sln.DotSettings b/SharpCompress.sln.DotSettings
index 4ff50910..e2f7e87f 100644
--- a/SharpCompress.sln.DotSettings
+++ b/SharpCompress.sln.DotSettings
@@ -15,17 +15,17 @@
Basic Clean
True
- Named
+ Positional
Required
Required
Required
Required
- True
+ False
True
True
- True
+ False
True
- True
+ False
True
True
True
@@ -42,7 +42,7 @@
ALWAYS_ADD
ALWAYS_ADD
ALWAYS_ADD
- True
+ False
1
1
NEVER
@@ -50,12 +50,12 @@
False
False
NEVER
- True
+ False
False
NEVER
- True
+ False
- True
+ False
LINE_BREAK
False
@@ -67,13 +67,13 @@
False
False
CHOP_IF_LONG
- CHOP_IF_LONG
+ CHOP_ALWAYS
CHOP_IF_LONG
False
CHOP_IF_LONG
- UseVarWhenEvident
- UseVarWhenEvident
- UseVarWhenEvident
+ UseVar
+ UseVar
+ UseVar
<Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" />
<Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" />
@@ -122,6 +122,7 @@
<Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" />
<Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
<Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" />
+
True
True
True
From d78a682dd8caf3a7cc9976863f408bd0d4c3f652 Mon Sep 17 00:00:00 2001
From: Morilli <35152647+Morilli@users.noreply.github.com>
Date: Sat, 19 Jul 2025 19:35:43 +0200
Subject: [PATCH 2/3] add failing test
---
tests/SharpCompress.Test/Zip/ZipArchiveTests.cs | 12 ++++++++++++
tests/TestArchives/Archives/Zip.EntryComment.zip | Bin 0 -> 194 bytes
2 files changed, 12 insertions(+)
create mode 100644 tests/TestArchives/Archives/Zip.EntryComment.zip
diff --git a/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs b/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs
index e678f29b..8b886afe 100644
--- a/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs
+++ b/tests/SharpCompress.Test/Zip/ZipArchiveTests.cs
@@ -820,4 +820,16 @@ public class ZipArchiveTests : ArchiveTests
using var _ = firstEntry.OpenEntryStream();
Assert.Equal(199, firstEntry.Size);
}
+
+ [Fact]
+ public void Zip_EntryCommentAfterEntryRead()
+ {
+ using var archive = ZipArchive.Open(
+ Path.Combine(TEST_ARCHIVES_PATH, "Zip.EntryComment.zip")
+ );
+ var firstEntry = archive.Entries.First();
+ Assert.Equal(29, firstEntry.Comment!.Length);
+ using var _ = firstEntry.OpenEntryStream();
+ Assert.Equal(29, firstEntry.Comment.Length);
+ }
}
diff --git a/tests/TestArchives/Archives/Zip.EntryComment.zip b/tests/TestArchives/Archives/Zip.EntryComment.zip
new file mode 100644
index 0000000000000000000000000000000000000000..7e4ab4198cb011094c354fe380876706848d2602
GIT binary patch
literal 194
zcmWIWW@h1H00F;wpQEBmr(NP_U|;}Y4h9B>lGNf7y^@NOkc`Y?h0J1wM1{1>oK(F4
zZ$>7223*=y7-T`_F(`mZgdto|5k>|H23GNZv#
Date: Sat, 19 Jul 2025 19:36:33 +0200
Subject: [PATCH 3/3] fix zipentry comment being lost after reading local entry
header
---
src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs | 2 --
.../Common/Zip/Headers/DirectoryEntryHeader.cs | 2 --
src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs | 2 ++
src/SharpCompress/Common/Zip/SeekableZipFilePart.cs | 10 ++--------
.../Common/Zip/SeekableZipHeaderFactory.cs | 5 +++++
src/SharpCompress/Common/Zip/ZipEntry.cs | 2 ++
6 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs b/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs
index f13faee7..4c980f91 100644
--- a/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs
+++ b/src/SharpCompress/Archives/Zip/ZipArchiveEntry.cs
@@ -18,6 +18,4 @@ public class ZipArchiveEntry : ZipEntry, IArchiveEntry
public bool IsComplete => true;
#endregion
-
- public string? Comment => ((SeekableZipFilePart)Parts.Single()).Comment;
}
diff --git a/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs b/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs
index 2b26d298..6ca248e4 100644
--- a/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs
+++ b/src/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs
@@ -128,6 +128,4 @@ internal class DirectoryEntryHeader : ZipFileEntry
public ushort InternalFileAttributes { get; set; }
public ushort DiskNumberStart { get; set; }
-
- public string? Comment { get; private set; }
}
diff --git a/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs b/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs
index 0570bf6d..6842cba6 100644
--- a/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs
+++ b/src/SharpCompress/Common/Zip/Headers/ZipFileEntry.cs
@@ -120,4 +120,6 @@ internal abstract class ZipFileEntry : ZipHeader
internal ZipFilePart? Part { get; set; }
internal bool IsZip64 => CompressedSize >= uint.MaxValue;
+
+ internal string? Comment { get; set; }
}
diff --git a/src/SharpCompress/Common/Zip/SeekableZipFilePart.cs b/src/SharpCompress/Common/Zip/SeekableZipFilePart.cs
index 54c4f527..e7572711 100644
--- a/src/SharpCompress/Common/Zip/SeekableZipFilePart.cs
+++ b/src/SharpCompress/Common/Zip/SeekableZipFilePart.cs
@@ -25,14 +25,8 @@ internal class SeekableZipFilePart : ZipFilePart
return base.GetCompressedStream();
}
- internal string? Comment => ((DirectoryEntryHeader)Header).Comment;
-
- private void LoadLocalHeader()
- {
- var hasData = Header.HasData;
- Header = _headerFactory.GetLocalHeader(BaseStream, ((DirectoryEntryHeader)Header));
- Header.HasData = hasData;
- }
+ private void LoadLocalHeader() =>
+ Header = _headerFactory.GetLocalHeader(BaseStream, (DirectoryEntryHeader)Header);
protected override Stream CreateBaseStream()
{
diff --git a/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs b/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs
index 816b0b67..e610c080 100644
--- a/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs
+++ b/src/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs
@@ -149,6 +149,11 @@ internal sealed class SeekableZipHeaderFactory : ZipHeaderFactory
{
throw new InvalidOperationException();
}
+
+ // populate fields only known from the DirectoryEntryHeader
+ localEntryHeader.HasData = directoryEntryHeader.HasData;
+ localEntryHeader.Comment = directoryEntryHeader.Comment;
+
if (FlagUtility.HasFlag(localEntryHeader.Flags, HeaderFlags.UsePostDataDescriptor))
{
localEntryHeader.Crc = directoryEntryHeader.Crc;
diff --git a/src/SharpCompress/Common/Zip/ZipEntry.cs b/src/SharpCompress/Common/Zip/ZipEntry.cs
index d8e947f8..c0b677d7 100644
--- a/src/SharpCompress/Common/Zip/ZipEntry.cs
+++ b/src/SharpCompress/Common/Zip/ZipEntry.cs
@@ -83,4 +83,6 @@ public class ZipEntry : Entry
public override bool IsSplitAfter => false;
internal override IEnumerable Parts => _filePart.Empty();
+
+ public string? Comment => _filePart?.Header.Comment;
}