mirror of https://github.com/v2ray/v2ray-core
fix auth reader buffer overrun
parent
32abea1397
commit
0cf5087852
|
@ -15,6 +15,7 @@ var (
|
||||||
|
|
||||||
errInsufficientBuffer = errors.New("Insufficient buffer.")
|
errInsufficientBuffer = errors.New("Insufficient buffer.")
|
||||||
errInvalidNonce = errors.New("Invalid nonce.")
|
errInvalidNonce = errors.New("Invalid nonce.")
|
||||||
|
errInvalidLength = errors.New("Invalid buffer size.")
|
||||||
)
|
)
|
||||||
|
|
||||||
type BytesGenerator interface {
|
type BytesGenerator interface {
|
||||||
|
@ -79,10 +80,14 @@ type AuthenticationReader struct {
|
||||||
aggressive bool
|
aggressive bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
readerBufferSize = 32 * 1024
|
||||||
|
)
|
||||||
|
|
||||||
func NewAuthenticationReader(auth Authenticator, reader io.Reader, aggressive bool) *AuthenticationReader {
|
func NewAuthenticationReader(auth Authenticator, reader io.Reader, aggressive bool) *AuthenticationReader {
|
||||||
return &AuthenticationReader{
|
return &AuthenticationReader{
|
||||||
auth: auth,
|
auth: auth,
|
||||||
buffer: buf.NewLocal(32 * 1024),
|
buffer: buf.NewLocal(readerBufferSize),
|
||||||
reader: reader,
|
reader: reader,
|
||||||
aggressive: aggressive,
|
aggressive: aggressive,
|
||||||
}
|
}
|
||||||
|
@ -96,6 +101,9 @@ func (v *AuthenticationReader) NextChunk() error {
|
||||||
if size > v.buffer.Len()-2 {
|
if size > v.buffer.Len()-2 {
|
||||||
return errInsufficientBuffer
|
return errInsufficientBuffer
|
||||||
}
|
}
|
||||||
|
if size > readerBufferSize-2 {
|
||||||
|
return errInvalidLength
|
||||||
|
}
|
||||||
if size == v.auth.Overhead() {
|
if size == v.auth.Overhead() {
|
||||||
return io.EOF
|
return io.EOF
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue