Skip to content
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

Non-nil empty strings cause Firestore to crash instead of throwing an error gracefully #8218

Closed
Sam-Spencer opened this issue Jun 9, 2021 · 3 comments · Fixed by #8248
Closed
Assignees

Comments

@Sam-Spencer
Copy link

Environment

  • Xcode version: 12.5
  • Firebase SDK version: 8.0.0
  • Installation method: Swift Package Manager
  • Firebase Component: Firestore

The Problem

Currently, attempting a Firestore document load (of any nature) with an empty ID causes a runtime exception which results in a crash. By "empty ID" I am referring to a string whose character count is zero, but where the object is non-nil. Literally, an empty string.

While Firestore handles a number of errors and returns the failure results gracefully in many cases, this is not one of those. It would be nice if the SDK could catch this and return an error

Steps to reproduce:

  1. Start in a Swift environment
  2. Create a Firestore document or collection request
  3. In the document ID parameter: .document(ID), supply a non-nil but empty string such as "".
  4. Firestore throws a fatal error and causes the application to crash.
  5. Crash logs are difficult to parse, as the throw occurs deep inside the Firestore core framework.

Relevant Code

It appears, from crash logs that this occurs deep in the Firestore framework (core/src/api/collection_reference.cc):

return DocumentReference(std::move(path), firestore());

There seems to be an attempt to handle the issue and fail gracefully in Source/API/FIRCollectionReference.mm):

- (FIRDocumentReference *)documentWithPath:(NSString *)documentPath {
  if (!documentPath) {
    ThrowInvalidArgument("Document path cannot be nil.");
  }
  DocumentReference child = self.reference.Document(util::MakeString(documentPath));
  return [[FIRDocumentReference alloc] initWithReference:std::move(child)];
}

Unfortunately, if(!documentPath) does not handle cases where strings may be non-nil, yet still empty (something I think may have been made possible in a recent Swift release 🥴?).

@Sam-Spencer
Copy link
Author

Seems to be a common issue.

@var-const var-const self-assigned this Jun 9, 2021
@var-const
Copy link
Contributor

Thanks for reporting this -- we can add a check for an empty string.

@Sam-Spencer
Copy link
Author

Woohoo! Thank you!

var-const added a commit that referenced this issue Jun 14, 2021
… API aren't empty (#8248)

Currently, the error would look like `Document references must have an even number of segments, but has 0`.

Fixes #8218.
@firebase firebase locked and limited conversation to collaborators Jul 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
3 participants