From eb7e55ac7d20970589006f68f118d71576d06af9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 10:08:28 +0000 Subject: [PATCH 1/4] Initial plan From 31c6eb3b5c300fc80cb27f7685a80f7fa222f973 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 14 Feb 2026 10:14:01 +0000 Subject: [PATCH 2/4] Fix NullReferenceException for 7z empty-stream entries Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com> --- .../Archives/SevenZip/SevenZipArchive.cs | 6 +++ src/SharpCompress/packages.lock.json | 12 +++--- .../SevenZip/SevenZipArchiveTests.cs | 35 ++++++++++++++++++ .../TestArchives/Archives/7Zip.EmptyStream.7z | Bin 0 -> 182 bytes 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 tests/TestArchives/Archives/7Zip.EmptyStream.7z diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs index de0adc98..710e490c 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs @@ -164,6 +164,12 @@ public partial class SevenZipArchive : AbstractArchive6hN#I(`FTQF&0_{XUN6Ij?Z(QdX zWc2P`W7owAJ3LISzu%dx-?f2LyTFp;hI0EGDbpai6EiJe2KZ^pM>R7sh_f*;a+Wf% eb2Bn9Dl;=Ovc@t9Ffi~ma&a-LKCO7czyJW@x Date: Sat, 14 Feb 2026 10:15:55 +0000 Subject: [PATCH 3/4] Improve empty-stream test to verify HasStream == false entries Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com> --- .../SevenZip/SevenZipArchiveTests.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs b/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs index 9947168e..0b77c040 100644 --- a/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs +++ b/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs @@ -4,6 +4,7 @@ using System.Linq; using SharpCompress.Archives; using SharpCompress.Archives.SevenZip; using SharpCompress.Common; +using SharpCompress.Common.SevenZip; using SharpCompress.Factories; using SharpCompress.Readers; using Xunit; @@ -355,15 +356,29 @@ public class SevenZipArchiveTests : ArchiveTests var testArchive = Path.Combine(TEST_ARCHIVES_PATH, "7Zip.EmptyStream.7z"); using var archive = SevenZipArchive.OpenArchive(testArchive); + var emptyStreamFileCount = 0; foreach (var entry in archive.Entries) { if (!entry.IsDirectory) { + // Verify this is actually an empty-stream entry (HasStream == false) + var sevenZipEntry = entry as SevenZipEntry; + if (sevenZipEntry?.FilePart.Header.HasStream == false) + { + emptyStreamFileCount++; + } + // This should not throw NullReferenceException entry.WriteToDirectory(SCRATCH_FILES_PATH); } } + // Ensure we actually tested empty-stream entries + Assert.True( + emptyStreamFileCount > 0, + "Test archive should contain at least one empty-stream entry" + ); + // Verify that empty files were created var extractedFiles = Directory.GetFiles( SCRATCH_FILES_PATH, From 13fdb4d7ca31d3d5d954cf6f39eef9d5b5989c51 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Sat, 14 Feb 2026 10:34:12 +0000 Subject: [PATCH 4/4] add better length from master --- src/SharpCompress/IO/SharpCompressStream.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/SharpCompress/IO/SharpCompressStream.cs b/src/SharpCompress/IO/SharpCompressStream.cs index b47b7031..a7c09072 100644 --- a/src/SharpCompress/IO/SharpCompressStream.cs +++ b/src/SharpCompress/IO/SharpCompressStream.cs @@ -206,8 +206,22 @@ internal partial class SharpCompressStream : Stream, IStreamStack throw new NotSupportedException(); } - public override long Length => - _isPassthrough ? stream.Length : throw new NotSupportedException(); + public override long Length + { + get + { + if (_isPassthrough) + { + return stream.Length; + } + + if (_ringBuffer is not null) + { + return _ringBuffer.Length; + } + throw new NotSupportedException(); + } + } public override long Position {