1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-25 00:45:24 +00:00

better error handling in AuthenticationReader

This commit is contained in:
Darien Raymond 2016-12-07 00:49:56 +01:00
parent 919b749578
commit 5f2eb09226
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -36,10 +36,16 @@ func NewAuthenticationReader(aead cipher.AEAD, reader io.Reader, ivGen BytesGene
}
func (v *AuthenticationReader) NextChunk() error {
if v.buffer.Len() < 2 {
return errInsufficientBuffer
}
size := int(serial.BytesToUint16(v.buffer.BytesTo(2)))
if size > v.buffer.Len()-2 {
return errInsufficientBuffer
}
if size == v.aead.Overhead() {
return io.EOF
}
cipherChunk := v.buffer.BytesRange(2, size+2)
plainChunk, err := v.aead.Open(cipherChunk, v.ivGen(), cipherChunk, v.extraGen())
if err != nil {
@ -67,9 +73,11 @@ func (v *AuthenticationReader) Read(b []byte) (int, error) {
err := v.NextChunk()
if err == errInsufficientBuffer {
v.buffer.FillFrom(v.reader)
} else if err != nil {
return 0, io.ErrUnexpectedEOF
_, err = v.buffer.FillFrom(v.reader)
}
if err != nil {
return 0, err
}
totalBytes := 0