< Summary

Information
Class: DotnetFuzzing.Fuzzers.JsonDocumentFuzzer
Assembly: DotnetFuzzing
File(s): D:\runner\runtime\src\libraries\Fuzzing\DotnetFuzzing\Fuzzers\JsonDocumentFuzzer.cs
Line coverage
80%
Covered lines: 16
Uncovered lines: 4
Coverable lines: 20
Total lines: 41
Line coverage: 80%
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(...)75%4488.23%

File(s)

D:\runner\runtime\src\libraries\Fuzzing\DotnetFuzzing\Fuzzers\JsonDocumentFuzzer.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.Text.Json;
 6
 7namespace DotnetFuzzing.Fuzzers;
 8
 9internal sealed class JsonDocumentFuzzer : IFuzzer
 10{
 111    public string[] TargetAssemblies { get; } = ["System.Text.Json"];
 012    public string[] TargetCoreLibPrefixes => [];
 013    public string Dictionary => "json.dict";
 14
 15    public void FuzzTarget(ReadOnlySpan<byte> bytes)
 488416    {
 488417        if (bytes.IsEmpty)
 018        {
 019            return;
 20        }
 21
 22        // The first byte is used to select various options.
 23        // The rest of the input is used as the UTF-8 JSON payload.
 488424        byte optionsByte = bytes[0];
 488425        bytes = bytes.Slice(1);
 26
 488427        var options = new JsonDocumentOptions
 488428        {
 488429            AllowTrailingCommas = (optionsByte & 1) != 0,
 488430            CommentHandling = (optionsByte & 2) != 0 ? JsonCommentHandling.Skip : JsonCommentHandling.Disallow,
 488431        };
 32
 488433        using var poisonAfter = PooledBoundedMemory<byte>.Rent(bytes, PoisonPagePlacement.After);
 34
 35        try
 488436        {
 488437            JsonDocument.Parse(poisonAfter.Memory, options).Dispose();
 15038        }
 1420239        catch (JsonException) { }
 976840    }
 41}