Skip to content

Commit 468362f

Browse files
authored
Merge pull request #105771 from carlossanlop/UpgradeZlibNg
Upgrade zlib-ng to 2.2.1
2 parents 2dd517e + e060e83 commit 468362f

File tree

138 files changed

+3589
-2157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+3589
-2157
lines changed

THIRD-PARTY-NOTICES.TXT

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,27 @@ written authorization of the copyright holder.
6969
License notice for zlib-ng
7070
-----------------------
7171

72-
https://github.com/zlib-ng/zlib-ng/blob/develop/LICENSE.md
72+
https://github.com/zlib-ng/zlib-ng/blob/d54e3769be0c522015b784eca2af258b1c026107/LICENSE.md
7373

7474
(C) 1995-2024 Jean-loup Gailly and Mark Adler
7575

76-
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
76+
This software is provided 'as-is', without any express or implied
77+
warranty. In no event will the authors be held liable for any damages
78+
arising from the use of this software.
7779

78-
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
80+
Permission is granted to anyone to use this software for any purpose,
81+
including commercial applications, and to alter it and redistribute it
82+
freely, subject to the following restrictions:
7983

80-
The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
84+
1. The origin of this software must not be misrepresented; you must not
85+
claim that you wrote the original software. If you use this software
86+
in a product, an acknowledgment in the product documentation would be
87+
appreciated but is not required.
8188

82-
Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
89+
2. Altered source versions must be plainly marked as such, and must not be
90+
misrepresented as being the original software.
8391

84-
This notice may not be removed or altered from any source distribution.
92+
3. This notice may not be removed or altered from any source distribution.
8593

8694
License notice for LinuxTracepoints
8795
-----------------------------------
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace System.IO.Compression;
5+
6+
internal static partial class ZLibNative
7+
{
8+
/// <summary>
9+
/// <p>ZLib can accept any integer value between 0 and 9 (inclusive) as a valid compression level parameter:
10+
/// 1 gives best speed, 9 gives best compression, 0 gives no compression at all (the input data is simply copied a block at a time).
11+
/// <code>CompressionLevel.DefaultCompression</code> = -1 requests a default compromise between speed and compression
12+
/// (currently equivalent to level 6).</p>
13+
///
14+
/// <p><strong>How to choose a compression level:</strong></p>
15+
///
16+
/// <p>The names <code>NoCompression</code>, <code>BestSpeed</code>, <code>DefaultCompression</code>, <code>BestCompression</code> are taken over from
17+
/// the corresponding ZLib definitions, which map to our public NoCompression, Fastest, Optimal, and SmallestSize respectively.</p>
18+
/// <p><em>Optimal Compression:</em></p>
19+
/// <p><code>ZLibNative.CompressionLevel compressionLevel = ZLibNative.CompressionLevel.DefaultCompression;</code> <br />
20+
/// <code>int windowBits = 15; // or -15 if no headers required</code> <br />
21+
/// <code>int memLevel = 8;</code> <br />
22+
/// <code>ZLibNative.CompressionStrategy strategy = ZLibNative.CompressionStrategy.DefaultStrategy;</code> </p>
23+
///
24+
///<p><em>Fastest compression:</em></p>
25+
///<p><code>ZLibNative.CompressionLevel compressionLevel = ZLibNative.CompressionLevel.BestSpeed;</code> <br />
26+
/// <code>int windowBits = 15; // or -15 if no headers required</code> <br />
27+
/// <code>int memLevel = 8; </code> <br />
28+
/// <code>ZLibNative.CompressionStrategy strategy = ZLibNative.CompressionStrategy.DefaultStrategy;</code> </p>
29+
///
30+
/// <p><em>No compression (even faster, useful for data that cannot be compressed such some image formats):</em></p>
31+
/// <p><code>ZLibNative.CompressionLevel compressionLevel = ZLibNative.CompressionLevel.NoCompression;</code> <br />
32+
/// <code>int windowBits = 15; // or -15 if no headers required</code> <br />
33+
/// <code>int memLevel = 7;</code> <br />
34+
/// <code>ZLibNative.CompressionStrategy strategy = ZLibNative.CompressionStrategy.DefaultStrategy;</code> </p>
35+
///
36+
/// <p><em>Smallest Size Compression:</em></p>
37+
/// <p><code>ZLibNative.CompressionLevel compressionLevel = ZLibNative.CompressionLevel.BestCompression;</code> <br />
38+
/// <code>int windowBits = 15; // or -15 if no headers required</code> <br />
39+
/// <code>int memLevel = 8;</code> <br />
40+
/// <code>ZLibNative.CompressionStrategy strategy = ZLibNative.CompressionStrategy.DefaultStrategy;</code> </p>
41+
/// </summary>
42+
public enum CompressionLevel : int
43+
{
44+
NoCompression = 0,
45+
BestSpeed = 1,
46+
DefaultCompression = -1,
47+
BestCompression = 9
48+
}
49+
}

src/libraries/Common/src/System/IO/Compression/ZLibNative.cs

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -37,48 +37,6 @@ public enum ErrorCode : int
3737
VersionError = -6
3838
}
3939

40-
/// <summary>
41-
/// <p>ZLib can accept any integer value between 0 and 9 (inclusive) as a valid compression level parameter:
42-
/// 1 gives best speed, 9 gives best compression, 0 gives no compression at all (the input data is simply copied a block at a time).
43-
/// <code>CompressionLevel.DefaultCompression</code> = -1 requests a default compromise between speed and compression
44-
/// (currently equivalent to level 6).</p>
45-
///
46-
/// <p><strong>How to choose a compression level:</strong></p>
47-
///
48-
/// <p>The names <code>NoCompression</code>, <code>BestSpeed</code>, <code>DefaultCompression</code>, <code>BestCompression</code> are taken over from
49-
/// the corresponding ZLib definitions, which map to our public NoCompression, Fastest, Optimal, and SmallestSize respectively.</p>
50-
/// <p><em>Optimal Compression:</em></p>
51-
/// <p><code>ZLibNative.CompressionLevel compressionLevel = ZLibNative.CompressionLevel.DefaultCompression;</code> <br />
52-
/// <code>int windowBits = 15; // or -15 if no headers required</code> <br />
53-
/// <code>int memLevel = 8;</code> <br />
54-
/// <code>ZLibNative.CompressionStrategy strategy = ZLibNative.CompressionStrategy.DefaultStrategy;</code> </p>
55-
///
56-
///<p><em>Fastest compression:</em></p>
57-
///<p><code>ZLibNative.CompressionLevel compressionLevel = ZLibNative.CompressionLevel.BestSpeed;</code> <br />
58-
/// <code>int windowBits = 15; // or -15 if no headers required</code> <br />
59-
/// <code>int memLevel = 8; </code> <br />
60-
/// <code>ZLibNative.CompressionStrategy strategy = ZLibNative.CompressionStrategy.DefaultStrategy;</code> </p>
61-
///
62-
/// <p><em>No compression (even faster, useful for data that cannot be compressed such some image formats):</em></p>
63-
/// <p><code>ZLibNative.CompressionLevel compressionLevel = ZLibNative.CompressionLevel.NoCompression;</code> <br />
64-
/// <code>int windowBits = 15; // or -15 if no headers required</code> <br />
65-
/// <code>int memLevel = 7;</code> <br />
66-
/// <code>ZLibNative.CompressionStrategy strategy = ZLibNative.CompressionStrategy.DefaultStrategy;</code> </p>
67-
///
68-
/// <p><em>Smallest Size Compression:</em></p>
69-
/// <p><code>ZLibNative.CompressionLevel compressionLevel = ZLibNative.CompressionLevel.BestCompression;</code> <br />
70-
/// <code>int windowBits = 15; // or -15 if no headers required</code> <br />
71-
/// <code>int memLevel = 8;</code> <br />
72-
/// <code>ZLibNative.CompressionStrategy strategy = ZLibNative.CompressionStrategy.DefaultStrategy;</code> </p>
73-
/// </summary>
74-
public enum CompressionLevel : int
75-
{
76-
NoCompression = 0,
77-
BestSpeed = 1,
78-
DefaultCompression = -1,
79-
BestCompression = 9
80-
}
81-
8240
/// <summary>
8341
/// <p><strong>From the ZLib manual:</strong></p>
8442
/// <p><code>CompressionStrategy</code> is used to tune the compression algorithm.<br />

src/libraries/Common/tests/System/IO/Compression/CompressionStreamUnitTestBase.cs

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,30 @@ async Task<long> GetLengthAsync(CompressionLevel compressionLevel)
497497
Assert.True(optimalLength >= smallestLength);
498498
}
499499

500+
[Theory]
501+
[MemberData(nameof(UncompressedTestFilesZLib))]
502+
public async Task ZLibCompressionOptions_SizeInOrder(string testFile)
503+
{
504+
using var uncompressedStream = await LocalMemoryStream.readAppFileAsync(testFile);
505+
506+
async Task<long> GetLengthAsync(int compressionLevel)
507+
{
508+
uncompressedStream.Position = 0;
509+
using var mms = new MemoryStream();
510+
using var compressor = CreateStream(mms, new ZLibCompressionOptions() { CompressionLevel = compressionLevel, CompressionStrategy = ZLibCompressionStrategy.Default }, leaveOpen: false);
511+
await uncompressedStream.CopyToAsync(compressor);
512+
await compressor.FlushAsync();
513+
return mms.Length;
514+
}
515+
516+
long fastestLength = await GetLengthAsync(1);
517+
long optimalLength = await GetLengthAsync(5);
518+
long smallestLength = await GetLengthAsync(9);
519+
520+
Assert.True(fastestLength >= optimalLength);
521+
Assert.True(optimalLength >= smallestLength);
522+
}
523+
500524
[Theory]
501525
[MemberData(nameof(ZLibOptionsRoundTripTestData))]
502526
public async Task RoundTripWithZLibCompressionOptions(string testFile, ZLibCompressionOptions options)
@@ -537,28 +561,6 @@ private async Task<MemoryStream> CompressTestFile(LocalMemoryStream testStream,
537561
return compressorOutput;
538562
}
539563

540-
protected async Task CompressionLevel_SizeInOrderBase(string testFile)
541-
{
542-
using var uncompressedStream = await LocalMemoryStream.readAppFileAsync(testFile);
543-
544-
async Task<long> GetLengthAsync(int compressionLevel)
545-
{
546-
uncompressedStream.Position = 0;
547-
using var mms = new MemoryStream();
548-
using var compressor = CreateStream(mms, new ZLibCompressionOptions() { CompressionLevel = compressionLevel, CompressionStrategy = ZLibCompressionStrategy.Default }, leaveOpen: false);
549-
await uncompressedStream.CopyToAsync(compressor);
550-
await compressor.FlushAsync();
551-
return mms.Length;
552-
}
553-
554-
long prev = await GetLengthAsync(0);
555-
for (int i = 1; i < 10; i++)
556-
{
557-
long cur = await GetLengthAsync(i);
558-
Assert.True(cur <= prev, $"Expected {cur} <= {prev} for quality {i}");
559-
prev = cur;
560-
}
561-
}
562564
}
563565

564566
public enum TestScenario

src/libraries/System.IO.Compression.Brotli/tests/System.IO.Compression.Brotli.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
<Compile Include="$(CommonTestPath)System\IO\ConnectedStreams.cs" Link="Common\System\IO\ConnectedStreams.cs" />
2828
<Compile Include="$(CommonPath)System\Net\MultiArrayBuffer.cs" Link="ProductionCode\Common\System\Net\MultiArrayBuffer.cs" />
2929
<Compile Include="$(CommonPath)System\Net\StreamBuffer.cs" Link="ProductionCode\Common\System\Net\StreamBuffer.cs" />
30+
<Compile Include="$(CommonPath)System\IO\Compression\ZLibNative.CompressionLevel.cs"
31+
Link="Common\System\IO\Compression\ZLibNative.CompressionLevel.cs" />
3032
</ItemGroup>
3133
<ItemGroup>
3234
<ProjectReference Include="$(CommonTestPath)StreamConformanceTests\StreamConformanceTests.csproj" />

src/libraries/System.IO.Compression/src/System.IO.Compression.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
<Compile Include="System\IO\Compression\DeflateZLib\ZLibException.cs" />
3636
<Compile Include="$(CommonPath)System\IO\Compression\ZLibNative.cs"
3737
Link="Common\System\IO\Compression\ZLibNative.cs" />
38+
<Compile Include="$(CommonPath)System\IO\Compression\ZLibNative.CompressionLevel.cs"
39+
Link="Common\System\IO\Compression\ZLibNative.CompressionLevel.cs" />
3840
<Compile Include="$(CommonPath)System\IO\Compression\ZLibNative.ZStream.cs"
3941
Link="Common\System\IO\Compression\ZLibNative.ZStream.cs" />
4042
<Compile Include="System\IO\Compression\CompressionLevel.cs" />

src/libraries/System.IO.Compression/tests/CompressionStreamUnitTests.Deflate.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,5 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati
219219
return base.WriteAsync(buffer, offset, count, cancellationToken);
220220
}
221221
}
222-
223-
[Theory]
224-
[MemberData(nameof(UncompressedTestFilesZLib))]
225-
public async Task ZLibCompressionLevel_SizeInOrder(string testFile)
226-
{
227-
await CompressionLevel_SizeInOrderBase(testFile);
228-
}
229222
}
230223
}

src/libraries/System.IO.Compression/tests/CompressionStreamUnitTests.Gzip.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,5 @@ public override Task WriteAsync(byte[] buffer, int offset, int count, Cancellati
441441
return base.WriteAsync(buffer, offset, count, cancellationToken);
442442
}
443443
}
444-
445-
[Theory]
446-
[MemberData(nameof(UncompressedTestFilesZLib))]
447-
public async Task ZLibCompressionLevel_SizeInOrder(string testFile)
448-
{
449-
await CompressionLevel_SizeInOrderBase(testFile);
450-
}
451444
}
452445
}

src/libraries/System.IO.Compression/tests/CompressionStreamUnitTests.ZLib.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,5 @@ public void StreamTruncation_IsDetected(TestScenario testScenario)
150150
}
151151
}, testScenario.ToString()).Dispose();
152152
}
153-
154-
[Theory]
155-
[MemberData(nameof(UncompressedTestFilesZLib))]
156-
public async Task ZLibCompressionLevel_SizeInOrder(string testFile)
157-
{
158-
await CompressionLevel_SizeInOrderBase(testFile);
159-
}
160153
}
161154
}

src/libraries/System.IO.Compression/tests/System.IO.Compression.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
<Compile Include="$(CommonTestPath)System\IO\Compression\FileData.cs" Link="Common\System\IO\Compression\FileData.cs" />
3636
<Compile Include="$(CommonTestPath)System\IO\Compression\LocalMemoryStream.cs" Link="Common\System\IO\Compression\LocalMemoryStream.cs" />
3737
<Compile Include="$(CommonTestPath)System\IO\Compression\StreamHelpers.cs" Link="Common\System\IO\Compression\StreamHelpers.cs" />
38+
<Compile Include="$(CommonPath)System\IO\Compression\ZLibNative.CompressionLevel.cs"
39+
Link="Common\System\IO\Compression\ZLibNative.CompressionLevel.cs" />
3840
<Compile Include="$(CommonTestPath)System\IO\TempFile.cs" Link="Common\System\IO\TempFile.cs" />
3941
<Compile Include="$(CommonTestPath)System\IO\WrappedStream.cs" Link="Common\System\IO\WrappedStream.cs" />
4042
<Compile Include="$(CommonTestPath)System\IO\Compression\ZipTestHelper.cs" Link="Common\System\IO\Compression\ZipTestHelper.cs" />

src/libraries/System.Net.WebSockets/src/System.Net.WebSockets.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
Link="Common\System\Net\WebSockets\WebSocketValidate.cs" />
3838
<Compile Include="$(CommonPath)System\IO\Compression\ZLibNative.cs"
3939
Link="Common\System\IO\Compression\ZLibNative.cs" />
40+
<Compile Include="$(CommonPath)System\IO\Compression\ZLibNative.CompressionLevel.cs"
41+
Link="Common\System\IO\Compression\ZLibNative.CompressionLevel.cs" />
4042
<Compile Include="$(CommonPath)System\IO\Compression\ZLibNative.ZStream.cs"
4143
Link="Common\System\IO\Compression\ZLibNative.ZStream.cs" />
4244
<Compile Include="$(CommonPath)Interop\Interop.zlib.cs"

src/native/external/cgmanifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"Type": "git",
4747
"Git": {
4848
"RepositoryUrl": "https://github.com/zlib-ng/zlib-ng",
49-
"CommitHash": "74253725f884e2424a0dd8ae3f69896d5377f325"
49+
"CommitHash": "d54e3769be0c522015b784eca2af258b1c026107"
5050
}
5151
},
5252
"DevelopmentDependency": false
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
v2.1.6
2-
74253725f884e2424a0dd8ae3f69896d5377f325
1+
v2.2.1
2+
d54e3769be0c522015b784eca2af258b1c026107
33

4-
https://github.com/zlib-ng/zlib-ng/releases/tag/2.1.6
4+
https://github.com/zlib-ng/zlib-ng/releases/tag/2.2.1
55

66
We have removed the following folders from our local copy as these files are not needed for our compilation:
77

8-
- zlib-ng/docs/
8+
- zlib-ng/doc/
99
- zlib-ng/test/
1010
- zlib-ng/arch/s390/self-hosted-builder/
1111

12-
Apply https://github.com/dotnet/runtime/pull/105433.patch
12+
Also, if the next version does not yet contain the fixes included in 12bc7edc73308f017ec40c6b2db694a6e3490ac2, cherry-pick it as a patch.

0 commit comments

Comments
 (0)