Prevent crashes when parsing malformed bundle payloads#16367
Prevent crashes when parsing malformed bundle payloads#16367cherylEnkidu wants to merge 1 commit into
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
Generated by 🚫 Danger |
#no-changelog
Summary
This PR fixes multiple vulnerabilities in bundle deserialization where parsing malformed JSON payloads caused uncaught C++ exceptions (
nlohmann::json::type_errorandnlohmann::json::out_of_range) to be thrown on the Firestore worker queue, resulting in process termination.Root Causes & Fix Details
DecodeCollectionSource:structuredQuery.fromwas only checked for presence, but not verified to be an array before call to.get_ref<const std::vector<json>&>()onfrom_json.from_json.is_array()that fails the reader gracefully if a non-array value is supplied.DecodeLimit:.at("value")on a limit object with no"value"key (e.g.,"limit":{}) threw anout_of_rangeexception.limit_object.contains("value")before callingat()..contains()/.at()calls inJsonReader:.contains()and.at()on primitives when a field was expected to be an object (but supplied as a primitive), causing nlohmann to throw type errors.JsonReader(Required*andOptional*methods) to first verify that the parent input value is a JSON object via.is_object().Verification
Added regression tests to
bundle_serializer_test.ccto verify that parsing failures are caught and handled gracefully (resulting inreader.status().ok()being false) rather than crashing the process:DecodeCollectionSourceFromNotArrayFails: Test Variant A payload (wherefromis a primitive string).DecodeLimitEmptyObjectFails: Test Variant B payload (wherelimitis{}).DecodePrimitiveAsObjectFails: Test payload where an object field (e.g.bundledQuery) is a primitive number.