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

Bug: HessianCodec failed to check package header length #380

Closed
witkeysa opened this issue Feb 29, 2020 · 3 comments
Closed

Bug: HessianCodec failed to check package header length #380

witkeysa opened this issue Feb 29, 2020 · 3 comments

Comments

@witkeysa
Copy link

witkeysa commented Feb 29, 2020

func (h *HessianCodec) ReadHeader(header *DubboHeader) error {
var err error
if h.reader.Size() < HEADER_LENGTH {
	return ErrHeaderNotEnough
}
buf, err := h.reader.Peek(HEADER_LENGTH)
if err != nil { // this is impossible
	return perrors.WithStack(err)
}
...

这一段会检查长度是否大于包头长度。由下面这段调用。

// Unmarshal ...
func (p *DubboPackage) Unmarshal(buf *bytes.Buffer, opts ...interface{}) error {
codec := hessian.NewHessianCodec(bufio.NewReaderSize(buf, buf.Len()))

// read header
err := codec.ReadHeader(&p.Header)

但是在bufio.NewReaderSize(buf, buf.Len())中

func NewReaderSize(rd io.Reader, size int) *Reader {
// Is it already a Reader?
b, ok := rd.(*Reader)
if ok && len(b.buf) >= size {
return b
}
if size < minReadBufferSize {
size = minReadBufferSize
}
r := new(Reader)
r.reset(make([]byte, size), rd)
return r
}

这里创建出的reader长度永远大于16.导致包头分包时,解包异常。

@AlexStocks
Copy link
Contributor

@witkeysa maybe u should submit this issue to dubbo-go-hessian2?

@witkeysa
Copy link
Author

@witkeysa maybe u should submit this issue to dubbo-go-hessian2?

ok,thanks

@AlexStocks
Copy link
Contributor

@witkeysa I have fix this issue in #381 and this pr will be merged into develop branch later. pls check this branch and make sure this bug is fixed. If not, pls tell me again here.

zouyx added a commit that referenced this issue Feb 29, 2020
@AlexStocks AlexStocks changed the title HessianCodec包头长度检查异常 Bug: HessianCodec failed to check package header length Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants