This is an automated email from the ASF dual-hosted git repository. jensg pushed a commit to branch 0.23.0 in repository https://gitbox.apache.org/repos/asf/thrift.git
commit 630d66c633a88bbae4a2a090fcb41f72dd1adc6a Author: Jens Geyer <[email protected]> AuthorDate: Wed Apr 8 23:06:45 2026 +0200 added int range checks --- lib/go/thrift/framed_transport.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/go/thrift/framed_transport.go b/lib/go/thrift/framed_transport.go index e3c323afc..00f277e18 100644 --- a/lib/go/thrift/framed_transport.go +++ b/lib/go/thrift/framed_transport.go @@ -26,6 +26,7 @@ import ( "encoding/binary" "fmt" "io" + "math" ) // Deprecated: Use DEFAULT_MAX_FRAME_SIZE instead. @@ -60,8 +61,13 @@ func NewTFramedTransportFactory(factory TTransportFactory) TTransportFactory { // Deprecated: Use NewTFramedTransportFactoryConf instead. func NewTFramedTransportFactoryMaxLength(factory TTransportFactory, maxLength uint32) TTransportFactory { + safeMax := maxLength + if safeMax > math.MaxInt32 { + safeMax = math.MaxInt32 + } + return NewTFramedTransportFactoryConf(factory, &TConfiguration{ - MaxFrameSize: int32(maxLength), + MaxFrameSize: int32(safeMax), noPropagation: true, }) @@ -196,8 +202,12 @@ func (p *TFramedTransport) WriteString(s string) (n int, err error) { } func (p *TFramedTransport) Flush(ctx context.Context) error { - defer bufPool.put(&p.writeBuf) size := p.writeBuf.Len() + if size > math.MaxUint32 { + return NewTTransportException(UNKNOWN_TRANSPORT_EXCEPTION, fmt.Sprintf("frame too large: %d bytes exceeds uint32 max",size)) + } + + defer bufPool.put(&p.writeBuf) buf := p.buffer[:4] binary.BigEndian.PutUint32(buf, uint32(size)) _, err := p.transport.Write(buf)
