Coverage Report

Created: 2026-05-16 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/swift-protobuf/FuzzTesting/Sources/FuzzBinary/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 FuzzCommon
10
import SwiftProtobuf
11
12
@_cdecl("LLVMFuzzerTestOneInput")
13
28.2k
public func FuzzBinary(_ start: UnsafeRawPointer, _ count: Int) -> CInt {
14
28.2k
    guard let (options, bytes) = BinaryFuzzingOptions.extractOptions(start, count) else {
15
11
        return 1
16
28.2k
    }
17
28.2k
    var msg: SwiftProtoTesting_Fuzz_Message?
18
28.2k
    do {
19
28.2k
        msg = try SwiftProtoTesting_Fuzz_Message(
20
28.2k
            serializedBytes: Array(bytes),
21
28.2k
            extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions,
22
28.2k
            partial: options.partialDecoding,
23
28.2k
            options: options.decoding
24
28.2k
        )
25
14.9k
    } catch {
26
13.2k
        // Error parsing are to be expected since not all input will be well formed.
27
28.2k
    }
28
28.2k
    // Test serialization for completeness.
29
28.2k
    // If a message was parsed, it should not fail to serialize, so assert as such.
30
28.2k
    let _: [UInt8]? = try! msg?.serializedBytes(options: options.encoding)
31
28.2k
32
28.2k
    return 0
33
28.2k
}