Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: HessianCodec failed to check package header length(issue #380) #381

Merged
merged 3 commits into from
Feb 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
AlexStocks marked this conversation as resolved.
Show resolved Hide resolved
pkg := &DubboPackage{}
buf := bytes.NewBuffer([]byte("hello"))
err := pkg.Unmarshal(buf)
assert.True(t, perrors.Cause(err) == hessian.ErrHeaderNotEnough)
}