mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 09:18:34 +00:00
buffer.go: Ensure extended part by Extend() & Resize() are all-zero
https://github.com/XTLS/Xray-core/pull/4655#issuecomment-2837693439
This commit is contained in:
parent
58c48664e2
commit
2eed70e17d
1 changed files with 7 additions and 0 deletions
|
@ -13,6 +13,8 @@ const (
|
||||||
Size = 8192
|
Size = 8192
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var zero = [Size * 10]byte{0}
|
||||||
|
|
||||||
var pool = bytespool.GetPool(Size)
|
var pool = bytespool.GetPool(Size)
|
||||||
|
|
||||||
// ownership represents the data owner of the buffer.
|
// ownership represents the data owner of the buffer.
|
||||||
|
@ -150,6 +152,7 @@ func (b *Buffer) Extend(n int32) []byte {
|
||||||
}
|
}
|
||||||
ext := b.v[b.end:end]
|
ext := b.v[b.end:end]
|
||||||
b.end = end
|
b.end = end
|
||||||
|
copy(ext, zero[:])
|
||||||
return ext
|
return ext
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,6 +201,7 @@ func (b *Buffer) Check() {
|
||||||
|
|
||||||
// Resize cuts the buffer at the given position.
|
// Resize cuts the buffer at the given position.
|
||||||
func (b *Buffer) Resize(from, to int32) {
|
func (b *Buffer) Resize(from, to int32) {
|
||||||
|
oldEnd := b.end
|
||||||
if from < 0 {
|
if from < 0 {
|
||||||
from += b.Len()
|
from += b.Len()
|
||||||
}
|
}
|
||||||
|
@ -210,6 +214,9 @@ func (b *Buffer) Resize(from, to int32) {
|
||||||
b.end = b.start + to
|
b.end = b.start + to
|
||||||
b.start += from
|
b.start += from
|
||||||
b.Check()
|
b.Check()
|
||||||
|
if b.end > oldEnd {
|
||||||
|
copy(b.v[oldEnd:b.end], zero[:])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance cuts the buffer at the given position.
|
// Advance cuts the buffer at the given position.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue