Skip to content

Commit fc92777

Browse files
committed
Merge branch 'master' into feat/opt-ziptest
2 parents a7af855 + aee3b44 commit fc92777

File tree

20 files changed

+68
-39
lines changed

20 files changed

+68
-39
lines changed

.github/workflows/build-test.yml

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ on:
1414

1515
jobs:
1616
Build:
17-
runs-on: ${{ matrix.os }}-latest
17+
runs-on: ${{ matrix.os }}
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
os: [ubuntu, windows, macos]
21+
os: [ubuntu-latest, windows-2019, macos-latest]
2222
target: [netstandard2.0, netstandard2.1]
2323
include:
24-
- os: windows
24+
- os: windows-2019
2525
target: net45
2626
env:
2727
LIB_PROJ: src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj
@@ -35,6 +35,9 @@ jobs:
3535
uses: actions/setup-dotnet@v1
3636
with:
3737
dotnet-version: '3.1.x'
38+
39+
- name: Show .NET info
40+
run: dotnet --info
3841

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

7477
CodeCov:
7578
name: Code Coverage
76-
runs-on: windows-latest
79+
runs-on: windows-2019
7780
env:
7881
DOTCOVER_VER: 2021.1.2
7982
DOTCOVER_PKG: jetbrains.dotcover.commandlinetools
@@ -117,7 +120,7 @@ jobs:
117120

118121
Pack:
119122
needs: [Build, Test, CodeCov]
120-
runs-on: windows-latest
123+
runs-on: windows-2019
121124
env:
122125
PKG_SUFFIX: ''
123126
PKG_PROJ: src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 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/)
1+
# 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/)
22

33
Introduction
44
------------

samples/ICSharpCode.SharpZipLib.Samples/cs/Cmd_BZip2/Cmd_BZip2.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ copy Cmd_BZip2.exe bunzip2.exe</PostBuildEvent>
101101
</ItemGroup>
102102
<ItemGroup>
103103
<PackageReference Include="SharpZipLib">
104-
<Version>1.3.1</Version>
104+
<Version>1.3.3</Version>
105105
</PackageReference>
106106
</ItemGroup>
107107
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />

samples/ICSharpCode.SharpZipLib.Samples/cs/Cmd_Checksum/Cmd_Checksum.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
</ItemGroup>
101101
<ItemGroup>
102102
<PackageReference Include="SharpZipLib">
103-
<Version>1.3.1</Version>
103+
<Version>1.3.3</Version>
104104
</PackageReference>
105105
</ItemGroup>
106106
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />

samples/ICSharpCode.SharpZipLib.Samples/cs/Cmd_GZip/Cmd_GZip.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ copy Cmd_GZip.exe gunzip.exe</PostBuildEvent>
100100
</ItemGroup>
101101
<ItemGroup>
102102
<PackageReference Include="SharpZipLib">
103-
<Version>1.3.1</Version>
103+
<Version>1.3.3</Version>
104104
</PackageReference>
105105
</ItemGroup>
106106
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />

samples/ICSharpCode.SharpZipLib.Samples/cs/Cmd_Tar/Cmd_Tar.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
</ItemGroup>
9292
<ItemGroup>
9393
<PackageReference Include="SharpZipLib">
94-
<Version>1.3.1</Version>
94+
<Version>1.3.3</Version>
9595
</PackageReference>
9696
</ItemGroup>
9797
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />

samples/ICSharpCode.SharpZipLib.Samples/cs/Cmd_ZipInfo/Cmd_ZipInfo.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
</ItemGroup>
100100
<ItemGroup>
101101
<PackageReference Include="SharpZipLib">
102-
<Version>1.3.1</Version>
102+
<Version>1.3.3</Version>
103103
</PackageReference>
104104
</ItemGroup>
105105
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />

samples/ICSharpCode.SharpZipLib.Samples/cs/CreateZipFile/CreateZipFile.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
</ItemGroup>
108108
<ItemGroup>
109109
<PackageReference Include="SharpZipLib">
110-
<Version>1.3.1</Version>
110+
<Version>1.3.3</Version>
111111
</PackageReference>
112112
</ItemGroup>
113113
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />

samples/ICSharpCode.SharpZipLib.Samples/cs/FastZip/FastZip.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
</ItemGroup>
9191
<ItemGroup>
9292
<PackageReference Include="SharpZipLib">
93-
<Version>1.3.1</Version>
93+
<Version>1.3.3</Version>
9494
</PackageReference>
9595
</ItemGroup>
9696
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />

samples/ICSharpCode.SharpZipLib.Samples/cs/sz/sz.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
</ItemGroup>
8686
<ItemGroup>
8787
<PackageReference Include="SharpZipLib">
88-
<Version>1.3.1</Version>
88+
<Version>1.3.3</Version>
8989
</PackageReference>
9090
</ItemGroup>
9191
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />

samples/ICSharpCode.SharpZipLib.Samples/cs/unzipfile/unzipfile.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
</ItemGroup>
6262
<ItemGroup>
6363
<PackageReference Include="SharpZipLib">
64-
<Version>1.3.1</Version>
64+
<Version>1.3.3</Version>
6565
</PackageReference>
6666
</ItemGroup>
6767
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

samples/ICSharpCode.SharpZipLib.Samples/cs/viewzipfile/viewzipfile.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
</ItemGroup>
6262
<ItemGroup>
6363
<PackageReference Include="SharpZipLib">
64-
<Version>1.3.1</Version>
64+
<Version>1.3.3</Version>
6565
</PackageReference>
6666
</ItemGroup>
6767
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

samples/ICSharpCode.SharpZipLib.Samples/cs/zf/zf.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
</ItemGroup>
8686
<ItemGroup>
8787
<PackageReference Include="SharpZipLib">
88-
<Version>1.3.1</Version>
88+
<Version>1.3.3</Version>
8989
</PackageReference>
9090
</ItemGroup>
9191
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />

samples/ICSharpCode.SharpZipLib.Samples/vb/CreateZipFile/CreateZipFile.vbproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
</ItemGroup>
9696
<ItemGroup>
9797
<PackageReference Include="SharpZipLib">
98-
<Version>1.3.1</Version>
98+
<Version>1.3.3</Version>
9999
</PackageReference>
100100
</ItemGroup>
101101
<ItemGroup>

samples/ICSharpCode.SharpZipLib.Samples/vb/WpfCreateZipFile/WpfCreateZipFile.vbproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
</ItemGroup>
172172
<ItemGroup>
173173
<PackageReference Include="SharpZipLib">
174-
<Version>1.3.1</Version>
174+
<Version>1.3.3</Version>
175175
</PackageReference>
176176
<PackageReference Include="WPFFolderBrowser">
177177
<Version>1.0.2</Version>

samples/ICSharpCode.SharpZipLib.Samples/vb/minibzip2/minibzip2.vbproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
</ItemGroup>
113113
<ItemGroup>
114114
<PackageReference Include="SharpZipLib">
115-
<Version>1.3.1</Version>
115+
<Version>1.3.3</Version>
116116
</PackageReference>
117117
</ItemGroup>
118118
<ItemGroup>

samples/ICSharpCode.SharpZipLib.Samples/vb/viewzipfile/viewzipfile.vbproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
</ItemGroup>
9191
<ItemGroup>
9292
<PackageReference Include="SharpZipLib">
93-
<Version>1.3.1</Version>
93+
<Version>1.3.3</Version>
9494
</PackageReference>
9595
</ItemGroup>
9696
<ItemGroup>

samples/ICSharpCode.SharpZipLib.Samples/vb/zipfiletest/zipfiletest.vbproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
</ItemGroup>
101101
<ItemGroup>
102102
<PackageReference Include="SharpZipLib">
103-
<Version>1.3.1</Version>
103+
<Version>1.3.3</Version>
104104
</PackageReference>
105105
</ItemGroup>
106106
<ItemGroup>

src/ICSharpCode.SharpZipLib/Zip/ZipConstants.cs

+24
Original file line numberDiff line numberDiff line change
@@ -487,4 +487,28 @@ public static class ZipConstants
487487

488488
#endregion Header Signatures
489489
}
490+
491+
/// <summary>
492+
/// GeneralBitFlags helper extensions
493+
/// </summary>
494+
public static class GenericBitFlagsExtensions
495+
{
496+
/// <summary>
497+
/// Efficiently check if any of the <see cref="GeneralBitFlags">flags</see> are set without enum un-/boxing
498+
/// </summary>
499+
/// <param name="target"></param>
500+
/// <param name="flags"></param>
501+
/// <returns>Returns whether any of flags are set</returns>
502+
public static bool HasAny(this GeneralBitFlags target, GeneralBitFlags flags)
503+
=> ((int)target & (int)flags) != 0;
504+
505+
/// <summary>
506+
/// Efficiently check if all the <see cref="GeneralBitFlags">flags</see> are set without enum un-/boxing
507+
/// </summary>
508+
/// <param name="target"></param>
509+
/// <param name="flags"></param>
510+
/// <returns>Returns whether the flags are all set</returns>
511+
public static bool HasAll(this GeneralBitFlags target, GeneralBitFlags flags)
512+
=> ((int)target & (int)flags) == (int)flags;
513+
}
490514
}

src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs

+19-17
Original file line numberDiff line numberDiff line change
@@ -1142,15 +1142,15 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
11421142
size = localExtraData.ReadLong();
11431143
compressedSize = localExtraData.ReadLong();
11441144

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

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

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

12171219
// Local entry flags dont have reserved bit set on.
1218-
if (localFlags.Includes(GeneralBitFlags.ReservedPKware4 | GeneralBitFlags.ReservedPkware14 | GeneralBitFlags.ReservedPkware15))
1220+
if (localFlags.HasAny(GeneralBitFlags.ReservedPKware4 | GeneralBitFlags.ReservedPkware14 | GeneralBitFlags.ReservedPkware15))
12191221
{
12201222
throw new ZipException("Reserved bit flags cannot be set.");
12211223
}
12221224

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

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

12431245
// Patched entries require extract version >= 27
1244-
if (localFlags.Includes(GeneralBitFlags.Patched) && extractVersion < 27)
1246+
if (localFlags.HasAny(GeneralBitFlags.Patched) && extractVersion < 27)
12451247
{
12461248
throw new ZipException($"Patched data requires higher version than ({extractVersion})");
12471249
}
12481250

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

12661268
// Strong encryption and extract version match
1267-
if (localFlags.Includes(GeneralBitFlags.StrongEncryption))
1269+
if (localFlags.HasAny(GeneralBitFlags.StrongEncryption))
12681270
{
12691271
if (extractVersion < 62)
12701272
{
12711273
throw new ZipException("Strong encryption flag set but version not high enough");
12721274
}
12731275
}
12741276

1275-
if (localFlags.Includes(GeneralBitFlags.HeaderMasked))
1277+
if (localFlags.HasAny(GeneralBitFlags.HeaderMasked))
12761278
{
12771279
if (fileTime != 0 || fileDate != 0)
12781280
{
12791281
throw new ZipException("Header masked set but date/time values non-zero");
12801282
}
12811283
}
12821284

1283-
if (!localFlags.Includes(GeneralBitFlags.Descriptor))
1285+
if (!localFlags.HasAny(GeneralBitFlags.Descriptor))
12841286
{
12851287
if (crcValue != (uint)entry.Crc)
12861288
{
@@ -1350,7 +1352,7 @@ private long TestLocalHeader(ZipEntry entry, HeaderTest tests)
13501352

13511353
// Size can be verified only if it is known in the local header.
13521354
// it will always be known in the central header.
1353-
if (!localFlags.Includes(GeneralBitFlags.Descriptor) ||
1355+
if (!localFlags.HasAny(GeneralBitFlags.Descriptor) ||
13541356
((size > 0 || compressedSize > 0) && entry.Size > 0))
13551357
{
13561358
if (size != 0 && size != entry.Size)
@@ -2504,7 +2506,7 @@ private void CopyBytes(ZipUpdate update, Stream destination, Stream source,
25042506
/// <returns>The descriptor size, zero if there isn't one.</returns>
25052507
private static int GetDescriptorSize(ZipUpdate update, bool includingSignature)
25062508
{
2507-
if (!((GeneralBitFlags)update.Entry.Flags).HasFlag(GeneralBitFlags.Descriptor))
2509+
if (!((GeneralBitFlags)update.Entry.Flags).HasAny(GeneralBitFlags.Descriptor))
25082510
return 0;
25092511

25102512
var descriptorWithSignature = update.Entry.LocalHeaderRequiresZip64

0 commit comments

Comments
 (0)