Skip to content

guard IsLocalResourceName against names missing documents segment#16396

Open
isl-Ramzi wants to merge 1 commit into
firebase:mainfrom
isl-Ramzi:bundle-resource-name-documents-guard
Open

guard IsLocalResourceName against names missing documents segment#16396
isl-Ramzi wants to merge 1 commit into
firebase:mainfrom
isl-Ramzi:bundle-resource-name-documents-guard

Conversation

@isl-Ramzi

Copy link
Copy Markdown
Contributor

A bundle whose document name matches the local project and database but stops before the documents segment, such as projects/<id>/databases/<db>, passes IsLocalResourceName and then reaches PopFirst(5) on a four-segment path, which trips a HARD_ASSERT and aborts the process. The same predicate gates DecodeName and IsLocalDocumentKey (the latter reachable from a document field's referenceValue), and bundle payloads handed to loadBundle are untrusted. Require the five-segment documents prefix in IsLocalResourceName so short names are rejected the way ExtractLocalPathFromResourceName already rejects them.

@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.

@ncooke3

ncooke3 commented Jul 14, 2026

Copy link
Copy Markdown
Member

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates IsLocalResourceName in serializer.cc to ensure that the resource path contains at least 5 segments and that the fifth segment is "documents", preventing assertions when stripping the prefix. It also adds unit tests to verify that decoding fails when the "documents" segment is missing. The review feedback suggests using path.size() >= 5 instead of path.size() > 4 for consistency with other parts of the codebase, and improving the formatting of the JSON string in the new unit test.

Comment on lines +1523 to +1525
return IsValidResourceName(path) && path.size() > 4 &&
path[1] == database_id_.project_id() &&
path[3] == database_id_.database_id() && path[4] == "documents";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

For consistency with other parts of the codebase (such as ValidateDocumentKeyPath which checks resource_name.size() < 5 and ExtractLocalPathFromResourceName which checks resource_name.size() <= 4), consider using path.size() >= 5 instead of path.size() > 4. This directly aligns with the 5-segment prefix requirement described in the comments.

Suggested change
return IsValidResourceName(path) && path.size() > 4 &&
path[1] == database_id_.project_id() &&
path[3] == database_id_.database_id() && path[4] == "documents";
return IsValidResourceName(path) && path.size() >= 5 &&
path[1] == database_id_.project_id() &&
path[3] == database_id_.database_id() && path[4] == "documents";

Comment on lines +1238 to +1240
std::string json(
R"({"name":"projects/p/databases/default",
"readTime":{"seconds":"0","nanos":0}})");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The JSON string in the raw string literal can be formatted with proper indentation to improve readability.

Suggested change
std::string json(
R"({"name":"projects/p/databases/default",
"readTime":{"seconds":"0","nanos":0}})");
std::string json(
R"({
"name": "projects/p/databases/default",
"readTime": {"seconds": "0", "nanos": 0}
})");

@cherylEnkidu

Copy link
Copy Markdown
Contributor

Thank you for this PR! Adding the bounds and segment validation directly into Serializer::IsLocalResourceName is a very elegant solution to the root cause of this crash.

We currently have another PR in progress that we need to merge into the main branch first. Could we ask you to hold off on this PR until that one lands?

Once the other PR is merged, we will revisit this to get your holistic fix integrated. Thanks again for your excellent work on this!

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.

3 participants