Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions lib/go/thrift/simple_json_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,12 @@ func (p *TSimpleJSONProtocol) ParseElemListBegin() (elemType TType, size int, e
if err != nil {
return elemType, 0, err
}
if nSize > math.MaxInt32 {
return elemType, 0, NewTProtocolExceptionWithType(
SIZE_LIMIT,
fmt.Errorf("size exceeded max allowed: %d", nSize),
)
}
err = checkSizeForProtocol(int32(nSize), p.cfg)
if err != nil {
return elemType, 0, err
Expand Down
29 changes: 29 additions & 0 deletions lib/go/thrift/simple_json_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,3 +791,32 @@ func TestJSONContextStack(t *testing.T) {
func TestTSimpleJSONProtocolUnmatchedBeginEnd(t *testing.T) {
UnmatchedBeginEndProtocolTest(t, NewTSimpleJSONProtocolFactory())
}

func TestReadSimpleJSONProtocolListBeginSizeOverflow(t *testing.T) {
// nSize = 1<<32 + 1; int32 narrowing wraps it to 1, which would pass checkSizeForProtocol.
// The list header is written directly as raw JSON to avoid int-width issues on 32-bit platforms.
overflowSize := int64(math.MaxInt32)*2 + 3 // = 4294967297 = 1<<32 + 1
for _, name := range []string{"list", "set"} {
t.Run(name, func(t *testing.T) {
buf := NewTMemoryBuffer()
buf.WriteString(fmt.Sprintf("[%d,%d]", I32, overflowSize))
proto := NewTSimpleJSONProtocolConf(buf, &TConfiguration{MaxMessageSize: 1024})
var err error
if name == "list" {
_, _, err = proto.ReadListBegin(context.Background())
} else {
_, _, err = proto.ReadSetBegin(context.Background())
}
if err == nil {
t.Fatal("expected error, got nil")
}
tpe, ok := err.(TProtocolException)
if !ok {
t.Fatalf("expected TProtocolException, got %T: %v", err, err)
}
if tpe.TypeId() != SIZE_LIMIT {
t.Errorf("expected SIZE_LIMIT, got %d: %v", tpe.TypeId(), err)
}
})
}
}
Loading