main.swift 1.1 KB

1234567891011121314151617181920212223242526272829303132
  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. import FuzzCommon
  9. import SwiftProtobuf
  10. @_cdecl("LLVMFuzzerTestOneInput")
  11. public func FuzzBinary(_ start: UnsafeRawPointer, _ count: Int) -> CInt {
  12. guard let (options, bytes) = BinaryDecodingOptions.extractOptions(start, count) else {
  13. return 1
  14. }
  15. var msg: SwiftProtoTesting_Fuzz_Message?
  16. do {
  17. msg = try SwiftProtoTesting_Fuzz_Message(
  18. serializedBytes: Array(bytes),
  19. extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions,
  20. options: options
  21. )
  22. } catch {
  23. // Error parsing are to be expected since not all input will be well formed.
  24. }
  25. // Test serialization for completeness.
  26. // If a message was parsed, it should not fail to serialize, so assert as such.
  27. let _: [UInt8]? = try! msg?.serializedBytes()
  28. return 0
  29. }