FSTFuzzTestSerializer.mm 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/nanopb/reader.h"
  22. #include "Firestore/core/src/firebase/firestore/remote/serializer.h"
  23. namespace firebase {
  24. namespace firestore {
  25. namespace fuzzing {
  26. using firebase::firestore::model::DatabaseId;
  27. using firebase::firestore::nanopb::Reader;
  28. using firebase::firestore::remote::Serializer;
  29. int FuzzTestDeserialization(const uint8_t *data, size_t size) {
  30. Serializer serializer{DatabaseId{"project", DatabaseId::kDefault}};
  31. @autoreleasepool {
  32. @try {
  33. Reader reader = Reader::Wrap(data, size);
  34. serializer.DecodeFieldValue(&reader);
  35. } @catch (...) {
  36. // Caught exceptions are ignored because the input might be malformed and
  37. // the deserialization might throw an error as intended. Fuzzing focuses on
  38. // runtime errors that are detected by the sanitizers.
  39. }
  40. }
  41. return 0;
  42. }
  43. } // namespace fuzzing
  44. } // namespace firestore
  45. } // namespace firebase