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 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. )
  23. } catch {
  24. // Error parsing are to be expected since not all input will be well formed.
  25. }
  26. // Test serialization for completeness.
  27. // If a message was parsed, it should not fail to serialize, so assert as such.
  28. let _ = try! msg?.jsonString()
  29. return 0
  30. }