Coverage Report

Created: 2026-09-13 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/swift-protobuf/FuzzTesting/Sources/FuzzJSON/main.swift
Line
Count
Source
1
// Copyright (c) 2014 - 2024 Apple Inc. and the project authors
2
// Licensed under Apache License v2.0 with Runtime Library Exception
3
//
4
// See LICENSE.txt for license information:
5
// https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt
6
//
7
// -----------------------------------------------------------------------------
8
9
import Foundation
10
import FuzzCommon
11
import SwiftProtobuf
12
13
@_cdecl("LLVMFuzzerTestOneInput")
14
23.5k
public func FuzzJSON(_ start: UnsafeRawPointer, _ count: Int) -> CInt {
15
23.5k
    guard let (options, bytes) = JSONFuzzingOptions.extractOptions(start, count) else {
16
7
        return 1
17
23.5k
    }
18
23.5k
    var msg: SwiftProtoTesting_Fuzz_Message?
19
23.5k
    do {
20
23.5k
        msg = try SwiftProtoTesting_Fuzz_Message(
21
23.5k
            jsonUTF8Data: Data(bytes),
22
23.5k
            extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions,
23
23.5k
            options: options.decoding
24
23.5k
        )
25
14.8k
    } catch {
26
14.8k
        // Error parsing are to be expected since not all input will be well formed.
27
23.5k
    }
28
23.5k
    // Test serialization for completeness.
29
23.5k
    // If a message was parsed, it should not fail to serialize, so assert as such.
30
23.5k
    let _ = try! msg?.jsonString(options: options.encoding)
31
23.5k
    return 0
32
23.5k
}