txthinking/brook · error
data too long
Error message
data too long
What it means
NewSimpleStreamServer reads a 2-byte length at b[32:34] and rejects values greater than 2048 with 'data too long', since the remainder cannot fit in the fixed 2048-byte pool buffer. This guards against buffer overflow from malformed or malicious length fields.
Source
Thrown at simplestreamserver.go:59
if err := client.SetDeadline(time.Now().Add(time.Duration(timeout) * time.Second)); err != nil {
return nil, err
}
}
s := &SimpleStreamServer{Client: client, Timeout: timeout, src: src}
b := x.BP2048.Get().([]byte)
if _, err := io.ReadFull(s.Client, b[:32+2]); err != nil {
x.BP2048.Put(b)
return nil, err
}
if bytes.Compare(password, b[:32]) != 0 {
x.BP2048.Put(b)
WaitReadErr(s.Client)
return nil, errors.New("Password is wrong")
}
l := int(binary.BigEndian.Uint16(b[32:34]))
if l > 2048 {
x.BP2048.Put(b)
return nil, errors.New("data too long")
}
if _, err := io.ReadFull(s.Client, b[:l]); err != nil {
x.BP2048.Put(b)
return nil, err
}
i := int64(binary.BigEndian.Uint32(b[:4]))
if time.Now().Unix()-i > 60 {
x.BP2048.Put(b)
WaitReadErr(s.Client)
return nil, errors.New("Expired request")
}
if i%2 == 0 {
s.network = "tcp"
s.RB = b
s.WB = x.BP2048.Get().([]byte)
}
if i%2 == 1 {
s.network = "udp"View on GitHub (pinned to 5cd13ef3b1)
Solutions
- Ensure the client writes the exact handshake layout: 32-byte password hash, then BigEndian uint16 length of the address at offset 32
- Check both ends run the same protocol version and same code path (tcp vs http wrapping)
- Log the offending l value and source IP to identify misbehaving or malicious clients
- Cap the address size on the client well below 2048 before sending
Example fix
// before (client, wrong layout) binary.BigEndian.PutUint16(b[34:36], uint16(len(dst))) // after binary.BigEndian.PutUint16(b[32:34], uint16(len(dst)))
Defensive patterns
Strategy: validation
Validate before calling
if len(dst) > 2048 {
return errors.New("destination exceeds protocol handshake limit of 2048 bytes")
} Try / catch
s, err := NewSimpleStreamServer(password, conn, ...)
if err != nil && err.Error() == "data too long" {
log.Printf("malformed handshake (oversized length) from %s", conn.RemoteAddr())
conn.Close()
} Prevention
- Match the client handshake layout exactly (hash, then uint16 length at offset 32)
- Keep addresses well below 2048 bytes on the client
- Use the same protocol version on both ends
- Log and monitor oversized-length rejections as potential attacks
When it happens
Trigger: The client writes a length prefix larger than 2048 (or a >16-bit-integer/garbage value lands at b[32:34]) in the handshake — a protocol violation, version mismatch, or a hostile client crafting a huge length.
Common situations: Client protocol version writing a different handshake layout (length at wrong offset); corrupted stream causing misaligned reads; attacker sending oversized length to probe the server; client sends raw address without the expected length framing.
Understand the failure class
Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.
Related errors
AI-assisted analysis of txthinking/brook@5cd13ef3b1 (2026-09-06).
Data as JSON: /api/errors/badace258226a862.
Report an issue: GitHub.