{"record":{"id":"580a42c99957afee","repo":"Pumpkin-MC/Pumpkin","slug":"invalid-bedrock-respawn-state-state","errorCode":null,"errorMessage":"invalid Bedrock respawn state {state}","messagePattern":"invalid Bedrock respawn state (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin-protocol/src/bedrock/server/respawn.rs","lineNumber":35,"sourceCode":"    pub state: RespawnState,\n    pub player_runtime_id: VarULong,\n}\n\n#[derive(Clone, Copy, Debug, PartialEq, Eq)]\n#[repr(u8)]\npub enum RespawnState {\n    SearchingForSpawn,\n    ReadyToSpawn,\n    ClientReadyToSpawn,\n}\n\nimpl PacketRead for RespawnState {\n    fn read<R: Read>(reader: &mut R) -> Result<Self, Error> {\n        match u8::read(reader)? {\n            0 => Ok(Self::SearchingForSpawn),\n            1 => Ok(Self::ReadyToSpawn),\n            2 => Ok(Self::ClientReadyToSpawn),\n            state => Err(Error::new(\n                ErrorKind::InvalidData,\n                format!(\"invalid Bedrock respawn state {state}\"),\n            )),\n        }\n    }\n}\n\nimpl PacketWrite for RespawnState {\n    fn write<W: Write>(&self, writer: &mut W) -> Result<(), Error> {\n        (*self as u8).write(writer)\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n    use crate::serial::PacketRead;\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-protocol/src/bedrock/server/respawn.rs#L17-L53","documentation":"Validation guard in RespawnState::read: the client sent a SRespawn (serverbound respawn) packet whose state byte is not one of the known values 0 (SearchingForSpawn), 1 (ReadyToSpawn) or 2 (ClientReadyToSpawn). The offending input is the raw state u8 from the packet — anything outside 0-2 means a protocol mismatch or a non-vanilla client.","triggerScenarios":"Respawn packet whose u8 state field is not 0, 1, or 2 — from corruption, misaligned reads, or a protocol version difference shifting the field.","commonSituations":"Client/server protocol mismatch after a Bedrock update, network corruption, or crafted packets.","solutions":["Drop the invalid respawn packet","Handle only the three defined states and reject others","Log the raw state byte at debug level"],"exampleFix":"// before\nmatch u8::read(reader)? {\n    0 => Ok(Self::SearchingForSpawn),\n    1 => Ok(Self::ReadyToSpawn),\n    2 => Ok(Self::ClientReadyToSpawn),\n    state => Err(...),\n}\n// after (if protocol adds state 3)\nmatch u8::read(reader)? {\n    0 => Ok(Self::SearchingForSpawn),\n    1 => Ok(Self::ReadyToSpawn),\n    2 => Ok(Self::ClientReadyToSpawn),\n    3 => Ok(Self::NewState),\n    state => Err(...),\n}","handlingStrategy":"type-guard","validationCode":"fn is_valid_respawn_state(b: u8) -> bool { b <= 2 }\n// check before decode if you own the byte: if !is_valid_respawn_state(raw) { reject }","typeGuard":"fn parse_respawn_state(b: u8) -> Option<RespawnState> {\n    match b { 0 => Some(RespawnState::SearchingForSpawn), 1 => Some(RespawnState::ReadyToSpawn), 2 => Some(RespawnState::ClientReadyToSpawn), _ => None }\n}","tryCatchPattern":"match RespawnState::read(reader) {\n    Ok(s) => handle_respawn(s),\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidData => { log::warn!(\"bad respawn state\"); disconnect(peer); }\n    Err(e) => Err(e.into()),\n}","preventionTips":["Update protocol crates together on both sides of a Bedrock version bump","Keep enum decoders exhaustive and tested over all u8 values","Use try_from-based enum conversion so bad values fail loudly and early"],"tags":["bedrock","protocol","packet-decoding","enum"],"backgroundTag":"invalid-enum-value","analyzedSha":"8d4639e25a57c15e47448ec327c780d41bbf2356","analyzedAt":"2026-09-09T15:32:22.916Z","contentChangedAt":"2026-09-09T15:32:22.916Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}