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 FuzzJSON(_ start: UnsafeRawPointer, _ count: Int) -> CInt {
  13. guard let (options, bytes) = JSONDecodingOptions.extractOptions(start, count) else {
  14. return 1
  15. }
  16. var msg: SwiftProtoTesting_Fuzz_Message?
  17. do {
  18. msg = try SwiftProtoTesting_Fuzz_Message(
  19. jsonUTF8Data: Data(bytes),
  20. extensions: SwiftProtoTesting_Fuzz_FuzzTesting_Extensions,
  21. options: options)
  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 _ = try! msg?.jsonString()
  28. return 0
  29. }