Skip to content

Commit

Permalink
Merge branch 'master' into feat/opt-ziptest
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed Apr 28, 2022
2 parents a7af855 + aee3b44 commit fc92777
Show file tree
Hide file tree
Showing 20 changed files with 68 additions and 39 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ on:

jobs:
Build:
runs-on: ${{ matrix.os }}-latest
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu, windows, macos]
os: [ubuntu-latest, windows-2019, macos-latest]
target: [netstandard2.0, netstandard2.1]
include:
- os: windows
- os: windows-2019
target: net45
env:
LIB_PROJ: src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj
Expand All @@ -35,6 +35,9 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: '3.1.x'

- name: Show .NET info
run: dotnet --info

- name: Build library (Debug)
run: dotnet build -c debug -f ${{ matrix.target }} ${{ env.LIB_PROJ }}
Expand Down Expand Up @@ -73,7 +76,7 @@ jobs:

CodeCov:
name: Code Coverage
runs-on: windows-latest
runs-on: windows-2019
env:
DOTCOVER_VER: 2021.1.2
DOTCOVER_PKG: jetbrains.dotcover.commandlinetools
Expand Down Expand Up @@ -117,7 +120,7 @@ jobs:

Pack:
needs: [Build, Test, CodeCov]
runs-on: windows-latest
runs-on: windows-2019
env:
PKG_SUFFIX: ''
PKG_PROJ: src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SharpZipLib [![Build Status](https://github.com/icsharpcode/SharpZipLib/actions/workflows/build-test.yml/badge.svg?branch=master)](https://github.com/icsharpcode/SharpZipLib/actions/workflows/build-test.yml) [![NuGet Version](https://img.shields.io/nuget/v/SharpZipLib.svg)](https://www.nuget.org/packages/SharpZipLib/)
# SharpZipLib [![Build Status](https://github.com/icsharpcode/SharpZipLib/actions/workflows/build-test.yml/badge.svg?branch=master)](https://github.com/icsharpcode/SharpZipLib/actions/workflows/build-test.yml) [![NuGet Version](https://img.shields.io/nuget/v/SharpZipLib.svg)](https://www.nuget.org/packages/SharpZipLib/) [![openupm](https://img.shields.io/npm/v/org.icsharpcode.sharpziplib?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/org.icsharpcode.sharpziplib/)

Introduction
------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ copy Cmd_BZip2.exe bunzip2.exe</PostBuildEvent>
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ copy Cmd_GZip.exe gunzip.exe</PostBuildEvent>
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
Expand Down
2 changes: 1 addition & 1 deletion samples/ICSharpCode.SharpZipLib.Samples/cs/sz/sz.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
2 changes: 1 addition & 1 deletion samples/ICSharpCode.SharpZipLib.Samples/cs/zf/zf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
<PackageReference Include="WPFFolderBrowser">
<Version>1.0.2</Version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="SharpZipLib">
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
Expand Down
24 changes: 24 additions & 0 deletions src/ICSharpCode.SharpZipLib/Zip/ZipConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,28 @@ public static class ZipConstants

#endregion Header Signatures
}

/// <summary>
/// GeneralBitFlags helper extensions
/// </summary>
public static class GenericBitFlagsExtensions
{
/// <summary>
/// Efficiently check if any of the <see cref="GeneralBitFlags">flags</see> are set without enum un-/boxing
/// </summary>
/// <param name="target"></param>
/// <param name="flags"></param>
/// <returns>Returns whether any of flags are set</returns>
public static bool HasAny(this GeneralBitFlags target, GeneralBitFlags flags)
=> ((int)target & (int)flags) != 0;

/// <summary>
/// Efficiently check if all the <see cref="GeneralBitFlags">flags</see> are set without enum un-/boxing
/// </summary>
/// <param name="target"></param>
/// <param name="flags"></param>
/// <returns>Returns whether the flags are all set</returns>
public static bool HasAll(this GeneralBitFlags target, GeneralBitFlags flags)
=> ((int)target & (int)flags) == (int)flags;
}
}
36 changes: 19 additions & 17 deletions src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,15 +1142,15 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
size = localExtraData.ReadLong();
compressedSize = localExtraData.ReadLong();

if (localFlags.Includes(GeneralBitFlags.Descriptor))
if (localFlags.HasAny(GeneralBitFlags.Descriptor))
{
// These may be valid if patched later
if ((size != -1) && (size != entry.Size))
if ((size > 0) && (size != entry.Size))
{
throw new ZipException("Size invalid for descriptor");
}

if ((compressedSize != -1) && (compressedSize != entry.CompressedSize))
if ((compressedSize > 0) && (compressedSize != entry.CompressedSize))
{
throw new ZipException("Compressed size invalid for descriptor");
}
Expand Down Expand Up @@ -1181,9 +1181,11 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
throw new ZipException($"Version required to extract this entry not supported ({extractVersion})");
}

const GeneralBitFlags notSupportedFlags = GeneralBitFlags.Patched | GeneralBitFlags.StrongEncryption |
GeneralBitFlags.EnhancedCompress | GeneralBitFlags.HeaderMasked;
if (localFlags.Includes(notSupportedFlags))
const GeneralBitFlags notSupportedFlags = GeneralBitFlags.Patched
| GeneralBitFlags.StrongEncryption
| GeneralBitFlags.EnhancedCompress
| GeneralBitFlags.HeaderMasked;
if (localFlags.HasAny(notSupportedFlags))
{
throw new ZipException($"The library does not support the zip features required to extract this entry ({localFlags & notSupportedFlags:F})");
}
Expand Down Expand Up @@ -1215,21 +1217,21 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
var localEncoding = _stringCodec.ZipInputEncoding(localFlags);

// Local entry flags dont have reserved bit set on.
if (localFlags.Includes(GeneralBitFlags.ReservedPKware4 | GeneralBitFlags.ReservedPkware14 | GeneralBitFlags.ReservedPkware15))
if (localFlags.HasAny(GeneralBitFlags.ReservedPKware4 | GeneralBitFlags.ReservedPkware14 | GeneralBitFlags.ReservedPkware15))
{
throw new ZipException("Reserved bit flags cannot be set.");
}

// Encryption requires extract version >= 20
if (localFlags.Includes(GeneralBitFlags.Encrypted) && extractVersion < 20)
if (localFlags.HasAny(GeneralBitFlags.Encrypted) && extractVersion < 20)
{
throw new ZipException($"Version required to extract this entry is too low for encryption ({extractVersion})");
}

// Strong encryption requires encryption flag to be set and extract version >= 50.
if (localFlags.Includes(GeneralBitFlags.StrongEncryption))
if (localFlags.HasAny(GeneralBitFlags.StrongEncryption))
{
if (!localFlags.Includes(GeneralBitFlags.Encrypted))
if (!localFlags.HasAny(GeneralBitFlags.Encrypted))
{
throw new ZipException("Strong encryption flag set but encryption flag is not set");
}
Expand All @@ -1241,13 +1243,13 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
}

// Patched entries require extract version >= 27
if (localFlags.Includes(GeneralBitFlags.Patched) && extractVersion < 27)
if (localFlags.HasAny(GeneralBitFlags.Patched) && extractVersion < 27)
{
throw new ZipException($"Patched data requires higher version than ({extractVersion})");
}

// Central header flags match local entry flags.
if (!localFlags.Equals((GeneralBitFlags)entry.Flags))
if ((int)localFlags != entry.Flags)
{
throw new ZipException($"Central header/local header flags mismatch ({(GeneralBitFlags)entry.Flags:F} vs {localFlags:F})");
}
Expand All @@ -1264,23 +1266,23 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
}

// Strong encryption and extract version match
if (localFlags.Includes(GeneralBitFlags.StrongEncryption))
if (localFlags.HasAny(GeneralBitFlags.StrongEncryption))
{
if (extractVersion < 62)
{
throw new ZipException("Strong encryption flag set but version not high enough");
}
}

if (localFlags.Includes(GeneralBitFlags.HeaderMasked))
if (localFlags.HasAny(GeneralBitFlags.HeaderMasked))
{
if (fileTime != 0 || fileDate != 0)
{
throw new ZipException("Header masked set but date/time values non-zero");
}
}

if (!localFlags.Includes(GeneralBitFlags.Descriptor))
if (!localFlags.HasAny(GeneralBitFlags.Descriptor))
{
if (crcValue != (uint)entry.Crc)
{
Expand Down Expand Up @@ -1350,7 +1352,7 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)

// Size can be verified only if it is known in the local header.
// it will always be known in the central header.
if (!localFlags.Includes(GeneralBitFlags.Descriptor) ||
if (!localFlags.HasAny(GeneralBitFlags.Descriptor) ||
((size > 0 || compressedSize > 0) && entry.Size > 0))
{
if (size != 0 && size != entry.Size)
Expand Down Expand Up @@ -2504,7 +2506,7 @@ private void CopyDescriptorBytes(ZipUpdate update, Stream dest, Stream source)
/// <returns>The descriptor size, zero if there isn't one.</returns>
private static int GetDescriptorSize(ZipUpdate update, bool includingSignature)
{
if (!((GeneralBitFlags)update.Entry.Flags).HasFlag(GeneralBitFlags.Descriptor))
if (!((GeneralBitFlags)update.Entry.Flags).HasAny(GeneralBitFlags.Descriptor))
return 0;

var descriptorWithSignature = update.Entry.LocalHeaderRequiresZip64
Expand Down

0 comments on commit fc92777

Please sign in to comment.