Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/ICSharpCode.SharpZipLib/Zip/ZipInputStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,9 @@ public ZipEntry GetNextEntry()

string name = ZipStrings.ConvertToStringExt(flags, buffer);

entry = new ZipEntry(name, versionRequiredToExtract)
entry = new ZipEntry(name, versionRequiredToExtract, ZipConstants.VersionMadeBy, (CompressionMethod)method)
{
Flags = flags,
CompressionMethod = (CompressionMethod)method
};

if ((flags & 8) == 0)
Expand Down
28 changes: 28 additions & 0 deletions test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,5 +324,33 @@ public void SingleLargeEntry()
}
);
}

const string BZip2CompressedZip =
"UEsDBC4AAAAMAEyxgU5p3ou9JwAAAAcAAAAFAAAAYS5kYXRCWmg5MUFZJlNZ0buMcAAAAkgACABA" +
"ACAAIQCCCxdyRThQkNG7jHBQSwECMwAuAAAADABMsYFOad6LvScAAAAHAAAABQAAAAAAAAAAAAAA" +
"AAAAAAAAYS5kYXRQSwUGAAAAAAEAAQAzAAAASgAAAAAA";

/// <summary>
/// Should fail to read a zip with BZip2 compression
/// </summary>
[Test]
[Category("Zip")]
public void ShouldReadBZip2EntryButNotDecompress()
{
var fileBytes = System.Convert.FromBase64String(BZip2CompressedZip);

using (var input = new MemoryStream(fileBytes, false))
{
var zis = new ZipInputStream(input);
var entry = zis.GetNextEntry();

Assert.That(entry.Name, Is.EqualTo("a.dat"), "Should be able to get entry name");
Assert.That(entry.CompressionMethod, Is.EqualTo(CompressionMethod.BZip2), "Entry should be BZip2 compressed");
Assert.That(zis.CanDecompressEntry, Is.False, "Should not be able to decompress BZip2 entry");

var buffer = new byte[1];
Assert.Throws<ZipException>(() => zis.Read(buffer, 0, 1), "Trying to read the stream should throw");
}
}
}
}