fix(tonic): respect max_message_size when decompressing a message #2484
+160
−5
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 patch fixes a bug where the configured max_message_size is not respected when a payload is compressed, leading the possibility of over allocating and exhausting memory over the configured maximum message size when decompressing the message.
Motivation
When compression is enabled, and a compressed message is sent or received, the configured max_message_size (for both clients and servers) is only checked against the compressed message size and that limit is not respected for the resulting uncompressed message, which can lead to resource exhaustion.
Solution
Respect the configured, or default, max_message_size limit while decompressing a message, returning an error if the resultant decompressed message would exceed the limit.