Skip to content

Commit dd36990

Browse files
authored
Fix log overflow in continuous fuzz testing (#2020)
Prevent generating too many "Unrecognized selector" console messages that eventually make Travis kill the job due to log exceeding limits.
1 parent ea076e3 commit dd36990

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

Firestore/Example/FuzzTests/FuzzingTargets/FSTFuzzTestFieldPath.mm

+25-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ int FuzzTestFieldPath(const uint8_t *data, size_t size) {
3131
// Convert the raw bytes to a string with UTF-8 format.
3232
NSData *d = [NSData dataWithBytes:data length:size];
3333
NSString *str = [[NSString alloc] initWithData:d encoding:NSUTF8StringEncoding];
34+
if (!str) {
35+
// TODO(varconst): this happens when `NSData` doesn't happen to contain valid UTF-8, perhaps
36+
// find a way to still convert it to a string.
37+
return 0;
38+
}
3439

3540
// Create a FieldPath object from a string.
3641
@try {
@@ -42,7 +47,7 @@ int FuzzTestFieldPath(const uint8_t *data, size_t size) {
4247
// Fuzz test creating a FieldPath from an array with a single string.
4348
NSArray *str_arr1 = [NSArray arrayWithObjects:str, nil];
4449
@try {
45-
[[FIRFieldPath alloc] initWithFields:str_arr1];
50+
(void)[[FIRFieldPath alloc] initWithFields:str_arr1];
4651
} @catch (...) {
4752
// Caught exceptions are ignored because they are not what we are after in
4853
// fuzz testing.
@@ -52,7 +57,7 @@ int FuzzTestFieldPath(const uint8_t *data, size_t size) {
5257
NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@" .,/_"];
5358
NSArray *str_arr2 = [str componentsSeparatedByCharactersInSet:set];
5459
@try {
55-
[[FIRFieldPath alloc] initWithFields:str_arr2];
60+
(void)[[FIRFieldPath alloc] initWithFields:str_arr2];
5661
} @catch (...) {
5762
// Ignore caught exceptions.
5863
}
@@ -62,9 +67,25 @@ int FuzzTestFieldPath(const uint8_t *data, size_t size) {
6267
// created as mutable objects. Returns nil if there is a parsing error.
6368
NSArray *str_arr3 =
6469
[NSJSONSerialization JSONObjectWithData:d options:NSJSONReadingMutableContainers error:nil];
70+
NSMutableArray *mutable_array = [[NSMutableArray alloc] initWithArray:str_arr3];
71+
if (str_arr3) {
72+
for (int i = 0; i < str_arr3.count; ++i) {
73+
NSObject *value = str_arr3[i];
74+
// `FIRFieldPath initWithFields:` relies on all members having `length` attribute.
75+
if (![value isKindOfClass:[NSString class]]) {
76+
if ([value isKindOfClass:[NSNumber class]]) {
77+
mutable_array[i] = [[NSString alloc] initWithFormat:@"%@", (NSNumber *)value];
78+
} else {
79+
// TODO(varconst): convert to string recursively.
80+
return 0;
81+
}
82+
}
83+
}
84+
}
85+
6586
@try {
66-
if (str_arr3) {
67-
[[FIRFieldPath alloc] initWithFields:str_arr3];
87+
if (mutable_array) {
88+
(void)[[FIRFieldPath alloc] initWithFields:mutable_array];
6889
}
6990
} @catch (...) {
7091
// Ignore caught exceptions.

0 commit comments

Comments
 (0)