From 8eea2cef9792dfa9632138371b103b64431f2aa9 Mon Sep 17 00:00:00 2001 From: Morilli <35152647+Morilli@users.noreply.github.com> Date: Thu, 21 Aug 2025 19:51:09 +0200 Subject: [PATCH 1/2] add failing test --- tests/SharpCompress.Test/Zip/ZipReaderTests.cs | 17 +++++++++++++++++ .../Archives/Zip.none.encrypted.zip | Bin 0 -> 780 bytes 2 files changed, 17 insertions(+) create mode 100644 tests/TestArchives/Archives/Zip.none.encrypted.zip diff --git a/tests/SharpCompress.Test/Zip/ZipReaderTests.cs b/tests/SharpCompress.Test/Zip/ZipReaderTests.cs index f8d69d6d..835521e0 100644 --- a/tests/SharpCompress.Test/Zip/ZipReaderTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipReaderTests.cs @@ -379,4 +379,21 @@ public class ZipReaderTests : ReaderTests Assert.Equal(4, x); } + + [Fact] + public void Zip_Uncompressed_Encrypted_Read() + { + using var archive = ArchiveFactory.Open( + Path.Combine(TEST_ARCHIVES_PATH, "Zip.none.encrypted.zip"), + new ReaderOptions { Password = "test" } + ); + using var reader = archive.ExtractAllEntries(); + reader.MoveToNextEntry(); + Assert.Equal("first.txt", reader.Entry.Key); + Assert.Equal(199, reader.Entry.Size); + reader.OpenEntryStream().Dispose(); + reader.MoveToNextEntry(); + Assert.Equal("second.txt", reader.Entry.Key); + Assert.Equal(197, reader.Entry.Size); + } } diff --git a/tests/TestArchives/Archives/Zip.none.encrypted.zip b/tests/TestArchives/Archives/Zip.none.encrypted.zip new file mode 100644 index 0000000000000000000000000000000000000000..915a2be85b7b190b8eb2927d3115fd09e4a609a5 GIT binary patch literal 780 zcmWIWW@a&FU}Q*U*wnDrkAZ=K;V}aP!*K=%22KWUhP2G0;u5`*iW0_|>R8L$@1O${ars(UvS^;TA&(MxOe@B zCWncdENNOtQyVTvWgS}4E^(fHx!i14_f292C)TvAh~5&xH^J!U&*DB|kMmL+vumo4 zX|?X<2?+b!WTDd1VVxRz|4L)h#4OXq!xg(Sr(DgcjbM0~5yY>2H|?1ER!tV=D~xOM zm$2S6teJB!u+MhCg3emAiDiwqR$gCnL(cNXq&7!HpzMGK%0mVQhNBD&3|tJ{48^I* z`FSa5p^~nnoHNbuNwntS&)-`$)40ME{XTJT&k*6geEOVvThA?Pt62Vr*Y72*VDM+$ z7kq*J;G2hMuKhbZ<>8testPeNf6_U|?u~ z((r`C#h?HdVq}nDXn3gqehTMRMz8=9ft0wAZNUtCWLrcT8IWQE#hUkF-w0a6$_8=( Q69W^&Sq26MO(qZz0MDEf(*OVf literal 0 HcmV?d00001 From 9f306966db094738a4dcee014720079fa01494f3 Mon Sep 17 00:00:00 2001 From: Morilli <35152647+Morilli@users.noreply.github.com> Date: Thu, 21 Aug 2025 19:55:35 +0200 Subject: [PATCH 2/2] Adjust logic in CreateDecompressionStream to not wrap the returned stream a ReadOnlySubStream never disposes its passes in stream which is problematic when that stream needs to be disposed. It's hard to tell who exactly has ownership over which stream here, but I'll just assume that whatever stream is passed in here should be disposed. --- src/SharpCompress/Common/Zip/ZipFilePart.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/SharpCompress/Common/Zip/ZipFilePart.cs b/src/SharpCompress/Common/Zip/ZipFilePart.cs index f8fd6cd5..77dc4abb 100644 --- a/src/SharpCompress/Common/Zip/ZipFilePart.cs +++ b/src/SharpCompress/Common/Zip/ZipFilePart.cs @@ -70,17 +70,12 @@ internal abstract class ZipFilePart : FilePart { case ZipCompressionMethod.None: { - if (stream is ReadOnlySubStream) + if (Header.CompressedSize is 0) { - return stream; + return new DataDescriptorStream(stream); } - if (Header.CompressedSize > 0) - { - return new ReadOnlySubStream(stream, Header.CompressedSize); - } - - return new DataDescriptorStream(stream); + return stream; } case ZipCompressionMethod.Shrink: {