Skip to content

Commit 0a5513d

Browse files
author
koeeenig
authored
Merge pull request #20 from icarus-consulting/i19-zippaths-crash
I19 zippaths crash
2 parents aa05c6e + 628877d commit 0a5513d

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

src/Yaapii.Zip/ZipPaths.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@ public ZipPaths(IInput input, bool leaveOpen = true)
3232
inputStream.Seek(0, SeekOrigin.Begin);
3333
inputStream.Flush();
3434
IEnumerable<string> files = new EnumerableOf<string>();
35-
using (var zip = new ZipArchive(inputStream, ZipArchiveMode.Read, leaveOpen))
35+
if(inputStream.Length > 0)
3636
{
37-
if (zip.Entries.Count > 0)
37+
using (var zip = new ZipArchive(inputStream, ZipArchiveMode.Read, leaveOpen))
3838
{
39-
files =
40-
new Mapped<ZipArchiveEntry, string>(entry =>
41-
entry.FullName,
42-
zip.Entries
43-
);
39+
if (zip.Entries.Count > 0)
40+
{
41+
files =
42+
new Mapped<ZipArchiveEntry, string>(entry =>
43+
entry.FullName,
44+
zip.Entries
45+
);
46+
}
4447
}
4548
}
4649
inputStream.Seek(0, SeekOrigin.Begin);

src/Yaapii.Zip/ZipUpdated.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ public ZipUpdated(IScalar<Stream> zip, string pathToUpdate, IInput update, bool
3434
{
3535
this.zip = new Solid<Stream>(() =>
3636
{
37-
new FailWhen(
38-
() => ExistsAndCrypted(new InputOf(zip.Value()), pathToUpdate),
39-
new InvalidOperationException(
40-
$"Cannot update '{pathToUpdate}' because the file is password protected"
41-
)
42-
).Go();
43-
44-
lock (zip.Value())
37+
var stream = zip.Value();
38+
lock (stream)
4539
{
46-
var stream = zip.Value();
40+
new FailWhen(
41+
() => ExistsAndCrypted(new InputOf(stream), pathToUpdate),
42+
new InvalidOperationException(
43+
$"Cannot update '{pathToUpdate}' because the file is password protected"
44+
)
45+
).Go();
46+
4747
stream.Seek(0, SeekOrigin.Begin);
4848
using (var archive = new ZipArchive(stream, ZipArchiveMode.Update, leaveOpen))
4949
{

tests/Test.Yaapii.Zip/ZipPathsTests.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System.IO;
2+
using System.Threading.Tasks;
23
using Xunit;
34
using Yaapii.Atoms.IO;
45

@@ -96,5 +97,17 @@ public void ListsAllPathsFromWindowsZip()
9697
).Value()
9798
);
9899
}
100+
101+
[Fact]
102+
public void EmptyFilesOnEmptyStream()
103+
{
104+
Assert.Empty(
105+
new ZipPaths(
106+
new InputOf(
107+
new MemoryStream()
108+
)
109+
)
110+
);
111+
}
99112
}
100113
}

0 commit comments

Comments
 (0)