{"record":{"id":"75cf7a6c93add96f","repo":"Pumpkin-MC/Pumpkin","slug":"invalid-packet-string-body-0","errorCode":null,"errorMessage":"Invalid packet string body: {0}","messagePattern":"Invalid packet string body: (.+?)","errorType":"exception","errorClass":"PacketError","httpStatus":null,"severity":"warning","filePath":"crates/pumpkin-protocol/src/rcon.rs","lineNumber":58,"sourceCode":"        buf.put_i32_le(id);\n        buf.put_i32_le(self as i32);\n        let bytes = body.as_bytes();\n        buf.put_slice(bytes);\n        buf.put_u8(0);\n        buf.put_u8(0);\n        buf\n    }\n}\n\n#[derive(Error, Debug)]\npub enum PacketError {\n    #[error(\"Invalid length\")]\n    InvalidLength,\n    #[error(\"Failed to send packet: {0}\")]\n    FailedSend(std::io::Error),\n    #[error(\"Missing packet null terminator\")]\n    MissingNullTerminator,\n    #[error(\"Invalid packet string body: {0}\")]\n    InvalidBody(std::str::Utf8Error),\n    #[error(\"Unknown packet type: {0}\")]\n    UnknownPacketType(i32),\n}\n\n#[derive(Debug, PartialEq, Eq)]\n/// Serverbound packet\npub struct Packet {\n    id: i32,\n    ptype: ServerboundPacket,\n    body: Box<str>,\n}\n\nimpl Packet {\n    pub fn deserialize(incoming: &mut Vec<u8>) -> Result<Option<Self>, PacketError> {\n        // We need at least 4 bytes to read the packet length header\n        if incoming.len() < 4 {\n            return Ok(None);","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-protocol/src/rcon.rs#L40-L76","documentation":"RconError::InvalidBody is thrown while decoding a Source RCON packet: the bytes between the packet header and its null terminator are not valid UTF-8, so the string body (the payload or command text) cannot be converted into a Rust String. The RCON protocol frames each packet as length/id/type/body/NUL; this error means the body bytes failed str::from_utf8. It indicates malformed or hostile client input, since the vanilla RCON client always sends UTF-8.","triggerScenarios":"Deserializing an inbound serverbound RCON packet via Packet::decode/read when the body region contains bytes that are not valid UTF-8 (e.g. binary garbage, wrong-encoding multi-byte sequences, or a truncated/mis-framed packet that shifts byte boundaries so non-text bytes land in the body).","commonSituations":"A non-Minecraft tool or script speaking the RCON protocol with a wrong text encoding (e.g. sending Latin-1 or GBK bytes); a fuzzing or attack client sending arbitrary binary payloads; a length-field mismatch after packet corruption so non-body bytes are parsed as the body.","solutions":["Log the packet id/type and the failing bytes; fix or drop the offending client sending non-UTF-8 bodies.","Ensure the sender encodes the body as UTF-8 before framing the packet.","If robustness is desired, sanitize/reject non-UTF-8 bytes at the connection layer before calling the decoder.","Verify packet length fields are parsed correctly so the body slice boundaries are right."],"exampleFix":"// before: server accepts any byte stream and panics/errors deep in decode\nlet body = std::str::from_utf8(body_bytes)?;\n\n// after: validate early and reject the client cleanly\nif std::str::from_utf8(body_bytes).is_err() {\n    connection.close(\"RCON body must be UTF-8\");\n    return;\n}","handlingStrategy":"validation","validationCode":"// Rust, before decoding: ensure the body slice is valid UTF-8\nfn body_is_utf8(body: &[u8]) -> bool { std::str::from_utf8(body).is_ok() }\nif !body_is_utf8(&body_bytes) {\n    drop_connection(\"non-UTF-8 RCON body\");\n}","typeGuard":"fn as_str_body(b: &[u8]) -> Option<&str> { std::str::from_utf8(b).ok() }","tryCatchPattern":"match packet::decode(&buf) {\n    Err(RconError::InvalidBody(e)) => debug!(\"dropping non-UTF-8 RCON packet: {e}\"),\n    Err(e) => warn!(\"rcon decode failed: {e}\"),\n    Ok(p) => handle(p),\n}","preventionTips":["Only allow trusted tools to connect to the RCON port and require the password.","Always encode RCON bodies as UTF-8 on the client side.","Log and drop malformed packets instead of propagating decode failures into handlers."],"tags":["rust","rcon","encoding","protocol","utf8"],"backgroundTag":"invalid-argument-format","analyzedSha":"8d4639e25a57c15e47448ec327c780d41bbf2356","analyzedAt":"2026-09-09T15:32:22.916Z","contentChangedAt":"2026-09-09T15:32:22.916Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}