Skip to content

Commit

Permalink
Merge pull request #381 from divebomb/develop
Browse files Browse the repository at this point in the history
Fix: issue #380
  • Loading branch information
zouyx authored Feb 29, 2020
2 parents 44edf4f + b109ee0 commit af5510b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ os:
- osx

go:
- "1.12"
- "1.13"

env:
Expand Down
8 changes: 7 additions & 1 deletion protocol/dubbo/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions protocol/dubbo/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
package dubbo

import (
"bytes"
"testing"
"time"
)

import (
hessian "github.com/apache/dubbo-go-hessian2"
perrors "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -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)
}

0 comments on commit af5510b

Please sign in to comment.