Skip to content

Commit ca8c2c8

Browse files
committed
added int range checks
1 parent aa89472 commit ca8c2c8

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

lib/go/thrift/framed_transport.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"encoding/binary"
2727
"fmt"
2828
"io"
29+
"math"
2930
)
3031

3132
// Deprecated: Use DEFAULT_MAX_FRAME_SIZE instead.
@@ -60,8 +61,13 @@ func NewTFramedTransportFactory(factory TTransportFactory) TTransportFactory {
6061

6162
// Deprecated: Use NewTFramedTransportFactoryConf instead.
6263
func NewTFramedTransportFactoryMaxLength(factory TTransportFactory, maxLength uint32) TTransportFactory {
64+
safeMax := maxLength
65+
if safeMax > math.MaxInt32 {
66+
safeMax = math.MaxInt32
67+
}
68+
6369
return NewTFramedTransportFactoryConf(factory, &TConfiguration{
64-
MaxFrameSize: int32(maxLength),
70+
MaxFrameSize: int32(safeMax),
6571

6672
noPropagation: true,
6773
})
@@ -196,8 +202,12 @@ func (p *TFramedTransport) WriteString(s string) (n int, err error) {
196202
}
197203

198204
func (p *TFramedTransport) Flush(ctx context.Context) error {
199-
defer bufPool.put(&p.writeBuf)
200205
size := p.writeBuf.Len()
206+
if size > math.MaxUint32 {
207+
return NewTTransportException(UNKNOWN_TRANSPORT_EXCEPTION, fmt.Sprintf("frame too large: %d bytes exceeds uint32 max",size))
208+
}
209+
210+
defer bufPool.put(&p.writeBuf)
201211
buf := p.buffer[:4]
202212
binary.BigEndian.PutUint32(buf, uint32(size))
203213
_, err := p.transport.Write(buf)

0 commit comments

Comments
 (0)