< Summary

Information
Class: DotnetFuzzing.Fuzzers.JsonDocumentFuzzer
Assembly: DotnetFuzzing
File(s): D:\runner\runtime\src\libraries\Fuzzing\DotnetFuzzing\Fuzzers\JsonDocumentFuzzer.cs
Line coverage
5%
Covered lines: 1
Uncovered lines: 19
Coverable lines: 20
Total lines: 41
Line coverage: 5%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
FuzzTarget(...)0%440%

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)
 016    {
 017        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.
 024        byte optionsByte = bytes[0];
 025        bytes = bytes.Slice(1);
 26
 027        var options = new JsonDocumentOptions
 028        {
 029            AllowTrailingCommas = (optionsByte & 1) != 0,
 030            CommentHandling = (optionsByte & 2) != 0 ? JsonCommentHandling.Skip : JsonCommentHandling.Disallow,
 031        };
 32
 033        using var poisonAfter = PooledBoundedMemory<byte>.Rent(bytes, PoisonPagePlacement.After);
 34
 35        try
 036        {
 037            JsonDocument.Parse(poisonAfter.Memory, options).Dispose();
 038        }
 039        catch (JsonException) { }
 040    }
 41}