{"record":{"id":"021c4fdd2ad34531","repo":"jackc/pgx","slug":"startup-message-too-short","errorCode":null,"errorMessage":"startup message too short","messagePattern":"startup message too short","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgproto3/startup_message.go","lineNumber":32,"sourceCode":"\tProtocolVersion30     = 196608            // 3.0\n\tProtocolVersion32     = 196610            // 3.2\n\tProtocolVersionLatest = ProtocolVersion32 // Latest is 3.2\n\tProtocolVersionNumber = ProtocolVersion30 // Default is still 3.0\n)\n\ntype StartupMessage struct {\n\tProtocolVersion uint32\n\tParameters      map[string]string\n}\n\n// Frontend identifies this message as sendable by a PostgreSQL frontend.\nfunc (*StartupMessage) Frontend() {}\n\n// Decode decodes src into dst. src must contain the complete message with the exception of the initial 1 byte message\n// type identifier and 4 byte message length.\nfunc (dst *StartupMessage) Decode(src []byte) error {\n\tif len(src) < 4 {\n\t\treturn errors.New(\"startup message too short\")\n\t}\n\n\tdst.ProtocolVersion = binary.BigEndian.Uint32(src)\n\trp := 4\n\n\tif dst.ProtocolVersion != ProtocolVersion30 && dst.ProtocolVersion != ProtocolVersion32 {\n\t\treturn fmt.Errorf(\"Bad startup message version number. Expected %d or %d, got %d\", ProtocolVersion30, ProtocolVersion32, dst.ProtocolVersion)\n\t}\n\n\tdst.Parameters = make(map[string]string)\n\tfor {\n\t\tidx := bytes.IndexByte(src[rp:], 0)\n\t\tif idx < 0 {\n\t\t\treturn &invalidMessageFormatErr{messageType: \"StartupMessage\"}\n\t\t}\n\t\tkey := string(src[rp : rp+idx])\n\t\trp += idx + 1\n","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgproto3/startup_message.go#L14-L50","documentation":"StartupMessage.Decode guard: the message body is too short to contain even the protocol version and parameter block required by the startup message format. A truncated or non-protocol byte stream at session start is the faulty input; realistic causes are a broken peer or reading garbage before a real startup packet.","triggerScenarios":"Thrown at pgproto3/startup_message.go:32 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the client speaks PostgreSQL protocol v3 and sends complete startup messages","Check for connection string/protocol mismatches (e.g. HTTP sent to a PG port)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}