Prevent crash due to large memory allocation (#291)

This commit is contained in:
Ambrose Chua 2024-05-06 10:10:23 +08:00 committed by GitHub
parent 09ed21d467
commit f34b6e85b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -160,6 +160,12 @@ func ReadFrame(reader io.Reader, addr net.Addr) (*Frame, error) {
if err != nil {
return nil, err
}
// Limit frame length to 2^21 - 1
if frame.Length > 2097151 {
return nil, errors.Errorf("frame length %d too large", frame.Length)
}
logrus.
WithField("client", addr).
WithField("length", frame.Length).