mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-25 06:36:05 +03:00
Fix: gRPC multi accepting empty bytes (#411)
This commit is contained in:
parent
b0e7ad9663
commit
0470381fe2
@ -38,7 +38,7 @@ func NewExisted(b []byte) *Buffer {
|
||||
|
||||
oLen := len(b)
|
||||
if oLen < Size {
|
||||
b = append(b, make([]byte, Size-oLen)...)
|
||||
b = b[:Size]
|
||||
}
|
||||
|
||||
return &Buffer{
|
||||
|
@ -100,7 +100,7 @@ func (h *HunkReaderWriter) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if cap(h.buf) == buf.Size {
|
||||
if cap(h.buf) >= buf.Size {
|
||||
b := h.buf
|
||||
h.index = len(h.buf)
|
||||
return buf.MultiBuffer{buf.NewExisted(b)}, nil
|
||||
|
@ -79,17 +79,21 @@ func (h *MultiHunkReaderWriter) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
||||
|
||||
var mb = make(buf.MultiBuffer, 0, len(h.buf))
|
||||
for _, b := range h.buf {
|
||||
if cap(b) >= buf.Size {
|
||||
mb = append(mb, buf.NewExisted(b))
|
||||
if len(b) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
if cap(b) >= buf.Size {
|
||||
mb = append(mb, buf.NewExisted(b))
|
||||
} else {
|
||||
nb := buf.New()
|
||||
nb.Extend(int32(len(b)))
|
||||
copy(nb.Bytes(), b)
|
||||
|
||||
mb = append(mb, nb)
|
||||
}
|
||||
|
||||
}
|
||||
return mb, nil
|
||||
}
|
||||
|
||||
@ -99,12 +103,15 @@ func (h *MultiHunkReaderWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
||||
return io.ErrClosedPipe
|
||||
}
|
||||
|
||||
hunk := &MultiHunk{Data: make([][]byte, len(mb))}
|
||||
hunks := make([][]byte, 0, len(mb))
|
||||
|
||||
for _, b := range mb {
|
||||
hunk.Data = append(hunk.Data, b.Bytes())
|
||||
if b.Len() > 0 {
|
||||
hunks = append(hunks, b.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
err := h.hc.Send(hunk)
|
||||
err := h.hc.Send(&MultiHunk{Data: hunks})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user