Skip to content

Commit a2da660

Browse files
committed
validate resource name format before PopFirst in bundle parsing
1 parent 6f843d9 commit a2da660

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

Firestore/core/src/bundle/bundle_serializer.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ ResourcePath BundleSerializer::DecodeName(JsonReader& reader,
400400
}
401401
auto path =
402402
ResourcePath::FromString(document_name.get_ref<const std::string&>());
403-
if (!rpc_serializer_.IsLocalResourceName(path)) {
403+
if (!rpc_serializer_.IsLocalResourceName(path) || path.size() <= 4 ||
404+
path[4] != "documents") {
404405
reader.Fail("Resource name is not valid for current instance: " +
405406
path.CanonicalString());
406407
return {};

Firestore/core/src/remote/serializer.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,8 @@ bool Serializer::IsLocalResourceName(const ResourcePath& path) const {
15211521

15221522
bool Serializer::IsLocalDocumentKey(absl::string_view path) const {
15231523
auto resource = ResourcePath::FromStringView(path);
1524-
return IsLocalResourceName(resource) &&
1524+
return IsLocalResourceName(resource) && resource.size() > 4 &&
1525+
resource[4] == "documents" &&
15251526
DocumentKey::IsDocumentKey(resource.PopFirst(5));
15261527
}
15271528

0 commit comments

Comments
 (0)