Honor unlimited negotiated frame_max when capping inbound message size (backport #2015) - #2016
Merged
Conversation
AMQConnection derived the inbound frame payload limit with Math.min(maxInboundMessageBodySize, frameMax), but a negotiated frame_max of 0 means "no limit" (see negotiatedMaxValue and AMQCommand#transmit), not a literal zero. Math.min silently turned that into a limit of 0, which Utils.framePayloadLimit then treated as "no limit" again, so the configured message body cap was discarded in favor of an effectively unbounded frame size. A frame_max of 0 is reachable via the client's own default (requestedFrameMax is 0 unless overridden) whenever the broker also negotiates 0, so maxInboundMessageBodySize could end up unenforced without any non-default client configuration. Add Utils.inboundFrameMax to compute the effective limit correctly, with a UtilsTest covering the arithmetic directly and two InboundFrameMax cases exercising it end to end against a fake broker that negotiates frame_max=0. (cherry picked from commit 6d7c2bf)
connection.tune's frame_max is parsed via a signed 32-bit read, so a broker can send a value with the high bit set and have it come back negative once negotiated. Unlike negotiatedChannelMax and negotiatedHeartbeat, the negotiated frameMax was never validated afterwards. A negative frameMax reaching Utils.inboundFrameMax defeats the Math.min against maxInboundMessageBodySize, since the negative value is always the smaller one, then trips the same "frame_max <= 0 means no limit" fallback in Utils.framePayloadLimit that frame_max=0 relies on for its legitimate meaning, reintroducing the size-cap bypass without a broker ever needing to negotiate a literal 0. A non-default, positive requestedFrameMax is also enough to reach this on its own, with an otherwise honest broker, since negotiatedMaxValue only launders a negative value back to 0 when one side's value is exactly 0. Reject the negotiated frame max outright when negative, the same way the sibling channel max and heartbeat checks already do. (cherry picked from commit 89ed7ea)
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.
This is an automatic backport of pull request #2015 done by [Mergify](https://mergify.com).