Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortriton <joao@tritao.eu>2015-09-04 17:17:17 +0300
committertriton <joao@tritao.eu>2015-09-04 17:17:17 +0300
commit5a422039ecf77a3d8c963e273c68b5c3e7c03bd8 (patch)
tree29e3c9ace3321502a69b656b741d1b64c2940146 /mcs/class/System.IO.Compression
parent6df3a3d4c02677130b135a8c646c31829ac4655a (diff)
[System.IO.Compression] Fixed handling of empty Zip archives in Update mode. Fixes bug #32725.
https://bugzilla.xamarin.com/show_bug.cgi?id=32725
Diffstat (limited to 'mcs/class/System.IO.Compression')
-rw-r--r--mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs11
-rw-r--r--mcs/class/System.IO.Compression/ZipArchive.cs6
2 files changed, 14 insertions, 3 deletions
diff --git a/mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs b/mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs
index 478af95dbeb..eacf2f6b3dd 100644
--- a/mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs
+++ b/mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs
@@ -251,5 +251,16 @@ namespace MonoTests.System.IO.Compression
File.Delete ("test.zip");
}
+
+ [Test]
+ public void ZipUpdateEmptyArchive()
+ {
+ File.WriteAllText("empty.zip", string.Empty);
+ using (var archive = new ZipArchive(File.Open("empty.zip", FileMode.Open),
+ ZipArchiveMode.Update))
+ {
+ }
+ File.Delete ("empty.zip");
+ }
}
}
diff --git a/mcs/class/System.IO.Compression/ZipArchive.cs b/mcs/class/System.IO.Compression/ZipArchive.cs
index 411aadc930f..b2d6e2f4bfe 100644
--- a/mcs/class/System.IO.Compression/ZipArchive.cs
+++ b/mcs/class/System.IO.Compression/ZipArchive.cs
@@ -103,9 +103,9 @@ namespace System.IO.Compression
throw new ArgumentException("Stream must support reading, writing and seeking for Update archive mode");
try {
- zipFile = mode == ZipArchiveMode.Create ?
- SharpCompress.Archive.Zip.ZipArchive.Create() :
- SharpCompress.Archive.Zip.ZipArchive.Open(stream);
+ zipFile = mode != ZipArchiveMode.Create && stream.Length != 0
+ ? SharpCompress.Archive.Zip.ZipArchive.Open(stream)
+ : SharpCompress.Archive.Zip.ZipArchive.Create();
} catch (Exception e) {
throw new InvalidDataException("The contents of the stream are not in the zip archive format.", e);
}