leitzler commented on code in PR #3057:
URL: https://github.com/apache/thrift/pull/3057#discussion_r1819462379
##########
lib/go/thrift/binary_protocol.go:
##########
@@ -555,7 +555,28 @@ func safeReadBytes(size int32, trans io.Reader) ([]byte,
error) {
return nil, nil
}
- buf := new(bytes.Buffer)
- _, err := io.CopyN(buf, trans, int64(size))
- return buf.Bytes(), err
+ const readLimit = 10 * 1024 * 1024
Review Comment:
> why not just `io.CopyN` [...]?
I have no strong opinions in either direction, that works fine for me! The
reason I changed it was that `io.CopyN` uses more memory than this approach.
Looking at 40MB ask from the issue tracker, `io.CopyN` allocates:
```
main_test.go:36: 134217366 B/op 21 allocs/op - ask: 41943040,
data: 41943040
```
while this approach allocates:
```
main_test.go:44: 83886131 B/op 5 allocs/op - ask: 41943040,
data: 41943040
```
But the downside, as you said, is that we will allocate more than available
when we get a malformed message.
Let me know if I should change it to use `io.CopyN` instead!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]