[cloud_firestore][Windows] Invalid field names (empty or `__x__`) close the app instead of throwing a FirebaseException
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 52/100
Hướng nghiên cứu
Start in packages/cloud_firestore/cloud_firestore/windows/cloud_firestore_plugin.cpp and compare DocumentReferenceSet, DocumentReferenceUpdate, the transaction handlers, and WriteBatchCommit, which already catches native exceptions. Trace how Pigeon handlers return errors to Dart, then reproduce the invalid field write on Windows and check that set, update, and transaction writes report a catchable FirebaseException instead of terminating the process.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
cloud_firestore
Which platforms are affected?
Windows
Description
On Windows, writing a document whose data contains an empty field name ("") or a reserved one (__x__) closes the app. Dart never sees an error: try/catch, FlutterError.onError and runZonedGuarded don't run, and Dart-level crash reporting records nothing. On Android the same write fails with a normal FirebaseException.
What happens
The Firebase C++ SDK validates field names and throws std::invalid_argument for an empty segment or one that starts and ends with __ (user_data.cc L185-L197). That rejection is correct. The problem is that the Windows plugin calls Set and Update without catching it:
DocumentReferenceSetandDocumentReferenceUpdatehave notry/catch.- The transaction commands (L1115-L1140) call
transaction.Set/Updatethe same way, on the SDK's transaction thread.
The exception leaves the Pigeon handler on the platform thread, and the process terminates (0xe06d7363, uncaught C++ exception).
WriteBatchCommit already does the right thing: it catches std::exception and returns a FlutterError (L1776-L1779). So the same invalid data fails cleanly in a batch but crashes the app in set(), update() and transactions. Android wraps documentReferenceSet in try/catch and sends the error to Dart (FlutterFirebaseFirestorePlugin.java L645-L675).
Evidence from production
Our Windows desktop app writes query results as maps keyed by column name. A SQL Server query SELECT 1 returns a column with an empty name, so the app wrote {'': 1}. Several customers' apps then closed about 20 seconds after every start, because the pending write retried on each launch. We had no error report from any of them; we only found the cause through Windows minidumps a customer sent us:
- Exception
0xe06d7363, thrown typestd::invalid_argument(catchable typesinvalid_argument,logic_error,exception), on the platform thread. - Throw site: the C++ SDK's
UserDataConverterfield-name check, the "Document fields must not be empty" branch. - Call chain: platform channel → cloud_firestore Pigeon handler →
DocumentReference::Set→ParseData→ field-name validation. - Seen on Windows 11 (build 26100) and Windows Server 2019 (build 17763).
We observed the empty-name case in production. The __x__ case goes through the same check, so we expect the same crash, but we haven't observed it.
The broader problem
The Windows plugin has no general rule that native failures become Dart errors. Each handler decides for itself, and several don't catch at all. Other examples:
ParseQuerycatches exceptions but only prints tostderrand returns a defaultQuery(L1607-L1611), so the real error message never reaches Dart.- #18883: transactions on Windows can use a destroyed
Transactionobject. That is a different root cause (object lifetime, not a thrown exception), but users see the same thing: the app closes with no Dart error.
For a desktop app, a native exit with no Dart error is the hardest failure to fix remotely. The developer gets no stack trace or message, and must ask the user for crash dumps. An invalid write should fail like it does on Android, with an exception the app can catch and report.
Reproducing the issue
// Windows desktop
try {
await FirebaseFirestore.instance.collection('test').doc('a').set({'': 1});
// Also expected to crash: {'__x__': 1}, {'row': {'': 1}}, update(),
// and transaction.set() with the same data.
} catch (e) {
print('caught: $e'); // never reached on Windows: the process exits
}
Expected (as on Android): a FirebaseException with code invalid-argument and the SDK's message, for example "Invalid data. Document fields must not be empty".
Actual on Windows: the process exits with 0xe06d7363.
We reconstructed this from the minidumps and the source above. We haven't run this exact snippet in an isolated Windows project.
Firebase Core version
firebase_core 3.15.2 (Firebase C++ SDK 12.7.0) in production, with cloud_firestore 5.6.12. The affected handlers are unchanged on current main (13420be, cloud_firestore 7.1.0, C++ SDK 14.1.0).
Flutter Version
3.35.3 stable (Windows desktop)
Additional context and comments
A possible fix:
- Wrap every Pigeon handler and the transaction update function in
try/catch (const std::exception&), likeWriteBatchCommit. Return aFlutterErrorwith codeinvalid-argumentande.what()as the message. - In
ParseQuery, report the caught error to Dart instead of printing it and returning a defaultQuery. - Optionally, validate field names in Dart before calling the platform, so every platform fails the same way.
Happy to open a PR for the first point if that approach works for you.
- Ngôn ngữ chính
- Dart
- Star
- 9.3k
- Fork
- 4.1k
- Merge trung bình
- 2 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 78
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của firebase/flutterfire
-
🚀 [firebase_core] Bump Firebase C++ SDK (14.1.0 → 14.2.0)Có thể đã có người làm @SelaseKay đã nhận hôm nay. Đang mởNeeds Attention type: enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
firebase/flutterfire#18977 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[firebase_core_web]: Firebase.initializeApp never completes when a Firebase JS SDK script fails to loadCó thể đã có người làm @LasseLegarth đã nhận 5 ngày trước. Đang mởNeeds Attention platform: web plugin: core reproduced type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
firebase/flutterfire#18964 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Needs Attention platform: android plugin: crashlytics type: enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
firebase/flutterfire#18951 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
blocked: external dependency platform: web plugin: ai type: bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
firebase/flutterfire#18938 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Needs Attention plugin: ai type: enhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 67/100
firebase/flutterfire#18917 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của firebase/flutterfire
Issue tương tự
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
[BUG] 172.2* 排除域名包含公网IPĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
-
agent: is checked on a wrapper holding several checkables answers from the first one in tree orderĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
AlphaWaveSystems/flutter-probe#865 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
ubuntu/app-center#2306 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
spotiflacapp/SpotiFLAC-Mobile#923 ·