fix: don't dereference a null superclass in the protobuf allow list check - #3509
Open
pjfanning wants to merge 1 commit into
Open
fix: don't dereference a null superclass in the protobuf allow list check#3509pjfanning wants to merge 1 commit into
pjfanning wants to merge 1 commit into
Conversation
…heck Motivation: ProtobufSerializer.isInAllowListClassName reads clazz.getSuperclass.getName unconditionally. getSuperclass is null for an interface, for Object and for a primitive, and the class it checks is the manifest from the wire, so a manifest naming an interface raised NullPointerException from the allow list check rather than the IllegalArgumentException that refusing a class is meant to produce. isInAllowList also evaluated isBoundToProtobufSerializer first, which calls serializerFor and raises, filling in a stack trace, for a class that is not bound - the common case for a class allowed only by name. Modification: Skip the superclass when there is none, and test the name list before the binding, which cannot throw. Both operands are pure predicates so the decision is unchanged. Result: An interface or Object manifest is refused with the allow list error instead of a NullPointerException.
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.
Motivation
This is the
pekko-remotehalf of the allow list ordering noted in #3503, and looking at itturned up something more than a reorder.
ProtobufSerializer.isInAllowListClassName(:196-200) readsclazz.getSuperclass.getNameunconditionally.
getSuperclassisnullfor an interface, forjava.lang.Objectand for aprimitive, and the class being checked is the manifest that arrived on the wire — so a manifest
naming an interface raises
NullPointerExceptionout of the allow list check instead of theIllegalArgumentExceptionthat refusing a class is supposed to produce. It is reachablewhenever the named class is not bound to a protobuf serializer, which is exactly the case the
allow list exists to refuse.
Separately,
isInAllowList(:183-185) evaluatedisBoundToProtobufSerializerfirst. Thatcalls
serializerFor, which raisesNotSerializableException— stack trace and all — for aclass that is not bound, which is the common case for a class allowed only by
pekko.serialization.protobuf.allowed-classes.Modification
Skip the superclass when there is none, and test the name list before the binding lookup, which
cannot throw. Both operands are pure predicates, so which one runs first does not change the
decision.
The ordering matters less here than in Jackson:
ProtobufSerializercaches its parsing handleafter the check (
:124-133), so it pays the cost once per class rather than once per message.The null dereference is the part worth fixing.
Result
An interface or
Objectmanifest is refused with the allow list error rather than aNullPointerException.Tests
sbt "remote/testOnly org.apache.pekko.remote.serialization.*"— 196 passed, 1 pendingTwo new tests in
ProtobufSerializerSpec, both checked to discriminate by reverting theproduction file and re-running — each then fails with
NullPointerException was thrown:reject an interface manifest rather than failing on its missing superclassreject java.lang.Object as a manifestsbt "remote/mimaReportBinaryIssues"— no issuessbt "remote/scalafmtCheckAll" headerCreateAll— cleanReferences
Completes the
isInAllowListordering from #3503, which changed the two Jackson serializers anddeliberately left this one out of a Jackson-scoped PR.