From 0a26af32f1441d4ee57e423c693fa58cccf9ac64 Mon Sep 17 00:00:00 2001 From: chengpeng-wang <15705513022@163.com> Date: Sun, 9 Mar 2025 21:44:21 -0400 Subject: [PATCH 1/2] fix buf panic --- .../lib/go/thrift/simple_json_protocol.go | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/thirdparty/github.com/apache/thrift/lib/go/thrift/simple_json_protocol.go b/thirdparty/github.com/apache/thrift/lib/go/thrift/simple_json_protocol.go index 412a482d..3aa1e45b 100644 --- a/thirdparty/github.com/apache/thrift/lib/go/thrift/simple_json_protocol.go +++ b/thirdparty/github.com/apache/thrift/lib/go/thrift/simple_json_protocol.go @@ -565,6 +565,10 @@ func (p *TSimpleJSONProtocol) Transport() TTransport { } func (p *TSimpleJSONProtocol) OutputPreValue() error { + if len(p.dumpContext) == 0 { + return errors.New("dumpContext is empty") + } + cxt := _ParseContext(p.dumpContext[len(p.dumpContext)-1]) switch cxt { case _CONTEXT_IN_LIST, _CONTEXT_IN_OBJECT_NEXT_KEY: @@ -582,6 +586,10 @@ func (p *TSimpleJSONProtocol) OutputPreValue() error { } func (p *TSimpleJSONProtocol) OutputPostValue() error { + if len(p.dumpContext) == 0 { + return errors.New("dumpContext is empty") + } + cxt := _ParseContext(p.dumpContext[len(p.dumpContext)-1]) switch cxt { case _CONTEXT_IN_LIST_FIRST: @@ -608,6 +616,10 @@ func (p *TSimpleJSONProtocol) OutputBool(value bool) error { if e := p.OutputPreValue(); e != nil { return e } + if len(p.dumpContext) == 0 { + return errors.New("dumpContext is empty") + } + var v string if value { v = string(JSON_TRUE) @@ -648,6 +660,9 @@ func (p *TSimpleJSONProtocol) OutputF64(value float64) error { v = string(JSON_QUOTE) + JSON_NEGATIVE_INFINITY + string(JSON_QUOTE) } else { v = strconv.FormatFloat(value, 'g', -1, 64) + if len(p.dumpContext) == 0 { + return errors.New("dumpContext is empty") + } switch _ParseContext(p.dumpContext[len(p.dumpContext)-1]) { case _CONTEXT_IN_OBJECT_FIRST, _CONTEXT_IN_OBJECT_NEXT_KEY: v = string(JSON_QUOTE) + v + string(JSON_QUOTE) @@ -664,6 +679,10 @@ func (p *TSimpleJSONProtocol) OutputI64(value int64) error { if e := p.OutputPreValue(); e != nil { return e } + if len(p.dumpContext) == 0 { + return errors.New("dumpContext is empty") + } + v := strconv.FormatInt(value, 10) switch _ParseContext(p.dumpContext[len(p.dumpContext)-1]) { case _CONTEXT_IN_OBJECT_FIRST, _CONTEXT_IN_OBJECT_NEXT_KEY: @@ -706,6 +725,10 @@ func (p *TSimpleJSONProtocol) OutputObjectEnd() error { if _, e := p.write(JSON_RBRACE); e != nil { return NewTProtocolException(e) } + if len(p.dumpContext) == 0 { + return errors.New("dumpContext is empty") + } + p.dumpContext = p.dumpContext[:len(p.dumpContext)-1] if e := p.OutputPostValue(); e != nil { return e @@ -728,6 +751,10 @@ func (p *TSimpleJSONProtocol) OutputListEnd() error { if _, e := p.write(JSON_RBRACKET); e != nil { return NewTProtocolException(e) } + if len(p.dumpContext) == 0 { + return errors.New("dumpContext is empty") + } + p.dumpContext = p.dumpContext[:len(p.dumpContext)-1] if e := p.OutputPostValue(); e != nil { return e @@ -752,6 +779,10 @@ func (p *TSimpleJSONProtocol) ParsePreValue() error { if e := p.readNonSignificantWhitespace(); e != nil { return NewTProtocolException(e) } + if len(p.parseContextStack) == 0 { + return errors.New("parseContextStack is empty") + } + cxt := _ParseContext(p.parseContextStack[len(p.parseContextStack)-1]) b, _ := p.reader.Peek(1) switch cxt { @@ -812,6 +843,10 @@ func (p *TSimpleJSONProtocol) ParsePostValue() error { if e := p.readNonSignificantWhitespace(); e != nil { return NewTProtocolException(e) } + if len(p.parseContextStack) == 0 { + return errors.New("parseContextStack is empty") + } + cxt := _ParseContext(p.parseContextStack[len(p.parseContextStack)-1]) switch cxt { case _CONTEXT_IN_LIST_FIRST: @@ -991,6 +1026,10 @@ func (p *TSimpleJSONProtocol) ParseObjectEnd() error { if isNull, err := p.readIfNull(); isNull || err != nil { return err } + if len(p.parseContextStack) == 0 { + return errors.New("parseContextStack is empty") + } + cxt := _ParseContext(p.parseContextStack[len(p.parseContextStack)-1]) if (cxt != _CONTEXT_IN_OBJECT_FIRST) && (cxt != _CONTEXT_IN_OBJECT_NEXT_KEY) { e := fmt.Errorf("Expected to be in the Object Context, but not in Object Context (%d)", cxt) @@ -1052,6 +1091,10 @@ func (p *TSimpleJSONProtocol) ParseListEnd() error { if isNull, err := p.readIfNull(); isNull || err != nil { return err } + if len(p.parseContextStack) == 0 { + return errors.New("parseContextStack is empty") + } + cxt := _ParseContext(p.parseContextStack[len(p.parseContextStack)-1]) if cxt != _CONTEXT_IN_LIST { e := fmt.Errorf("Expected to be in the List Context, but not in List Context (%d)", cxt) From a5eadd50933b9661f23fbdc005d663c6bfabd7b6 Mon Sep 17 00:00:00 2001 From: chengpeng-wang <15705513022@163.com> Date: Sun, 9 Mar 2025 22:25:58 -0400 Subject: [PATCH 2/2] fix bof panic and add errors package --- .../thrift/lib/go/thrift/simple_json_protocol.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/thirdparty/github.com/apache/thrift/lib/go/thrift/simple_json_protocol.go b/thirdparty/github.com/apache/thrift/lib/go/thrift/simple_json_protocol.go index 3aa1e45b..e06d291d 100644 --- a/thirdparty/github.com/apache/thrift/lib/go/thrift/simple_json_protocol.go +++ b/thirdparty/github.com/apache/thrift/lib/go/thrift/simple_json_protocol.go @@ -22,6 +22,7 @@ package thrift import ( "bufio" "bytes" + "errors" "encoding/base64" "encoding/json" "fmt" @@ -566,7 +567,7 @@ func (p *TSimpleJSONProtocol) Transport() TTransport { func (p *TSimpleJSONProtocol) OutputPreValue() error { if len(p.dumpContext) == 0 { - return errors.New("dumpContext is empty") + return errors.New("dumpContext is empty") } cxt := _ParseContext(p.dumpContext[len(p.dumpContext)-1]) @@ -617,7 +618,7 @@ func (p *TSimpleJSONProtocol) OutputBool(value bool) error { return e } if len(p.dumpContext) == 0 { - return errors.New("dumpContext is empty") + return errors.New("dumpContext is empty") } var v string @@ -661,7 +662,7 @@ func (p *TSimpleJSONProtocol) OutputF64(value float64) error { } else { v = strconv.FormatFloat(value, 'g', -1, 64) if len(p.dumpContext) == 0 { - return errors.New("dumpContext is empty") + return errors.New("dumpContext is empty") } switch _ParseContext(p.dumpContext[len(p.dumpContext)-1]) { case _CONTEXT_IN_OBJECT_FIRST, _CONTEXT_IN_OBJECT_NEXT_KEY: @@ -680,7 +681,7 @@ func (p *TSimpleJSONProtocol) OutputI64(value int64) error { return e } if len(p.dumpContext) == 0 { - return errors.New("dumpContext is empty") + return errors.New("dumpContext is empty") } v := strconv.FormatInt(value, 10) @@ -780,7 +781,7 @@ func (p *TSimpleJSONProtocol) ParsePreValue() error { return NewTProtocolException(e) } if len(p.parseContextStack) == 0 { - return errors.New("parseContextStack is empty") + return errors.New("parseContextStack is empty") } cxt := _ParseContext(p.parseContextStack[len(p.parseContextStack)-1]) @@ -1027,7 +1028,7 @@ func (p *TSimpleJSONProtocol) ParseObjectEnd() error { return err } if len(p.parseContextStack) == 0 { - return errors.New("parseContextStack is empty") + return errors.New("parseContextStack is empty") } cxt := _ParseContext(p.parseContextStack[len(p.parseContextStack)-1]) @@ -1092,7 +1093,7 @@ func (p *TSimpleJSONProtocol) ParseListEnd() error { return err } if len(p.parseContextStack) == 0 { - return errors.New("parseContextStack is empty") + return errors.New("parseContextStack is empty") } cxt := _ParseContext(p.parseContextStack[len(p.parseContextStack)-1])