Skip to content

Commit

Permalink
fix(thrift): return err if sz < 0 for str/bin
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaost committed Nov 5, 2024
1 parent cb56ecb commit 4b9ff07
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions protocol/thrift/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ func (p BinaryProtocol) ReadBinary(buf []byte) (b []byte, l int, err error) {
if err != nil {
return nil, 0, errReadBin
}
if sz < 0 {
return nil, 0, errNegativeSize
}
l = 4 + int(sz)
if len(buf) < l {
return nil, 4, errReadBin
Expand All @@ -340,6 +343,9 @@ func (p BinaryProtocol) ReadString(buf []byte) (s string, l int, err error) {
if err != nil {
return "", 0, errReadStr
}
if sz < 0 {
return "", 0, errNegativeSize
}
l = 4 + int(sz)
if len(buf) < l {
return "", 4, errReadStr
Expand Down
3 changes: 3 additions & 0 deletions protocol/thrift/bufferreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ func (r *BufferReader) ReadBinary() (b []byte, err error) {
if err != nil {
return nil, err
}
if sz < 0 {
return nil, errNegativeSize
}
b = dirtmake.Bytes(int(sz), int(sz))
_, err = r.readBinary(b)
return
Expand Down

0 comments on commit 4b9ff07

Please sign in to comment.