Repository navigation
fix(buffa): bound recursive extension expansion depth in JSON and textproto - #849
Open
dev-burnern wants to merge 1 commit into
Open
dev-burnern wants to merge 1 commit into
dev-burnern wants to merge 1 commit into
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
This branch has not been deployed
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Bound recursive message-typed extension expansion depth during JSON serialization and textproto encoding, matching the existing
MAX_ANY_EXPANSION_DEPTHguard used forgoogle.protobuf.Any.Background
Message-typed protobuf extensions are stored in
UnknownFieldsas opaqueUnknownFieldData::LengthDelimited(Vec<u8>)during wire decoding (Message::decode), so the binary decoder'sRECURSION_LIMITdoes not bound deeply nested self-referential or mutually recursive message extensions. Whilegoogle.protobuf.Anyalready guards against unbounded expansion at serialize time viaenter_any_expansion()(JSON) andTextEncoder::any_depth(textproto), extension expansion had no equivalent depth check in either path.(Submitted as a stability hardening PR per Anthropic security triage recommendation.)
Changes
buffa/src/extension_registry.rs): Acquirecrate::type_registry::enter_any_expansion()inserialize_extensionsbefore invoking(entry.to_json)(...), returning aserde::ser::ErrorwhenMAX_ANY_EXPANSION_DEPTHis exceeded. Sharing the guard withAnyalso bounds alternatingAny↔ extension nesting.buffa/src/text/encoder.rs): ShareTextEncoder::any_depthinwrite_extension_fieldsto stop expanding pastMAX_ANY_EXPANSION_DEPTH(keeping output valid textproto and preserving theOkcontract forStringsinks). Also save/restoreself.ext_nameacross recursive calls so nested extensions do not clobber an outer repeated extension's name.buffa/src/extension_registry.rs,buffa/src/type_registry.rs):serialize_extensions_caps_recursive_depth: verifies shallow recursive extensions succeed andMAX_ANY_EXPANSION_DEPTH + 5levels fail cleanly with an error.write_extension_fields_caps_recursive_depth: verifiesMAX_ANY_EXPANSION_DEPTH + 5levels terminate cleanly atMAX_ANY_EXPANSION_DEPTHnested blocks.Verification
cargo test -p buffa --features json,text --lib(1,136 passed, 0 failed)cargo clippy -p buffa --features json,text --all-targets -- -D warningscargo check -p buffa --no-default-features --features json,textcargo fmt --checkcargo doc -p buffa --features json,text --no-deps