Fix aead request overflow

This commit is contained in:
世界 2022-07-15 11:16:00 +08:00
parent a6fa7ada6e
commit dacfbcd606
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
9 changed files with 17 additions and 9 deletions

View file

@ -1,7 +1,7 @@
package shadowsocks package shadowsocks
//go:generate go install -v mvdan.cc/gofumpt@latest //go:generate go install -v mvdan.cc/gofumpt@latest
//go:generate go install -v github.com/daixiang0/gci@latest //go:generate go install -v github.com/daixiang0/gci@v0.4.0
//go:generate gofumpt -l -w . //go:generate gofumpt -l -w .
//go:generate gofmt -s -w . //go:generate gofmt -s -w .
//go:generate gci write . //go:generate gci write -s "standard,prefix(github.com/sagernet/),default" .

View file

@ -379,18 +379,18 @@ type BufferedWriter struct {
} }
func (w *BufferedWriter) Write(p []byte) (n int, err error) { func (w *BufferedWriter) Write(p []byte) (n int, err error) {
var index int
for { for {
cachedN := copy(w.data[w.reversed+w.index:], p[index:]) cachedN := copy(w.data[w.reversed+w.index:], p[n:])
if cachedN == len(p[index:]) { w.index += cachedN
w.index += cachedN if cachedN == len(p[n:]) {
return cachedN, nil n += cachedN
return
} }
err = w.Flush() err = w.Flush()
if err != nil { if err != nil {
return return
} }
index += cachedN n += cachedN
} }
} }
@ -412,6 +412,7 @@ func (w *BufferedWriter) Flush() error {
increaseNonce(w.upstream.nonce) increaseNonce(w.upstream.nonce)
_, err := w.upstream.upstream.Write(w.upstream.buffer[:w.reversed+offset+len(packet)]) _, err := w.upstream.upstream.Write(w.upstream.buffer[:w.reversed+offset+len(packet)])
w.reversed = 0 w.reversed = 0
w.index = 0
return err return err
} }

View file

@ -14,6 +14,7 @@ import (
M "github.com/sagernet/sing/common/metadata" M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network" N "github.com/sagernet/sing/common/network"
"github.com/sagernet/sing/common/rw" "github.com/sagernet/sing/common/rw"
"golang.org/x/crypto/chacha20poly1305" "golang.org/x/crypto/chacha20poly1305"
"golang.org/x/crypto/hkdf" "golang.org/x/crypto/hkdf"
) )

View file

@ -19,6 +19,7 @@ import (
N "github.com/sagernet/sing/common/network" N "github.com/sagernet/sing/common/network"
"github.com/sagernet/sing/common/rw" "github.com/sagernet/sing/common/rw"
"github.com/sagernet/sing/common/udpnat" "github.com/sagernet/sing/common/udpnat"
"golang.org/x/crypto/chacha20poly1305" "golang.org/x/crypto/chacha20poly1305"
) )

View file

@ -8,7 +8,6 @@ import (
"crypto/sha256" "crypto/sha256"
"encoding/base64" "encoding/base64"
"encoding/binary" "encoding/binary"
"github.com/sagernet/sing/common/random"
"io" "io"
"math" "math"
mRand "math/rand" mRand "math/rand"
@ -26,7 +25,9 @@ import (
E "github.com/sagernet/sing/common/exceptions" E "github.com/sagernet/sing/common/exceptions"
M "github.com/sagernet/sing/common/metadata" M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network" N "github.com/sagernet/sing/common/network"
"github.com/sagernet/sing/common/random"
"github.com/sagernet/sing/common/rw" "github.com/sagernet/sing/common/rw"
"golang.org/x/crypto/chacha20poly1305" "golang.org/x/crypto/chacha20poly1305"
"lukechampine.com/blake3" "lukechampine.com/blake3"
) )

View file

@ -18,6 +18,7 @@ import (
M "github.com/sagernet/sing/common/metadata" M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network" N "github.com/sagernet/sing/common/network"
"github.com/sagernet/sing/common/udpnat" "github.com/sagernet/sing/common/udpnat"
"lukechampine.com/blake3" "lukechampine.com/blake3"
) )

View file

@ -27,6 +27,7 @@ import (
N "github.com/sagernet/sing/common/network" N "github.com/sagernet/sing/common/network"
"github.com/sagernet/sing/common/replay" "github.com/sagernet/sing/common/replay"
"github.com/sagernet/sing/common/udpnat" "github.com/sagernet/sing/common/udpnat"
"golang.org/x/crypto/chacha20poly1305" "golang.org/x/crypto/chacha20poly1305"
) )

View file

@ -20,6 +20,7 @@ import (
M "github.com/sagernet/sing/common/metadata" M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network" N "github.com/sagernet/sing/common/network"
"github.com/sagernet/sing/common/rw" "github.com/sagernet/sing/common/rw"
"lukechampine.com/blake3" "lukechampine.com/blake3"
) )

View file

@ -15,6 +15,7 @@ import (
"github.com/sagernet/sing/common/buf" "github.com/sagernet/sing/common/buf"
M "github.com/sagernet/sing/common/metadata" M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network" N "github.com/sagernet/sing/common/network"
"golang.org/x/crypto/chacha20" "golang.org/x/crypto/chacha20"
) )