Skip to content

Commit 37edbc6

Browse files
author
Mina Farid
authored
Fuzz test Serializer to decode FieldValue (#1485)
1 parent 03ff392 commit 37edbc6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Firestore/Example/FuzzTests/FSTFuzzTestsPrincipal.mm

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,27 @@
1818

1919
#include "LibFuzzer/FuzzerDefs.h"
2020

21+
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
2122
#include "Firestore/core/src/firebase/firestore/remote/serializer.h"
2223

24+
using firebase::firestore::model::DatabaseId;
2325
using firebase::firestore::remote::Serializer;
2426

2527
namespace {
2628

2729
// Fuzz-test the deserialization process in Firestore. The Serializer reads raw
2830
// bytes and converts them to a model object.
2931
void FuzzTestDeserialization(const uint8_t *data, size_t size) {
30-
// TODO(minafarid): fuzz-test Serializer.
32+
DatabaseId database_id{"project", DatabaseId::kDefault};
33+
Serializer serializer{database_id};
34+
35+
@try {
36+
serializer.DecodeFieldValue(data, size);
37+
} @catch (...) {
38+
// Caught exceptions are ignored because the input might be malformed and
39+
// the deserialization might throw an error as intended. Fuzzing focuses on
40+
// runtime errors that are detected by the sanitizers.
41+
}
3142
}
3243

3344
// Contains the code to be fuzzed. Called by the fuzzing library with

0 commit comments

Comments
 (0)