Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc: fix message length checks when compression is enabled and maxReceiveMessageSize is MaxInt #7918

Merged
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b08845a
Fix test cases and update code to latest branch
vinothkumarr227 Dec 10, 2024
a02e58c
small tweaks
vinothkumarr227 Dec 11, 2024
54da70d
small tweaks
vinothkumarr227 Dec 12, 2024
4efd6fe
update code based on review feedback
vinothkumarr227 Dec 12, 2024
851d13a
fixed the changes based on review feedback
vinothkumarr227 Dec 13, 2024
26bf731
Added test cases for Handles maxReceiveMessageSize as MaxInt64
vinothkumarr227 Dec 17, 2024
3cf9054
Fixed the review changes
vinothkumarr227 Dec 18, 2024
27a68a0
Remove the casting for doesReceiveMessageOverflow
vinothkumarr227 Dec 18, 2024
3daef9b
Resolve all the issues
vinothkumarr227 Dec 18, 2024
8815cbd
Refactored code changes done
vinothkumarr227 Dec 18, 2024
5541486
test: switching to stubserver in tests instead of testservice (#7925)
pvsravani Dec 18, 2024
a21e192
cleanup: replace dial with newclient (#7920)
janardhanvissa Dec 18, 2024
09132bf
deps: update crypto dependency to resolve CVE-2024-45337 (#7956)
TomerJLevy Dec 20, 2024
5181e7b
test: Workaround slow SRV lookups in flaking test (#7957)
arjan-bal Dec 20, 2024
46faf72
envconfig: enable xDS client fallback by default (#7949)
easwars Dec 20, 2024
bd4989a
test: Add a test for decompression exceeding max receive message size…
arjan-bal Dec 23, 2024
985965a
outlierdetection: Support health listener for ejection updates (#7908)
arjan-bal Dec 23, 2024
8a0db4c
Revert "test: switching to stubserver in tests instead of testservice…
vinothkumarr227 Dec 23, 2024
cf12ace
Revert "cleanup: replace dial with newclient (#7920)"
vinothkumarr227 Dec 23, 2024
0e927fb
Revert "deps: update crypto dependency to resolve CVE-2024-45337 (#79…
vinothkumarr227 Dec 23, 2024
ee88fc0
Revert "envconfig: enable xDS client fallback by default (#7949)"
vinothkumarr227 Dec 23, 2024
4ef6aab
Revert "test: Add a test for decompression exceeding max receive mess…
vinothkumarr227 Dec 23, 2024
7ef57fd
Revert "outlierdetection: Support health listener for ejection update…
vinothkumarr227 Dec 23, 2024
20d4dc6
Revert the changes
vinothkumarr227 Dec 23, 2024
0907f9d
Revert the changes for test cases
vinothkumarr227 Dec 23, 2024
84e8a4f
Fix decompression size check and refactor based on review feedback
vinothkumarr227 Dec 23, 2024
77ea230
small tweaks
vinothkumarr227 Dec 24, 2024
6ff9321
Fixed the space formatting issues
vinothkumarr227 Dec 24, 2024
82124a4
Rename the test cases and refactor some of them
vinothkumarr227 Dec 24, 2024
4e9c665
Fix reviewed changes
vinothkumarr227 Jan 10, 2025
da82d30
small tweaks
vinothkumarr227 Jan 10, 2025
33962c2
Fixed test cases for decompress function
vinothkumarr227 Jan 10, 2025
23baa53
Fixed test cases for dock block
vinothkumarr227 Jan 10, 2025
7664e75
small tweaks
vinothkumarr227 Jan 10, 2025
6fb580c
Fixed review changes for the decompress function
vinothkumarr227 Jan 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
small tweaks
  • Loading branch information
vinothkumarr227 committed Jan 10, 2025
commit da82d307535222a9c374a7e13a847654364f1e15
8 changes: 3 additions & 5 deletions rpc_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"compress/gzip"
"context"
"encoding/binary"
"errors"
"fmt"
"io"
"math"
Expand Down Expand Up @@ -809,8 +808,6 @@
}
}

var errMaxMessageSizeExceeded = errors.New("max message size exceeded")

// recvAndDecompress reads a message from the stream, decompressing it if necessary.
//
// Cancelling the returned cancel function releases the buffer back to the pool. So the caller should cancel as soon as
Expand Down Expand Up @@ -852,24 +849,25 @@
return out, nil
}

// Using compressor, decompress d, returning data and size.
// If the decompressed data exceeds maxReceiveMessageSize, it returns errMaxMessageSizeExceeded.
// decompress decompresses the given data `d` using either a custom decompressor `dc`
// or a provided `compressor`. It checks if the decompressed data exceeds the
// `maxReceiveMessageSize` and returns an error if so.
func decompress(compressor encoding.Compressor, d mem.BufferSlice, dc Decompressor, maxReceiveMessageSize int, pool mem.BufferPool) (mem.BufferSlice, error) {
if dc != nil {
uncompressed, err := dc.Do(d.Reader())
if err != nil {
return nil, status.Errorf(codes.Internal, "grpc: failed to decompress the received message: %v", err)
}

Check warning on line 860 in rpc_util.go

View check run for this annotation

Codecov / codecov/patch

rpc_util.go#L859-L860

Added lines #L859 - L860 were not covered by tests
if len(uncompressed) > maxReceiveMessageSize {
return nil, status.Errorf(codes.ResourceExhausted, "grpc: message after decompression larger than max (%d vs. %d)", len(uncompressed), maxReceiveMessageSize)
}

Check warning on line 863 in rpc_util.go

View check run for this annotation

Codecov / codecov/patch

rpc_util.go#L862-L863

Added lines #L862 - L863 were not covered by tests
return mem.BufferSlice{mem.SliceBuffer(uncompressed)}, nil
}
if compressor != nil {
dcReader, err := compressor.Decompress(d.Reader())
if err != nil {
return nil, status.Errorf(codes.Internal, "grpc: failed to decompress the message: %v", err)
}

Check warning on line 870 in rpc_util.go

View check run for this annotation

Codecov / codecov/patch

rpc_util.go#L869-L870

Added lines #L869 - L870 were not covered by tests

out, err := mem.ReadAll(io.LimitReader(dcReader, int64(maxReceiveMessageSize)), pool)
if err != nil {
Expand All @@ -884,7 +882,7 @@
}
return out, nil
}
return d, nil

Check warning on line 885 in rpc_util.go

View check run for this annotation

Codecov / codecov/patch

rpc_util.go#L885

Added line #L885 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this an error scenario? If the payload is compressed (which is the only reason to call this function) and we don't have the decompressor, then we should error.

In reality, this can't happen because checkRecvPayload would prevent it, but this should still return an error, not a success.

}

// doesReceiveMessageOverflow checks if the number of bytes read from the stream
Expand Down
Loading