-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Firestore Crash with Empty Blob field #11773
Comments
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight. |
thanks for reporting @harry-dickson . I'll take a look |
@harry-dickson , can you please share the code snippet you're using to store and read back the null blob? I expected a field value of null to fall under
|
I'll take a closer look tomorrow, but it's Flutter/Dart and I believe it's set though an update: DocumentRef<Stuff> ref;
ref.update({"blob": null}); I think I can prevent this in the case of null as a workaround - and fix the handful of broken documents The read is coming through a subscription: DocumentRef<Stuff> ref;
ref.snapshots().listen(...) The initial load that's triggered by the listen causes the crash before it gets near the flutter code. |
That's not right. If it is null in the source object, it is simply omitted in the Map provided to the update. It seems plausible from a simple text search in xcode:
pb_bytes_array_t* _Nullable MakeBytesArray(const void* _Nullable data,
size_t size) {
if (size == 0) return nullptr;
// Handle non-empty data...
} Called from MakeByteString() nanopb_util.h line 170 } else if ([input isKindOfClass:[NSData class]]) {
NSData *inputData = input;
return [self encodeBlob:(nanopb::MakeByteString(inputData))];
} I will try and stop writing empty arrays in my code as a workaround. |
I get this crash for data that looks like this in the firebase console:
That is, the field is present, but void/empty. In Flutter (package cloud_firestorm_platform_interface:blob.dart) it is not legal to store a null Blob. Looks like empty Blobs are coming from the database into the ios sdk typed as a Blob but with null as value. |
Something did change back in May/June time: firebase/flutterfire#11096 |
My workaround is to store an empty String in place of an empty Blob which works for my data assumptions; ymmv: static Map<String, dynamic> writeBytes(
Map<String, dynamic> buf,
String attr,
Uint8List? bytes,
) {
if (bytes != null) {
if (bytes.isEmpty) {
buf[attr] = "";
} else {
buf[attr] = Blob(bytes);
}
}
return buf;
} |
Fix will be part of next release. |
Description
I have a Document with a Blob field that is
nullempty.In my Flutter app, when I fetch the document there is a crash.
The crash occurs in
Firestore/core/src/nanopb/nanopb_util.h
: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
: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
The text was updated successfully, but these errors were encountered: