Closed
Description
Description
I have a Document with a Blob field that is null empty.
In my Flutter app, when I fetch the document there is a crash.
The crash occurs in Firestore/core/src/nanopb/nanopb_util.h
:
// line 181
inline NSData* _Nonnull MakeNSData(const pb_bytes_array_t* _Nullable data) {
return [[NSData alloc] initWithBytes:data->bytes length:data->size];
}
The data
is declared as being nullable, null is passed in and then dereferenced without any attempt to check it.
The return type is not nullable, making reasonable behavior difficult. Either it should return something in the face of null, or it should never be called with null in the first place. Allowing the app to crash is not a cool outcome.
This is the calling code in FSTUserDataWriter.mm
:
// line 81
- (id)convertedValue:(const google_firestore_v1_Value &)value {
switch (GetTypeOrder(value)) {
case TypeOrder::kMap:
return [self convertedObject:value.map_value];
case TypeOrder::kArray:
return [self convertedArray:value.array_value];
case TypeOrder::kReference:
return [self convertedReference:value];
case TypeOrder::kTimestamp:
return [self convertedTimestamp:value.timestamp_value];
case TypeOrder::kServerTimestamp:
return [self convertedServerTimestamp:value];
case TypeOrder::kNull:
return [NSNull null];
case TypeOrder::kBoolean:
return value.boolean_value ? @YES : @NO;
case TypeOrder::kNumber:
return value.which_value_type == google_firestore_v1_Value_integer_value_tag
? @(value.integer_value)
: @(value.double_value);
case TypeOrder::kString:
return MakeNSString(MakeStringView(value.string_value));
case TypeOrder::kBlob:
return MakeNSData(value.bytes_value); // <<============= Here: value.bytes_value is nil
case TypeOrder::kGeoPoint:
return MakeFIRGeoPoint(
GeoPoint(value.geo_point_value.latitude, value.geo_point_value.longitude));
case TypeOrder::kMaxValue:
// It is not possible for users to construct a kMaxValue manually.
break;
}
UNREACHABLE();
}
Reproducing the issue
Store a document with a null Blob field. Now read it.
Firebase SDK Version
10.12
Xcode Version
14.2
Installation Method
CocoaPods
Firebase Product(s)
Firestore
Targeted Platforms
iOS
Relevant Log Output
No response
If using Swift Package Manager, the project's Package.resolved
N/A
If using CocoaPods, the project's Podfile.lock
N/A