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)
|
oLen := len(b)
|
||||||
if oLen < Size {
|
if oLen < Size {
|
||||||
b = append(b, make([]byte, Size-oLen)...)
|
b = b[:Size]
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Buffer{
|
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
|
b := h.buf
|
||||||
h.index = len(h.buf)
|
h.index = len(h.buf)
|
||||||
return buf.MultiBuffer{buf.NewExisted(b)}, nil
|
return buf.MultiBuffer{buf.NewExisted(b)}, nil
|
||||||
|
@ -79,16 +79,20 @@ func (h *MultiHunkReaderWriter) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
|||||||
|
|
||||||
var mb = make(buf.MultiBuffer, 0, len(h.buf))
|
var mb = make(buf.MultiBuffer, 0, len(h.buf))
|
||||||
for _, b := range h.buf {
|
for _, b := range h.buf {
|
||||||
if cap(b) >= buf.Size {
|
if len(b) == 0 {
|
||||||
mb = append(mb, buf.NewExisted(b))
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
nb := buf.New()
|
if cap(b) >= buf.Size {
|
||||||
nb.Extend(int32(len(b)))
|
mb = append(mb, buf.NewExisted(b))
|
||||||
copy(nb.Bytes(), b)
|
} else {
|
||||||
|
nb := buf.New()
|
||||||
|
nb.Extend(int32(len(b)))
|
||||||
|
copy(nb.Bytes(), b)
|
||||||
|
|
||||||
|
mb = append(mb, nb)
|
||||||
|
}
|
||||||
|
|
||||||
mb = append(mb, nb)
|
|
||||||
}
|
}
|
||||||
return mb, nil
|
return mb, nil
|
||||||
}
|
}
|
||||||
@ -99,12 +103,15 @@ func (h *MultiHunkReaderWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|||||||
return io.ErrClosedPipe
|
return io.ErrClosedPipe
|
||||||
}
|
}
|
||||||
|
|
||||||
hunk := &MultiHunk{Data: make([][]byte, len(mb))}
|
hunks := make([][]byte, 0, len(mb))
|
||||||
|
|
||||||
for _, b := range 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user