FSTFuzzTestSerializer.mm 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #include <cstddef>
  18. #include <cstdint>
  19. #import "Firestore/Example/FuzzTests/FuzzingTargets/FSTFuzzTestSerializer.h"
  20. #include "Firestore/core/src/firebase/firestore/model/database_id.h"
  21. #include "Firestore/core/src/firebase/firestore/remote/serializer.h"
  22. namespace firebase {
  23. namespace firestore {
  24. namespace fuzzing {
  25. using firebase::firestore::model::DatabaseId;
  26. using firebase::firestore::remote::Serializer;
  27. int FuzzTestDeserialization(const uint8_t *data, size_t size) {
  28. Serializer serializer{DatabaseId{"project", DatabaseId::kDefault}};
  29. @autoreleasepool {
  30. @try {
  31. serializer.DecodeFieldValue(data, size);
  32. } @catch (...) {
  33. // Caught exceptions are ignored because the input might be malformed and
  34. // the deserialization might throw an error as intended. Fuzzing focuses on
  35. // runtime errors that are detected by the sanitizers.
  36. }
  37. }
  38. return 0;
  39. }
  40. } // namespace fuzzing
  41. } // namespace firestore
  42. } // namespace firebase