Skip to content
Open
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions thrift/protocol_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package thrift

import (
"encoding/binary"
"errors"
"io"
"math"
)
Expand Down Expand Up @@ -277,6 +278,14 @@ func (p *binaryProtocolReader) ReadFieldEnd() error {
return nil
}

func (p *binaryProtocolReader) validateSize(sz int) bool {
if fr, ok := p.r.(*FramedReadWriteCloser); ok {
return sz <= fr.rbuf.Len()
}

return true
}

func (p *binaryProtocolReader) ReadMapBegin() (keyType byte, valueType byte, size int, err error) {
if keyType, err = p.ReadByte(); err != nil {
return
Expand All @@ -287,6 +296,10 @@ func (p *binaryProtocolReader) ReadMapBegin() (keyType byte, valueType byte, siz
var sz int32
sz, err = p.ReadI32()
size = int(sz)

if !p.validateSize(size) {
err = errors.New("map is too large")
Copy link
Contributor

Choose a reason for hiding this comment

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

Include the invalid size?

}
return
}

Expand All @@ -301,6 +314,10 @@ func (p *binaryProtocolReader) ReadListBegin() (elementType byte, size int, err
var sz int32
sz, err = p.ReadI32()
size = int(sz)

if !p.validateSize(size) {
err = errors.New("list is too large")
Copy link
Contributor

Choose a reason for hiding this comment

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

Include the invalid size?

}
return
}

Expand Down