diff options
author | triton <joao@tritao.eu> | 2015-09-04 17:17:17 +0300 |
---|---|---|
committer | triton <joao@tritao.eu> | 2015-09-04 17:17:17 +0300 |
commit | 5a422039ecf77a3d8c963e273c68b5c3e7c03bd8 (patch) | |
tree | 29e3c9ace3321502a69b656b741d1b64c2940146 /mcs | |
parent | 6df3a3d4c02677130b135a8c646c31829ac4655a (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')
-rw-r--r-- | mcs/class/System.IO.Compression/Test/System.IO.Compression/ZipTest.cs | 11 | ||||
-rw-r--r-- | mcs/class/System.IO.Compression/ZipArchive.cs | 6 |
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); } |