< Summary

Information
Class: DotnetFuzzing.Fuzzers.Deflate64Fuzzer
Assembly: DotnetFuzzing
File(s): D:\runner\runtime\src\libraries\Fuzzing\DotnetFuzzing\Fuzzers\Deflate64Fuzzer.cs
Line coverage
82%
Covered lines: 39
Uncovered lines: 8
Coverable lines: 47
Total lines: 83
Line coverage: 82.9%
Branch coverage
75%
Covered branches: 3
Total branches: 4
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
FuzzTarget(...)50%2271.42%
.cctor()100%11100%
CreateStream(...)100%11100%
CopyToRentedArray(...)100%1160%
TestArchive()100%22100%

File(s)

D:\runner\runtime\src\libraries\Fuzzing\DotnetFuzzing\Fuzzers\Deflate64Fuzzer.cs

#LineLine coverage
 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
 4using System.Buffers;
 5using System.Linq;
 6using System.IO.Compression;
 7using System.Reflection;
 8using System.Threading.Tasks;
 9
 10namespace DotnetFuzzing.Fuzzers;
 11
 12internal sealed class Deflate64Fuzzer : IFuzzer
 13{
 114    public string[] TargetAssemblies { get; } = ["System.IO.Compression"];
 015    public string[] TargetCoreLibPrefixes => [];
 016    public string Corpus => "deflate64";
 17
 18    public void FuzzTarget(ReadOnlySpan<byte> bytes)
 325119    {
 325120        if (bytes.IsEmpty)
 021        {
 022            return;
 23        }
 24
 325125        TestArchive(CopyToRentedArray(bytes), bytes.Length, async: false).GetAwaiter().GetResult();
 325126        TestArchive(CopyToRentedArray(bytes), bytes.Length, async: true).GetAwaiter().GetResult();
 325127    }
 28
 29#pragma warning disable IL2026 // RequiresUnreferencedCode
 130    private static readonly Type _deflateStreamType = typeof(ZipArchive).Assembly.GetType("System.IO.Compression.Deflate
 31#pragma warning restore IL2026
 32
 33    private static Stream CreateStream(byte[] bytes, int length)
 650234    {
 35#pragma warning disable IL2077 // dynamic access to non-public ctors
 650236        return (Stream)Activator.CreateInstance(
 650237            _deflateStreamType,
 650238            bindingAttr: BindingFlags.NonPublic | BindingFlags.Instance,
 650239            binder: null,
 650240            args: new object[] { new MemoryStream(bytes, 0, length), ZipCompressionMethod.Deflate64, -1L },
 650241            culture: null)!;
 42#pragma warning restore IL2077
 650243    }
 44
 45    private byte[] CopyToRentedArray(ReadOnlySpan<byte> bytes)
 650246    {
 650247        byte[] buffer = ArrayPool<byte>.Shared.Rent(bytes.Length);
 48        try
 650249        {
 650250            bytes.CopyTo(buffer);
 650251            return buffer;
 52        }
 053        catch
 054        {
 055            ArrayPool<byte>.Shared.Return(buffer);
 056            throw;
 57        }
 650258    }
 59
 60    private async Task TestArchive(byte[] buffer, int length, bool async)
 650261    {
 62        try
 650263        {
 650264            using var stream = CreateStream(buffer, length);
 650265            if (async)
 325166            {
 325167                await stream.CopyToAsync(Stream.Null);
 208868            }
 69            else
 325170            {
 325171                stream.CopyTo(Stream.Null);
 208872            }
 417673        }
 232674        catch (InvalidDataException)
 232675        {
 76            // ignore, this exception is expected to be thrown for invalid/corrupted archives.
 232677        }
 78        finally
 650279        {
 650280            ArrayPool<byte>.Shared.Return(buffer);
 650281        }
 650282    }
 83}