{"record":{"id":"229c0afc5e028836","repo":"txthinking/brook","slug":"data-too-small-229c0a","errorCode":null,"errorMessage":"data too small","messagePattern":"data too small","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"simplepacketserverconn.go","lineNumber":42,"sourceCode":"\n\t\"github.com/txthinking/socks5\"\n)\n\ntype SimplePacketServerConnFactory struct {\n\tConns map[string]*PacketConn\n\tLock  *sync.Mutex\n}\n\nfunc NewSimplePacketServerConnFactory() *SimplePacketServerConnFactory {\n\treturn &SimplePacketServerConnFactory{\n\t\tConns: make(map[string]*PacketConn),\n\t\tLock:  &sync.Mutex{},\n\t}\n}\n\nfunc (f *SimplePacketServerConnFactory) Handle(addr *net.UDPAddr, b, p []byte, w func([]byte) (int, error), timeout int) (net.Conn, []byte, error) {\n\tif len(b) < 32+4 {\n\t\treturn nil, nil, errors.New(\"data too small\")\n\t}\n\tif bytes.Compare(p, b[:32]) != 0 {\n\t\treturn nil, nil, errors.New(\"Password is wrong\")\n\t}\n\ti := int64(binary.BigEndian.Uint32(b[32 : 32+4]))\n\tif time.Now().Unix()-i > 60 {\n\t\treturn nil, nil, errors.New(\"Expired request\")\n\t}\n\ta, h, p, err := socks5.ParseBytesAddress(b[32+4:])\n\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\tdst := socks5.ToAddress(a, h, p)\n\tf.Lock.Lock()\n\tc, ok := f.Conns[addr.String()+dst]\n\tf.Lock.Unlock()\n\tif ok {\n\t\t_ = c.In(b[32+4+1+len(h)+2:])","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/txthinking/brook/blob/5cd13ef3b1fb574e88ebf2c1b5d95f2ebe1342c8/simplepacketserverconn.go#L24-L60","documentation":"SimplePacketServerConnFactory.Handle validates an incoming UDP packet used to establish a packet-based connection. The packet must be at least 32 bytes of password + 4 bytes of big-endian timestamp; if len(b) < 36 the packet is malformed or truncated, and this error is returned before any further processing.","triggerScenarios":"Calling Handle (directly or via the packet server) with a payload shorter than 36 bytes: an empty datagram, a client sending only the password (32 bytes) without the timestamp/payload, packet truncation, or a client speaking an older/different protocol version.","commonSituations":"Version mismatch between client and server protocol implementations; port scanners or random UDP traffic hitting the listening socket; MTU/fragmentation dropping the tail of a datagram; misconfigured client omitting the timestamp field.","solutions":["Update the client to send password (32 bytes) + timestamp (4 bytes) + payload; verify with a length check before sending.","Ensure client and server use the same protocol version and packet framing.","Log the offending source address (addr) to identify scanners or misbehaving clients and drop them silently.","Check network path (MTU, proxies, NAT) for datagram truncation."],"exampleFix":"// before (client)\nbuf := make([]byte, 32)\ncopy(buf, password)\nconn.Write(buf) // server: \"data too small\"\n// after\nbuf := make([]byte, 32+4)\ncopy(buf, password)\nbinary.BigEndian.PutUint32(buf[32:], uint32(time.Now().Unix()))\nbuf = append(buf, payload...)\nconn.Write(buf)","handlingStrategy":"validation","validationCode":"func packetIsValid(b []byte) bool {\n    return len(b) >= 32+4\n}\n// client side, before sending:\n// if len(packet) < 36 { return errors.New(\"packet framing broken\") }","typeGuard":"func isWellFormedPacket(b []byte) bool {\n    return len(b) >= 36\n}","tryCatchPattern":"conn, rest, err := factory.Handle(addr, b, password, w, timeout)\nif err != nil {\n    if strings.Contains(err.Error(), \"data too small\") {\n        // log addr, drop packet silently; likely scanner/misconfigured client\n        return\n    }\n    return err\n}","preventionTips":["Pin client and server to the same protocol version.","On the client, assert packet length >= 36 before send.","Monitor logs for repeated short-packet sources and firewall scanners.","Beware MTU issues on UDP paths carrying large datagrams."],"tags":["udp","packet-validation","protocol","payload-too-small"],"backgroundTag":"payload-too-large","analyzedSha":"5cd13ef3b1fb574e88ebf2c1b5d95f2ebe1342c8","analyzedAt":"2026-09-06T04:35:00.432Z","contentChangedAt":"2026-09-06T04:35:00.432Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}