Repository navigation
descriptor: reject a field or extension typed as a map entry it does not own - #720
Merged
iainmcgin merged 4 commits intoOct 20, 2026
Merged
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
… expected entry An extension whose type is a map entry now fails with PoolError::ExtensionWithMapEntryType, whatever its shape. protoc accepts one, a repeated extension of the entry's containing message that is named for the entry, and treats it as a map. The pool has no map extension, linking it as a list left the entry's own rules unchecked, and the code buffa-codegen emits for it names an entry struct that is not generated. InvalidMapEntryUse gains expected_entry, the full name a map field of that name requires of its entry, and its Display text gives the remedy for the case at hand: the field's shape when the name is right, the entry's name otherwise. The docs say which rules are stricter than protoc 33.5 (the extension, and a repeated group named for the entry), map_entry_name cites both protoc functions it mirrors, and the fragment names the one shape that linked as a working map before.
iainmcgin
reviewed
Oct 16, 2026
iainmcgin
left a comment
Collaborator
There was a problem hiding this comment.
[claude code] Thanks. The field rules are a faithful port of protoc, the pass-1 options change holds on every path traced, and the no_std fix is in. Pushed one maintainer commit on top (a2bc0a0), with one maintainer decision and the review fixes:
- Every extension whose type is a map entry is rejected, with the new
PoolError::ExtensionWithMapEntryType, including the one shape protoc compiles. The pool has no map extension, linking it as a list left the entry shape unchecked, and the codebuffa-codegenemits for it names an entry struct that is not generated. The docs name this as a rule stricter than protoc. InvalidMapEntryUsegainsexpected_entry, the full name a map field of that name requires of its entry. ItsDisplaytext gives the remedy for the case at hand: the field shape when the name is already right, the entry name otherwise. Both texts are asserted in tests.- Parity wording: the line numbers in the description are from protobuf
main. At v33.5,ValidateMapEntry(descriptor.cc:9135) has no group rule, so a repeated group named for the entry is accepted there. The pool still rejects it, and the variant doc says so. - Tests: the extension cases are one table of seven shapes, through
newanddecode; a rejection for a name that differs only in case;a_1bandFOO_BARnaming cases; the linked entry keeps its options. - The fragment is rewritten: the exact naming rule, the one shape that linked as a working map before and what to do about it, and the extension rule.
cargo test --workspace passes on this head (4279 passed, 0 failed), as do the no_std check and tests. The description will be updated to match.
iainmcgin
approved these changes
Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #637.
find_map_entrytreated a repeated message field as a map when its type was amap_entrymessage nested in the same message, without comparing the entry's name with the field's. Every field that failed that test linked as an ordinary message field. So a second repeated field of an entry's type linked as a second map, and a singular field, a field of another message, or an extension of an entry type linked as a message field.The pool now applies protoc's rule (
ValidateMapEntry, protoc v33.5descriptor.cc:9135): a map entry can be the type of one field only, the repeated message field of the entry's containing message whose name gives the entry's name (ToCamelCase(name, false)followed byEntry).PoolError::InvalidMapEntryUse { field, entry, expected_entry }.PoolError::ExtensionWithMapEntryType. Here the pool is stricter than protoc, which compilesextend Holder { repeated Holder.EntriesEntry entries = 100; }and treats it as a map. The pool has no map extension, and the codebuffa-codegenemits for that shape refers to an entry struct that is not generated. An ordinary message type withkey = 1andvalue = 2has the same wire form.mainbranch rejects it.One hand-built shape that linked as a working map before now fails: an entry nested in the right message under another name. Rename the entry, or clear
map_entryon a message that is not a map's entry.Not changed:
buffa-codegen's ownfind_map_entrydoes not check the entry name, so it still generates a map field for a misnamed entry, and withgenerate_reflectionthe generateddescriptor_pool()then panics on first use (#626).