-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
rpc_util: Throws error if message is larger than MaxRecvMsgSize #6999
Conversation
Also prevents int overflow in bufferSize
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #6999 +/- ##
==========================================
- Coverage 82.43% 82.36% -0.08%
==========================================
Files 296 300 +4
Lines 31473 31381 -92
==========================================
- Hits 25946 25847 -99
+ Misses 4468 4467 -1
- Partials 1059 1067 +8
|
@Aditya-Sood -- could you please resolve the merge conflicts to the file due to this change 5ccf176? Also, seems like we are missing some coverage. Do you mind adding in some units to test the scenario? |
return nil, size + n, fmt.Errorf("overflow: message larger than max size receivable by client (%v bytes)", maxReceiveMessageSize) | ||
} | ||
} | ||
|
||
return buf.Bytes(), int(bytesRead), err | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will also need fixes below here in case DecompressedSize
is not implemented by the compressor.
As @arvindbr8 mentioned, we'll also want tests for overflowing the max message size with both kinds of compressors, too (some may already exist), and also covering the case where the max size is set to MaxInt
. I guess we can't test overflowing with MaxInt
very easily, though. Maybe 2GB (on a 32-bit system) isn't asking too much(?), but even that could be problematic.
I think a unit test of decompress
would be ideal here, with an internal way to override MaxInt
to a smaller value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @dfawley,
regarding the fixes for compressor
not implementing DecompressedSize
, could you please elaborate on what the intended behaviour should be?
I had the following changes in mind:
if sizer, ok := compressor.(interface {
DecompressedSize(compressedBytes []byte) int
}); ok {
...
} else {
log.Println("warn: compressor does not implement method DecompressedSize()")
}
d, err = io.ReadAll(io.LimitReader(dcReader, int64(maxReceiveMessageSize)))
if len(d) == maxReceiveMessageSize {
b := make([]byte, 1)
if n, err := dcReader.Read(b); n > 0 || err != io.EOF {
return nil, len(d) + n, fmt.Errorf("overflow: message larger than max size receivable by client (%v bytes)", maxReceiveMessageSize)
}
}
return d, len(d), err
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, something like that LGTM. It would be great if you can refactor the code to remove the duplication, though, since both code paths are very similar.
hi @arvindbr8, have resolved the merge conflict in the new commit |
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
have implemented the change for #6999 (comment) |
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
hi @arvindbr8, @dfawley I have been trying to trace the back the input tests which end up at do you have any advice on how I can figure this out? |
Why not just write a new Do not create messages of size |
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
got it @dfawley, I'll do it this weekend |
This PR is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed. |
Also prevents int overflow in bufferSize
Fixes #4552
RELEASE NOTES:
grpc.MaxRecvMsgSize(math.MaxInt)