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

HessianCodec包头长度检查异常 #156

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

HessianCodec包头长度检查异常 #156

witkeysa opened this issue Feb 29, 2020 · 4 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.导致包头分包时,解包异常。

@Patrick0308
Copy link
Contributor

你的请求包头是小于16字节的?我看dubbo协议头部都已经大于16了,你收到请求包有问题

@witkeysa
Copy link
Author

收到的请求包没有问题,但是被分包了,比如说tcp收到的数据长度为200,200这个数据中有一个190长度的包,这个包解包没有问题,但是剩下的10长度的数据会被传到这个函数里解包,然后就会报错,导致这个会话就直接报错退出了

@AlexStocks
Copy link
Contributor

@witkeysa what you said is right.

@AlexStocks
Copy link
Contributor

@witkeysa I have reopen dubbo-go issue apache/dubbo-go#380 and submit pr apache/dubbo-go#381. so I will close this issue. [sorry Let u close issue 380 before.]

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

3 participants