diff --git a/test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs b/test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs
index 21c3eacbd..bcabf1c86 100644
--- a/test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs
+++ b/test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs
@@ -2,6 +2,7 @@
using ICSharpCode.SharpZipLib.Tests.TestSupport;
using ICSharpCode.SharpZipLib.Zip;
using NUnit.Framework;
+using System;
using System.IO;
namespace ICSharpCode.SharpZipLib.Tests.Zip
@@ -191,6 +192,49 @@ public void EmptyZipEntries()
Assert.AreEqual(extractCount, 0, "No data should be read from empty entries");
}
+ ///
+ /// Test that calling Write with 0 bytes behaves.
+ /// See issue @ https://github.com/icsharpcode/SharpZipLib/issues/123.
+ ///
+ [Test]
+ [Category("Zip")]
+ public void TestZeroByteWrite()
+ {
+ using (var ms = new MemoryStreamWithoutSeek())
+ {
+ using (var outStream = new ZipOutputStream(ms) { IsStreamOwner = false })
+ {
+ var ze = new ZipEntry("Striped Marlin");
+ outStream.PutNextEntry(ze);
+
+ var buffer = Array.Empty();
+ outStream.Write(buffer, 0, 0);
+ }
+
+ ms.Seek(0, SeekOrigin.Begin);
+
+ using (var inStream = new ZipInputStream(ms) { IsStreamOwner = false })
+ {
+ int extractCount = 0;
+ byte[] decompressedData = new byte[100];
+
+ while (inStream.GetNextEntry() != null)
+ {
+ while (true)
+ {
+ int numRead = inStream.Read(decompressedData, extractCount, decompressedData.Length);
+ if (numRead <= 0)
+ {
+ break;
+ }
+ extractCount += numRead;
+ }
+ }
+ Assert.Zero(extractCount, "No data should be read from empty entries");
+ }
+ }
+ }
+
[Test]
[Category("Zip")]
public void WriteZipStreamWithNoCompression([Values(0, 1, 256)] int contentLength)