main.swift 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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 Foundation
  9. import FuzzCommon
  10. import SwiftProtobuf
  11. @_cdecl("LLVMFuzzerTestOneInput")
  12. public func FuzzTextFormat(_ start: UnsafeRawPointer, _ count: Int) -> CInt {
  13. guard let (options, bytes) = TextFormatDecodingOptions.extractOptions(start, count) else {
  14. return 1
  15. }
  16. guard let str = String(data: Data(bytes), encoding: .utf8) else { return 0 }
  17. var msg: SwiftProtoTesting_Fuzz_Message?
  18. do {
  19. msg = try SwiftProtoTesting_Fuzz_Message(
  20. textFormatString: str,
  21. options: options,
  22. extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions
  23. )
  24. } catch {
  25. // Error parsing are to be expected since not all input will be well formed.
  26. }
  27. // Test serialization for completeness.
  28. let _ = msg?.textFormatString()
  29. return 0
  30. }