Skip to content
Snippets Groups Projects
Commit aeb4057e authored by alexstocks's avatar alexstocks
Browse files

Fix: issue 380

parent 082cc62b
No related branches found
No related tags found
No related merge requests found
...@@ -75,7 +75,13 @@ func (p *DubboPackage) Marshal() (*bytes.Buffer, error) { ...@@ -75,7 +75,13 @@ func (p *DubboPackage) Marshal() (*bytes.Buffer, error) {
} }
func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, opts ...interface{}) error { 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 // read header
err := codec.ReadHeader(&p.Header) err := codec.ReadHeader(&p.Header)
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
package dubbo package dubbo
import ( import (
"bytes"
"testing" "testing"
"time" "time"
) )
...@@ -25,6 +26,7 @@ import ( ...@@ -25,6 +26,7 @@ import (
import ( import (
hessian "github.com/apache/dubbo-go-hessian2" hessian "github.com/apache/dubbo-go-hessian2"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
perrors "github.com/pkg/errors"
) )
func TestDubboPackage_MarshalAndUnmarshal(t *testing.T) { func TestDubboPackage_MarshalAndUnmarshal(t *testing.T) {
...@@ -72,3 +74,10 @@ 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, []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]) 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
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