fix: ssr panic

This commit is contained in:
gVisor bot 2023-10-22 23:39:46 +08:00
parent 32d5d90f3d
commit 4f0d1d141e

View file

@ -7,6 +7,7 @@ import (
"crypto/rc4" "crypto/rc4"
"encoding/base64" "encoding/base64"
"encoding/binary" "encoding/binary"
"errors"
"net" "net"
"strconv" "strconv"
"strings" "strings"
@ -107,6 +108,10 @@ func (a *authChainA) Decode(dst, src *bytes.Buffer) error {
dataLength := int(binary.LittleEndian.Uint16(src.Bytes()[:2]) ^ binary.LittleEndian.Uint16(a.lastServerHash[14:16])) dataLength := int(binary.LittleEndian.Uint16(src.Bytes()[:2]) ^ binary.LittleEndian.Uint16(a.lastServerHash[14:16]))
randDataLength := a.randDataLength(dataLength, a.lastServerHash, &a.randomServer) randDataLength := a.randDataLength(dataLength, a.lastServerHash, &a.randomServer)
length := dataLength + randDataLength length := dataLength + randDataLength
// Temporary workaround for https://github.com/Dreamacro/clash/issues/1352
if dataLength < 0 || randDataLength < 0 || length < 0 {
return errors.New("ssr crashing blocked")
}
if length >= 4096 { if length >= 4096 {
a.rawTrans = true a.rawTrans = true
@ -130,6 +135,11 @@ func (a *authChainA) Decode(dst, src *bytes.Buffer) error {
if dataLength > 0 && randDataLength > 0 { if dataLength > 0 && randDataLength > 0 {
pos += getRandStartPos(randDataLength, &a.randomServer) pos += getRandStartPos(randDataLength, &a.randomServer)
} }
// Temporary workaround for https://github.com/Dreamacro/clash/issues/1352
if pos < 0 || pos+dataLength < 0 || dataLength < 0 {
return errors.New("ssr crashing blocked")
}
wantedData := src.Bytes()[pos : pos+dataLength] wantedData := src.Bytes()[pos : pos+dataLength]
a.decrypter.XORKeyStream(wantedData, wantedData) a.decrypter.XORKeyStream(wantedData, wantedData)
if a.recvID == 1 { if a.recvID == 1 {