Skip to content

Prevent crashes when parsing malformed bundle payloads#16367

Open
cherylEnkidu wants to merge 1 commit into
mainfrom
cheryl/bundleDeserialization
Open

Prevent crashes when parsing malformed bundle payloads#16367
cherylEnkidu wants to merge 1 commit into
mainfrom
cheryl/bundleDeserialization

Conversation

@cherylEnkidu

@cherylEnkidu cherylEnkidu commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

#no-changelog

Summary

This PR fixes multiple vulnerabilities in bundle deserialization where parsing malformed JSON payloads caused uncaught C++ exceptions (nlohmann::json::type_error and nlohmann::json::out_of_range) to be thrown on the Firestore worker queue, resulting in process termination.

Root Causes & Fix Details

  1. Unchecked array access in DecodeCollectionSource:
    • Issue: structuredQuery.from was only checked for presence, but not verified to be an array before call to .get_ref<const std::vector<json>&>() on from_json.
    • Fix: Added a guard from_json.is_array() that fails the reader gracefully if a non-array value is supplied.
  2. Missing key check in DecodeLimit:
    • Issue: Calling .at("value") on a limit object with no "value" key (e.g., "limit":{}) threw an out_of_range exception.
    • Fix: Checked limit_object.contains("value") before calling at().
  3. Unchecked .contains() / .at() calls in JsonReader:
    • Issue: Downstream parsing code called .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.
    • Fix: Updated all lookup helper methods in JsonReader (Required* and Optional* methods) to first verify that the parent input value is a JSON object via .is_object().

Verification

Added regression tests to bundle_serializer_test.cc to verify that parsing failures are caught and handled gracefully (resulting in reader.status().ok() being false) rather than crashing the process:

  • DecodeCollectionSourceFromNotArrayFails: Test Variant A payload (where from is a primitive string).
  • DecodeLimitEmptyObjectFails: Test Variant B payload (where limit is {}).
  • DecodePrimitiveAsObjectFails: Test payload where an object field (e.g. bundledQuery) is a primitive number.

@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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.

@danger-firebase-ios

Copy link
Copy Markdown
1 Warning
⚠️ Did you forget to add a changelog entry? (Add #no-changelog to the PR description to silence this warning.)

Generated by 🚫 Danger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants