Skip to content

Commit 34901ae

Browse files
committed
Merge branch 'master' of github.com:icsharpcode/SharpZipLib into async-ZipOutputStream
2 parents 3473cfa + d34e5c9 commit 34901ae

File tree

20 files changed

+960
-853
lines changed

20 files changed

+960
-853
lines changed

.github/workflows/build-test.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
name: Build and Test
22

33
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: 'Tag Ref'
8+
required: true
49
pull_request:
510
branches: [ master ]
611
push:
@@ -23,6 +28,7 @@ jobs:
2328
steps:
2429
- uses: actions/checkout@v2
2530
with:
31+
ref: ${{ github.events.inputs.tag }}
2632
fetch-depth: 0
2733

2834
- name: Setup .NET Core
@@ -120,6 +126,7 @@ jobs:
120126
steps:
121127
- uses: actions/checkout@v2
122128
with:
129+
ref: ${{ github.events.inputs.tag }}
123130
fetch-depth: 0
124131

125132
- name: Setup .NET Core
@@ -138,8 +145,18 @@ jobs:
138145
if: ${{ github.event_name == 'pull_request' }}
139146
run: echo "PKG_SUFFIX=-PR" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
140147

148+
- name: Set package version
149+
continue-on-error: true
150+
run: |-
151+
$PKG_GIT_VERSION="$(git describe --tags --abbrev | % { $_.substring(1) })"
152+
Write-Output "::notice::Git describe: $PKG_GIT_VERSION"
153+
Write-Output "::notice::Package suffix: $env:PKG_SUFFIX"
154+
$PKG_VERSION = "${PKG_GIT_VERSION}${env:PKG_SUFFIX}"
155+
Write-Output "::notice::Package version: $PKG_VERSION"
156+
Write-Output "PKG_VERSION=$PKG_VERSION" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
157+
141158
- name: Create nuget package
142-
run: dotnet pack ${{ env.PKG_PROJ }} -c Release --output dist ${{ env.PKG_PROPS }} /p:Version=$(git describe --abbrev | % { $_.substring(1) })${{ env.PKG_SUFFIX }}
159+
run: dotnet pack ${{ env.PKG_PROJ }} -c Release --output dist ${{ env.PKG_PROPS }} /p:Version=${{ env.PKG_VERSION }}
143160

144161
- name: Upload nuget package artifact
145162
uses: actions/upload-artifact@v2

SECURITY.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
| Version | Supported |
66
| ------- | ------------------ |
77
| 1.3.x | :white_check_mark: |
8-
| 1.2.x | :white_check_mark: |
9-
| 1.1.x | :white_check_mark: |
10-
| 1.0.x | :white_check_mark: |
11-
| < 1.0 | :x: |
8+
| < 1.3 | :x: |
129

1310
## Reporting a Vulnerability
1411

src/ICSharpCode.SharpZipLib/ICSharpCode.SharpZipLib.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
<!-- Nuget specific tags -->
1313
<PropertyGroup>
14-
<AssemblyVersion>1.3.2.10</AssemblyVersion>
15-
<FileVersion>1.3.2.10</FileVersion>
16-
<Version>1.3.2</Version>
14+
<Version>1.3.3</Version>
15+
<FileVersion>$(Version).11</FileVersion>
16+
<AssemblyVersion>$(FileVersion)</AssemblyVersion>
1717
<PackageId>SharpZipLib</PackageId>
1818
<Company>ICSharpCode</Company>
1919
<Authors>ICSharpCode</Authors>
@@ -26,7 +26,7 @@
2626
<PackageTags>Compression Library Zip GZip BZip2 LZW Tar</PackageTags>
2727
<NeutralLanguage>en-US</NeutralLanguage>
2828
<PackageReleaseNotes>
29-
Please see https://github.com/icsharpcode/SharpZipLib/wiki/Release-1.3.2 for more information.</PackageReleaseNotes>
29+
Please see https://github.com/icsharpcode/SharpZipLib/wiki/Release-1.3.3 for more information.</PackageReleaseNotes>
3030
<PackageProjectUrl>https://github.com/icsharpcode/SharpZipLib</PackageProjectUrl>
3131
</PropertyGroup>
3232

src/ICSharpCode.SharpZipLib/Tar/TarArchive.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ public void ExtractContents(string destinationDirectory, bool allowParentTravers
613613
throw new ObjectDisposedException("TarArchive");
614614
}
615615

616-
var fullDistDir = Path.GetFullPath(destinationDirectory);
616+
var fullDistDir = Path.GetFullPath(destinationDirectory).TrimEnd('/', '\\');
617617

618618
while (true)
619619
{
@@ -658,8 +658,9 @@ private void ExtractEntry(string destDir, TarEntry entry, bool allowParentTraver
658658
name = name.Replace('/', Path.DirectorySeparatorChar);
659659

660660
string destFile = Path.Combine(destDir, name);
661+
var destFileDir = Path.GetDirectoryName(Path.GetFullPath(destFile)) ?? "";
661662

662-
if (!allowParentTraversal && !Path.GetFullPath(destFile).StartsWith(destDir, StringComparison.InvariantCultureIgnoreCase))
663+
if (!allowParentTraversal && !destFileDir.StartsWith(destDir, StringComparison.InvariantCultureIgnoreCase))
663664
{
664665
throw new InvalidNameException("Parent traversal in paths is not allowed");
665666
}

src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ public static bool IsCompressionMethodSupported(CompressionMethod method)
10891089
/// <summary>
10901090
/// Cleans a name making it conform to Zip file conventions.
10911091
/// Devices names ('c:\') and UNC share names ('\\server\share') are removed
1092-
/// and forward slashes ('\') are converted to back slashes ('/').
1092+
/// and back slashes ('\') are converted to forward slashes ('/').
10931093
/// Names are made relative by trimming leading slashes which is compatible
10941094
/// with the ZIP naming convention.
10951095
/// </summary>

src/ICSharpCode.SharpZipLib/Zip/ZipExtraData.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface ITaggedData
1515
/// <summary>
1616
/// Get the ID for this tagged data value.
1717
/// </summary>
18-
short TagID { get; }
18+
ushort TagID { get; }
1919

2020
/// <summary>
2121
/// Set the contents of this instance from the data passed.
@@ -41,7 +41,7 @@ public class RawTaggedData : ITaggedData
4141
/// Initialise a new instance.
4242
/// </summary>
4343
/// <param name="tag">The tag ID.</param>
44-
public RawTaggedData(short tag)
44+
public RawTaggedData(ushort tag)
4545
{
4646
_tag = tag;
4747
}
@@ -51,7 +51,7 @@ public RawTaggedData(short tag)
5151
/// <summary>
5252
/// Get the ID for this tagged data value.
5353
/// </summary>
54-
public short TagID
54+
public ushort TagID
5555
{
5656
get { return _tag; }
5757
set { _tag = value; }
@@ -100,7 +100,7 @@ public byte[] Data
100100
/// <summary>
101101
/// The tag ID for this instance.
102102
/// </summary>
103-
private short _tag;
103+
private ushort _tag;
104104

105105
private byte[] _data;
106106

@@ -139,7 +139,7 @@ public enum Flags : byte
139139
/// <summary>
140140
/// Get the ID
141141
/// </summary>
142-
public short TagID
142+
public ushort TagID
143143
{
144144
get { return 0x5455; }
145145
}
@@ -325,7 +325,7 @@ public class NTTaggedData : ITaggedData
325325
/// <summary>
326326
/// Get the ID for this tagged data value.
327327
/// </summary>
328-
public short TagID
328+
public ushort TagID
329329
{
330330
get { return 10; }
331331
}

test/ICSharpCode.SharpZipLib.Tests/BZip2/Bzip2Tests.cs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using ICSharpCode.SharpZipLib.BZip2;
22
using ICSharpCode.SharpZipLib.Tests.TestSupport;
33
using NUnit.Framework;
4-
using System;
54
using System.IO;
65

76
namespace ICSharpCode.SharpZipLib.Tests.BZip2
@@ -24,34 +23,30 @@ public void BasicRoundTrip()
2423
{
2524
var ms = new MemoryStream();
2625
var outStream = new BZip2OutputStream(ms);
26+
27+
var buf = Utils.GetDummyBytes(size: 10000, RandomSeed);
2728

28-
byte[] buf = new byte[10000];
29-
var rnd = new Random(RandomSeed);
30-
rnd.NextBytes(buf);
31-
32-
outStream.Write(buf, 0, buf.Length);
29+
outStream.Write(buf, offset: 0, buf.Length);
3330
outStream.Close();
3431
ms = new MemoryStream(ms.GetBuffer());
35-
ms.Seek(0, SeekOrigin.Begin);
32+
ms.Seek(offset: 0, SeekOrigin.Begin);
3633

37-
using (BZip2InputStream inStream = new BZip2InputStream(ms))
34+
using BZip2InputStream inStream = new BZip2InputStream(ms);
35+
var buf2 = new byte[buf.Length];
36+
var pos = 0;
37+
while (true)
3838
{
39-
byte[] buf2 = new byte[buf.Length];
40-
int pos = 0;
41-
while (true)
39+
var numRead = inStream.Read(buf2, pos, count: 4096);
40+
if (numRead <= 0)
4241
{
43-
int numRead = inStream.Read(buf2, pos, 4096);
44-
if (numRead <= 0)
45-
{
46-
break;
47-
}
48-
pos += numRead;
42+
break;
4943
}
44+
pos += numRead;
45+
}
5046

51-
for (int i = 0; i < buf.Length; ++i)
52-
{
53-
Assert.AreEqual(buf2[i], buf[i]);
54-
}
47+
for (var i = 0; i < buf.Length; ++i)
48+
{
49+
Assert.AreEqual(buf2[i], buf[i]);
5550
}
5651
}
5752

test/ICSharpCode.SharpZipLib.Tests/Base/InflaterDeflaterTests.cs

Lines changed: 24 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,10 @@ private MemoryStream Deflate(byte[] data, int level, bool zlib)
6161
return memoryStream;
6262
}
6363

64-
private static byte[] GetRandomTestData(int size)
65-
{
66-
byte[] buffer = new byte[size];
67-
var rnd = new Random(RandomSeed);
68-
rnd.NextBytes(buffer);
69-
70-
return buffer;
71-
}
72-
7364
private void RandomDeflateInflate(int size, int level, bool zlib)
7465
{
75-
byte[] buffer = GetRandomTestData(size);
76-
77-
MemoryStream ms = Deflate(buffer, level, zlib);
66+
var buffer = Utils.GetDummyBytes(size, RandomSeed);
67+
var ms = Deflate(buffer, level, zlib);
7868
Inflate(ms, buffer, level, zlib);
7969
}
8070

@@ -131,9 +121,8 @@ private async Task<MemoryStream> DeflateAsync(byte[] data, int level, bool zlib)
131121

132122
private async Task RandomDeflateInflateAsync(int size, int level, bool zlib)
133123
{
134-
byte[] buffer = GetRandomTestData(size);
135-
136-
MemoryStream ms = await DeflateAsync(buffer, level, zlib);
124+
var buffer = Utils.GetDummyBytes(size, RandomSeed);
125+
var ms = await DeflateAsync(buffer, level, zlib);
137126
await InflateAsync(ms, buffer, level, zlib);
138127
}
139128

@@ -180,58 +169,56 @@ public void InflateDeflateZlib([Range(0, 9)] int level)
180169
[Category("Async")]
181170
public async Task InflateDeflateZlibAsync([Range(0, 9)] int level)
182171
{
183-
await RandomDeflateInflateAsync(100000, level, true);
172+
await RandomDeflateInflateAsync(size: 100000, level, zlib: true);
184173
}
185174

186175
private delegate void RunCompress(byte[] buffer);
187176

188-
private int runLevel;
189-
private bool runZlib;
190-
private long runCount;
191-
private readonly Random runRandom = new Random(RandomSeed);
177+
private int _runLevel;
178+
private bool _runZlib;
192179

193180
private void DeflateAndInflate(byte[] buffer)
194181
{
195-
++runCount;
196-
MemoryStream ms = Deflate(buffer, runLevel, runZlib);
197-
Inflate(ms, buffer, runLevel, runZlib);
182+
var ms = Deflate(buffer, _runLevel, _runZlib);
183+
Inflate(ms, buffer, _runLevel, _runZlib);
198184
}
199185

200-
private void TryVariants(RunCompress test, byte[] buffer, int index)
186+
private void TryVariants(RunCompress test, byte[] buffer, Random random, int index)
201187
{
202188
int worker = 0;
203189
while (worker <= 255)
204190
{
205191
buffer[index] = (byte)worker;
206192
if (index < buffer.Length - 1)
207193
{
208-
TryVariants(test, buffer, index + 1);
194+
TryVariants(test, buffer, random, index + 1);
209195
}
210196
else
211197
{
212198
test(buffer);
213199
}
214200

215-
worker += runRandom.Next(256);
201+
worker += random.Next(maxValue: 256);
216202
}
217203
}
218204

219205
private void TryManyVariants(int level, bool zlib, RunCompress test, byte[] buffer)
220206
{
221-
runLevel = level;
222-
runZlib = zlib;
223-
TryVariants(test, buffer, 0);
207+
var random = new Random(RandomSeed);
208+
_runLevel = level;
209+
_runZlib = zlib;
210+
TryVariants(test, buffer, random, 0);
224211
}
225212

226213
// TODO: Fix this
227-
//[Test]
228-
//[Category("Base")]
229-
//public void SmallBlocks()
230-
//{
231-
// byte[] buffer = new byte[10];
232-
// Array.Clear(buffer, 0, buffer.Length);
233-
// TryManyVariants(0, false, new RunCompress(DeflateAndInflate), buffer);
234-
//}
214+
[Test]
215+
[Category("Base")]
216+
[Explicit("Long-running")]
217+
public void SmallBlocks()
218+
{
219+
var buffer = new byte[10];
220+
TryManyVariants(level: 0, zlib: false, DeflateAndInflate, buffer);
221+
}
235222

236223
/// <summary>
237224
/// Basic inflate/deflate test

0 commit comments

Comments
 (0)