From c48eba79fde169354b8d3fb730d0f627254ea621 Mon Sep 17 00:00:00 2001 From: alexstocks Date: Sat, 29 Feb 2020 18:56:45 +0800 Subject: [PATCH 1/3] Fix: issue 380 --- protocol/dubbo/codec.go | 8 +++++++- protocol/dubbo/codec_test.go | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/protocol/dubbo/codec.go b/protocol/dubbo/codec.go index 3e50eb901d..76416b2baf 100644 --- a/protocol/dubbo/codec.go +++ b/protocol/dubbo/codec.go @@ -83,7 +83,13 @@ func (p *DubboPackage) Marshal() (*bytes.Buffer, error) { // Unmarshal ... func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, opts ...interface{}) error { - codec := hessian.NewHessianCodec(bufio.NewReaderSize(buf, buf.Len())) + // fix issue https://github.com/apache/dubbo-go/issues/380 + bufLen := buf.Len() + if bufLen < hessian.HEADER_LENGTH { + return perrors.WithStack(hessian.ErrHeaderNotEnough) + } + + codec := hessian.NewHessianCodec(bufio.NewReaderSize(buf, bufLen)) // read header err := codec.ReadHeader(&p.Header) diff --git a/protocol/dubbo/codec_test.go b/protocol/dubbo/codec_test.go index 149644a6ea..02ce02d205 100644 --- a/protocol/dubbo/codec_test.go +++ b/protocol/dubbo/codec_test.go @@ -18,6 +18,7 @@ package dubbo import ( + "bytes" "testing" "time" ) @@ -25,6 +26,7 @@ import ( import ( hessian "github.com/apache/dubbo-go-hessian2" "github.com/stretchr/testify/assert" + perrors "github.com/pkg/errors" ) func TestDubboPackage_MarshalAndUnmarshal(t *testing.T) { @@ -72,3 +74,10 @@ func TestDubboPackage_MarshalAndUnmarshal(t *testing.T) { assert.Equal(t, []interface{}{"a"}, pkgres.Body.([]interface{})[5]) assert.Equal(t, map[string]string{"dubbo": "2.0.2", "interface": "Service", "path": "path", "timeout": "1000", "version": "2.6"}, pkgres.Body.([]interface{})[6]) } + +func TestIssue380(t *testing.T) { + pkg := &DubboPackage{} + buf := bytes.NewBuffer([]byte("hello")) + err := pkg.Unmarshal(buf) + assert.True(t, perrors.Cause(err) == hessian.ErrHeaderNotEnough) +} \ No newline at end of file From d3a6bbba3b1dd96838109689b70646739836beb8 Mon Sep 17 00:00:00 2001 From: alexstocks Date: Sat, 29 Feb 2020 18:57:43 +0800 Subject: [PATCH 2/3] Add: issue 380 ut --- protocol/dubbo/codec_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/protocol/dubbo/codec_test.go b/protocol/dubbo/codec_test.go index 02ce02d205..5dc71f0d08 100644 --- a/protocol/dubbo/codec_test.go +++ b/protocol/dubbo/codec_test.go @@ -25,8 +25,8 @@ import ( import ( hessian "github.com/apache/dubbo-go-hessian2" - "github.com/stretchr/testify/assert" perrors "github.com/pkg/errors" + "github.com/stretchr/testify/assert" ) func TestDubboPackage_MarshalAndUnmarshal(t *testing.T) { @@ -79,5 +79,5 @@ func TestIssue380(t *testing.T) { pkg := &DubboPackage{} buf := bytes.NewBuffer([]byte("hello")) err := pkg.Unmarshal(buf) - assert.True(t, perrors.Cause(err) == hessian.ErrHeaderNotEnough) -} \ No newline at end of file + assert.True(t, perrors.Cause(err) == hessian.ErrHeaderNotEnough) +} From b109ee0dbcfcb43e33a7d6d04891744c9954682e Mon Sep 17 00:00:00 2001 From: alexstocks Date: Sat, 29 Feb 2020 19:55:20 +0800 Subject: [PATCH 3/3] Rem: go 1.12 in travis config --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index feb052a52f..7f30febe7b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ os: - osx go: - - "1.12" - "1.13" env: