Skip to content

Commit

Permalink
Fixed a NRE when matching an Open Office XML format
Browse files Browse the repository at this point in the history
  • Loading branch information
neilharvey committed Sep 26, 2019
1 parent b0598b0 commit f17f4cb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/FileSignatures/FileSignatures.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Version>3.0.0</Version>
<Version>3.0.1</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AssemblyVersion>3.0.1.0</AssemblyVersion>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' Or '$(TargetFramework)' == 'netstandard2.0' ">
Expand Down
5 changes: 4 additions & 1 deletion src/FileSignatures/Formats/OfficeOpenXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ public override bool IsMatch(byte[] header)
}
finally
{
archive.Dispose();
if(archive != null)
{
archive.Dispose();
}
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions test/FileSignatures.Tests/Formats/OfficeOpenXmlTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using FileSignatures.Formats;
using System.IO;
using Xunit;

namespace FileSignatures.Tests.Formats
{
public class OfficeOpenXmlTests
{
[Fact]
public void InvalidZipArchive_DoesNotThrow()
{
var inspector = new FileFormatInspector();

using (var stream = new MemoryStream(new byte[] { 0x50, 0x4B, 0x03, 0x04 }))
{
var format = inspector.DetermineFileFormat(stream);

Assert.NotNull(format);
Assert.IsType<Zip>(format);
}
}
}
}

1 comment on commit f17f4cb

@neilharvey
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #18

Please sign in to comment.