validate protobuf message index bounds on deserialize#2271
Open
uwezkhan wants to merge 1 commit into
Open
Conversation
|
🎉 All Contributor License Agreements have been signed. Ready to merge. |
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.
What
The protobuf deserializer picks the writer message type by walking the message-index array from the Confluent wire framing into the parsed
FileDescriptorProto.SchemaId._read_index_arraycaps the array length but not the individual index values, and those values are zigzag varints, so a crafted message can carry a negative or out-of-range index._get_message_desc_protothen indexesdesc.message_type/desc.nested_typewith the value directly.Before: a negative index (for example uvarint
0x01, which zigzag-decodes to-1) wraps around and resolves to a different message type in the same file, so the payload is decoded against the wrong descriptor. An out-of-range positive index raises a bareIndexError.After: an index outside
0 <= index < len(...)raisesSerializationErrorwith the index and the available count, matching the bound check the confluent-kafka-go reference (toMessageDesc) already applies. Valid indexes behave the same as today.Tradeoff: a message that previously decoded against an unintended message type now fails fast instead of returning a mis-typed object. That is the point of the change, but it does convert a silent wrong-result into a surfaced error.
Checklist
References
JIRA:
Test & Review
Added
test_message_index_in_rangeandtest_message_index_out_of_rangetotests/schema_registry/_async/test_proto.py(and the generated_synccounterpart). The out-of-range cases[-1],[2],[0, -1],[0, 5]reproduce the issue on master and pass after the change._syncfiles were regenerated withtools/unasync.py.Open questions / Follow-ups
None.