Skip to content

fix: bound nesting depth when deserializing enclosed payloads (#3500) - #3501

Open
pjfanning wants to merge 1 commit into
apache:1.7.xfrom
pjfanning:nest17
Open

fix: bound nesting depth when deserializing enclosed payloads (#3500)#3501
pjfanning wants to merge 1 commit into
apache:1.7.xfrom
pjfanning:nest17

Conversation

@pjfanning

Copy link
Copy Markdown
Member

cherry pick 3def397 #3500

…#3500)

Motivation:
Several of the remoting wire formats enclose a serialized payload whose enclosed
message is itself a serialized payload (for example Some, Optional, Status.Failure,
StatusReply, a Throwable cause, or an ActorSelectionMessage). Each level is parsed
separately, so neither a protobuf parser's own nesting limit nor the size of the
message bounds how deep the chain can go relative to the stack: the recursion tracks
the nesting rather than the number of bytes. A sufficiently deeply nested message
fails with a StackOverflowError rather than a serialization error.

Modification:
Add a per-thread nesting-depth counter (NestedDeserialization). A level is counted
where a serializer is actually invoked: Serialization.deserializeByteArray counts
one, and in WrappedPayloadSupport.deserializePayload the two branches that call a
serializer directly count one each, while the branch that delegates back to
Serialization leaves the counting to it. Nesting deeper than
pekko.actor.serialization-max-nesting-depth (default 32) is rejected with a
NotSerializableException. Ordinary nesting depths are unaffected.

Result:
An over-nested payload is rejected as an ordinary serialization error instead of
exhausting the stack.

Tests:
- sbt "remote/testOnly org.apache.pekko.remote.serialization.NestedPayloadDepthSpec" - 5 passed
- sbt "actor-tests/testOnly org.apache.pekko.serialization.SerializeSpec org.apache.pekko.serialization.WireManifestClassLoadingSpec" - 21 passed
- sbt "actor/mimaReportBinaryIssues" "remote/mimaReportBinaryIssues" - no issues
- scalafmt on the changed Scala sources

References:
None - robustness of nested payload deserialization
@pjfanning pjfanning added this to the 1.7.1 milestone Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant