Commit 32f40833 authored by Levin Zimmermann's avatar Levin Zimmermann

fixup! go/proto/msgpack: Simplify debugging by printing function name in case of overflow

parent eda58438
...@@ -153,7 +153,8 @@ func testMsgMarshal(t *testing.T, enc Encoding, msg Msg, encoded string) { ...@@ -153,7 +153,8 @@ func testMsgMarshal(t *testing.T, enc Encoding, msg Msg, encoded string) {
// decode must detect buffer overflow // decode must detect buffer overflow
for l := len(encoded) - 1; l >= 0; l-- { for l := len(encoded) - 1; l >= 0; l-- {
n, err = enc.MsgDecode(msg2, data[:l]) n, err = enc.MsgDecode(msg2, data[:l])
if !(n == 0 && err == ErrDecodeOverflow) { errDecodeOverflow := new(ErrDecodeOverflow)
if !(n == 0 && errors.As(err, &errDecodeOverflow)) {
t.Errorf("%c/%v: decode overflow not detected on [:%v]", enc, typ, l) t.Errorf("%c/%v: decode overflow not detected on [:%v]", enc, typ, l)
} }
......
...@@ -320,6 +320,7 @@ package proto ...@@ -320,6 +320,7 @@ package proto
import ( import (
"encoding/binary" "encoding/binary"
"errors"
"math" "math"
"reflect" "reflect"
"sort" "sort"
...@@ -1155,7 +1156,8 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty ...@@ -1155,7 +1156,8 @@ func (d *decoderM) genBasic(assignto string, typ *types.Basic, userType types.Ty
// correct float, but data is too short - catch this to return // correct float, but data is too short - catch this to return
// 'ErrDecodeOverflow' instead of type error. // 'ErrDecodeOverflow' instead of type error.
d.emit(" err = mdecodeErr(%q, err)", d.pathName(assignto)) d.emit(" err = mdecodeErr(%q, err)", d.pathName(assignto))
d.emit(" if err == ErrDecodeOverflow {") d.emit(" errDecodeOverflow := new(ErrDecodeOverflow)")
d.emit(" if errors.As(err, &errDecodeOverflow) {")
d.emit(" return 0, err") d.emit(" return 0, err")
d.emit(" }") d.emit(" }")
d.emit(" tail, err = msgp.ReadNilBytes(data)") d.emit(" tail, err = msgp.ReadNilBytes(data)")
......
...@@ -6,6 +6,7 @@ package proto ...@@ -6,6 +6,7 @@ package proto
import ( import (
"encoding/binary" "encoding/binary"
"errors"
"math" "math"
"reflect" "reflect"
"sort" "sort"
...@@ -420,7 +421,8 @@ func (p *RequestIdentification) neoMsgDecodeM(data []byte) (int, error) { ...@@ -420,7 +421,8 @@ func (p *RequestIdentification) neoMsgDecodeM(data []byte) (int, error) {
v, tail, err := msgp.ReadFloat64Bytes(data) v, tail, err := msgp.ReadFloat64Bytes(data)
if err != nil { if err != nil {
err = mdecodeErr("RequestIdentification.IdTime", err) err = mdecodeErr("RequestIdentification.IdTime", err)
if err == ErrDecodeOverflow { errDecodeOverflow := new(ErrDecodeOverflow)
if errors.As(err, &errDecodeOverflow) {
return 0, err return 0, err
} }
tail, err = msgp.ReadNilBytes(data) tail, err = msgp.ReadNilBytes(data)
...@@ -1124,7 +1126,8 @@ func (p *NotifyNodeInformation) neoMsgDecodeM(data []byte) (int, error) { ...@@ -1124,7 +1126,8 @@ func (p *NotifyNodeInformation) neoMsgDecodeM(data []byte) (int, error) {
v, tail, err := msgp.ReadFloat64Bytes(data) v, tail, err := msgp.ReadFloat64Bytes(data)
if err != nil { if err != nil {
err = mdecodeErr("NotifyNodeInformation.IdTime", err) err = mdecodeErr("NotifyNodeInformation.IdTime", err)
if err == ErrDecodeOverflow { errDecodeOverflow := new(ErrDecodeOverflow)
if errors.As(err, &errDecodeOverflow) {
return 0, err return 0, err
} }
tail, err = msgp.ReadNilBytes(data) tail, err = msgp.ReadNilBytes(data)
...@@ -1228,7 +1231,8 @@ func (p *NotifyNodeInformation) neoMsgDecodeM(data []byte) (int, error) { ...@@ -1228,7 +1231,8 @@ func (p *NotifyNodeInformation) neoMsgDecodeM(data []byte) (int, error) {
v, tail, err := msgp.ReadFloat64Bytes(data) v, tail, err := msgp.ReadFloat64Bytes(data)
if err != nil { if err != nil {
err = mdecodeErr("NotifyNodeInformation.IdTime", err) err = mdecodeErr("NotifyNodeInformation.IdTime", err)
if err == ErrDecodeOverflow { errDecodeOverflow := new(ErrDecodeOverflow)
if errors.As(err, &errDecodeOverflow) {
return 0, err return 0, err
} }
tail, err = msgp.ReadNilBytes(data) tail, err = msgp.ReadNilBytes(data)
...@@ -4969,7 +4973,8 @@ func (p *AnswerRebaseObject) neoMsgDecodeM(data []byte) (int, error) { ...@@ -4969,7 +4973,8 @@ func (p *AnswerRebaseObject) neoMsgDecodeM(data []byte) (int, error) {
v, tail, err := msgp.ReadUint64Bytes(data) v, tail, err := msgp.ReadUint64Bytes(data)
if err != nil { if err != nil {
err = mdecodeErr("AnswerRebaseObject.Compression", err) err = mdecodeErr("AnswerRebaseObject.Compression", err)
if err == ErrDecodeOverflow { errDecodeOverflow := new(ErrDecodeOverflow)
if errors.As(err, &errDecodeOverflow) {
return 0, err return 0, err
} }
tail, err = msgp.ReadNilBytes(data) tail, err = msgp.ReadNilBytes(data)
...@@ -5190,7 +5195,8 @@ func (p *StoreObject) neoMsgDecodeM(data []byte) (int, error) { ...@@ -5190,7 +5195,8 @@ func (p *StoreObject) neoMsgDecodeM(data []byte) (int, error) {
v, tail, err := msgp.ReadUint64Bytes(data) v, tail, err := msgp.ReadUint64Bytes(data)
if err != nil { if err != nil {
err = mdecodeErr("StoreObject.Compression", err) err = mdecodeErr("StoreObject.Compression", err)
if err == ErrDecodeOverflow { errDecodeOverflow := new(ErrDecodeOverflow)
if errors.As(err, &errDecodeOverflow) {
return 0, err return 0, err
} }
tail, err = msgp.ReadNilBytes(data) tail, err = msgp.ReadNilBytes(data)
...@@ -6241,7 +6247,8 @@ func (p *AnswerObject) neoMsgDecodeM(data []byte) (int, error) { ...@@ -6241,7 +6247,8 @@ func (p *AnswerObject) neoMsgDecodeM(data []byte) (int, error) {
v, tail, err := msgp.ReadUint64Bytes(data) v, tail, err := msgp.ReadUint64Bytes(data)
if err != nil { if err != nil {
err = mdecodeErr("AnswerObject.Compression", err) err = mdecodeErr("AnswerObject.Compression", err)
if err == ErrDecodeOverflow { errDecodeOverflow := new(ErrDecodeOverflow)
if errors.As(err, &errDecodeOverflow) {
return 0, err return 0, err
} }
tail, err = msgp.ReadNilBytes(data) tail, err = msgp.ReadNilBytes(data)
...@@ -7777,7 +7784,8 @@ func (p *AnswerNodeList) neoMsgDecodeM(data []byte) (int, error) { ...@@ -7777,7 +7784,8 @@ func (p *AnswerNodeList) neoMsgDecodeM(data []byte) (int, error) {
v, tail, err := msgp.ReadFloat64Bytes(data) v, tail, err := msgp.ReadFloat64Bytes(data)
if err != nil { if err != nil {
err = mdecodeErr("AnswerNodeList.IdTime", err) err = mdecodeErr("AnswerNodeList.IdTime", err)
if err == ErrDecodeOverflow { errDecodeOverflow := new(ErrDecodeOverflow)
if errors.As(err, &errDecodeOverflow) {
return 0, err return 0, err
} }
tail, err = msgp.ReadNilBytes(data) tail, err = msgp.ReadNilBytes(data)
...@@ -13194,7 +13202,8 @@ func (p *AddObject) neoMsgDecodeM(data []byte) (int, error) { ...@@ -13194,7 +13202,8 @@ func (p *AddObject) neoMsgDecodeM(data []byte) (int, error) {
v, tail, err := msgp.ReadUint64Bytes(data) v, tail, err := msgp.ReadUint64Bytes(data)
if err != nil { if err != nil {
err = mdecodeErr("AddObject.Compression", err) err = mdecodeErr("AddObject.Compression", err)
if err == ErrDecodeOverflow { errDecodeOverflow := new(ErrDecodeOverflow)
if errors.As(err, &errDecodeOverflow) {
return 0, err return 0, err
} }
tail, err = msgp.ReadNilBytes(data) tail, err = msgp.ReadNilBytes(data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment