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 181inlineNSData* _Nonnull MakeNSData(constpb_bytes_array_t* _Nullable data) { return [[NSDataalloc] 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 [selfconvertedObject:value.map_value]; case TypeOrder::kArray: return [selfconvertedArray:value.array_value]; case TypeOrder::kReference: return [selfconvertedReference:value]; case TypeOrder::kTimestamp: return [selfconvertedTimestamp:value.timestamp_value]; case TypeOrder::kServerTimestamp: return [selfconvertedServerTimestamp:value]; case TypeOrder::kNull: return [NSNullnull]; 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: returnMakeNSString(MakeStringView(value.string_value)); case TypeOrder::kBlob: returnMakeNSData(value.bytes_value); // <<============= Here: value.bytes_value is nilcase TypeOrder::kGeoPoint: returnMakeFIRGeoPoint( 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