[FLINK-34620] Fix stack overflow in recursive protobuf message handling in flink-protobuf#28108
Open
khaledh wants to merge 1 commit intoapache:masterfrom
Open
[FLINK-34620] Fix stack overflow in recursive protobuf message handling in flink-protobuf#28108khaledh wants to merge 1 commit intoapache:masterfrom
flink-protobuf#28108khaledh wants to merge 1 commit intoapache:masterfrom
Conversation
Collaborator
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 is the purpose of the change
Protobuf allows recursive message definitions (e.g.,
message Node { Node child = 1; }). When Flink's protobuf format encounters such a schema,PbToRowTypeUtil.generateRowTyperecurses infinitely and crashes withStackOverflowError. This makes it impossible to use the protobuf format with any proto schema that contains recursive references.This change adds cycle detection to
PbToRowTypeUtil. When a message type is encountered that is already being resolved in the current ancestor chain, the recursive field is emitted asVARBINARY(raw protobuf bytes) instead of recursing. The protobuf binary data is preserved and can be deserialized on demand by consumers if needed.Brief change log
PbToRowTypeUtiltracks ancestor message types during schema generation and emitsVARBINARYfor fields that would cause infinite recursionPbCodegenBytesDeserializergenerates code to serialize recursive message fields to their raw protobuf bytes via.toByteArray()PbCodegenDeserializeFactoryroutes MESSAGE fields mapped toVARBINARYto the new bytes deserializerPbSchemaValidationUtilsacceptsVARBINARYas a valid mapping for MESSAGE fields at recursive boundariesVerifying this change
Note: This change has been reviewed and deployed internally at Shopify on production Flink jobs with no regressions since March 13, 2026.
This change added tests and can be verified as follows:
RecursiveMessageProtoToRowTestwith 6 tests covering:VARBINARYfor recursive fields instead of crashingreadDefaultValuessettingreadDefaultValues=false(explicit field presence)readDefaultValues=truetest_recursive_message.proto(proto3) andtest_recursive_message_proto2.proto(proto2) test protos with self-referencing message definitionsflink-protobuftests pass with no regressionsDoes this pull request potentially affect one of the following parts:
@Public(Evolving): noDocumentation
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code