diff --git a/tests/SharpCompress.Test/Zip/ZipReaderAsyncTests.cs b/tests/SharpCompress.Test/Zip/ZipReaderAsyncTests.cs index c4c5bb3a..aaa345ad 100644 --- a/tests/SharpCompress.Test/Zip/ZipReaderAsyncTests.cs +++ b/tests/SharpCompress.Test/Zip/ZipReaderAsyncTests.cs @@ -337,4 +337,52 @@ public class ZipReaderAsyncTests : ReaderTests } } } + + [Fact] + public async ValueTask Archive_Iteration_DoesNotBreak_WhenFlushThrows_Deflate_Async() + { + // Regression test: since 0.41.0, archive iteration would silently break + // when the input stream throws NotSupportedException in Flush(). + // Only the first entry would be returned, then iteration would stop without exception. + var path = Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip"); + using var fileStream = File.OpenRead(path); + using Stream stream = new ThrowOnFlushStream(fileStream); + await using var reader = ReaderFactory.OpenAsyncReader(new AsyncOnlyStream(stream)); + + var count = 0; + while (await reader.MoveToNextEntryAsync()) + { + if (!reader.Entry.IsDirectory) + { + count++; + } + } + + // Should iterate through all entries, not just the first one + Assert.True(count > 1, $"Expected more than 1 entry, but got {count}"); + } + + [Fact] + public async ValueTask Archive_Iteration_DoesNotBreak_WhenFlushThrows_LZMA_Async() + { + // Regression test: since 0.41.0, archive iteration would silently break + // when the input stream throws NotSupportedException in Flush(). + // Only the first entry would be returned, then iteration would stop without exception. + var path = Path.Combine(TEST_ARCHIVES_PATH, "Zip.lzma.dd.zip"); + using var fileStream = File.OpenRead(path); + using Stream stream = new ThrowOnFlushStream(fileStream); + await using var reader = ReaderFactory.OpenAsyncReader(new AsyncOnlyStream(stream)); + + var count = 0; + while (await reader.MoveToNextEntryAsync()) + { + if (!reader.Entry.IsDirectory) + { + count++; + } + } + + // Should iterate through all entries, not just the first one + Assert.True(count > 1, $"Expected more than 1 entry, but got {count}"); + } }