{"record":{"id":"df27f623d7b57ee5","repo":"Pumpkin-MC/Pumpkin","slug":"invalid-ability-value-type-val-type","errorCode":null,"errorMessage":"Invalid ability value type: {val_type}","messagePattern":"Invalid ability value type: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin-protocol/src/bedrock/server/request_ability.rs","lineNumber":19,"sourceCode":"use crate::{codec::var_int::VarInt, serial::PacketRead};\nuse pumpkin_macros::packet;\nuse std::io::{Error, Read};\n\n#[derive(Clone, Debug)]\npub enum AbilityValue {\n    Bool(bool),\n    Float(f32),\n}\n\nimpl PacketRead for AbilityValue {\n    fn read<R: Read>(buf: &mut R) -> Result<Self, Error> {\n        let val_type = u8::read(buf)?;\n        let bool_val = bool::read(buf)?;\n        let float_val = f32::read(buf)?;\n        match val_type {\n            1 => Ok(Self::Bool(bool_val)),\n            2 => Ok(Self::Float(float_val)),\n            _ => Err(Error::new(\n                std::io::ErrorKind::InvalidData,\n                format!(\"Invalid ability value type: {val_type}\"),\n            )),\n        }\n    }\n}\n\n#[derive(PacketRead)]\n#[packet(184)]\npub struct SRequestAbility {\n    pub ability: VarInt,\n    pub value: AbilityValue,\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-protocol/src/bedrock/server/request_ability.rs#L1-L37","documentation":"Thrown while decoding an ability value in the Bedrock RequestAbility packet when the ability value's type byte is neither 1 (Bool) nor 2 (Float). Only these two value types are defined by the protocol, so any other byte means the packet is malformed.","triggerScenarios":"RequestAbility packet containing a Value with val_type not in {1, 2}, e.g. a corrupted byte, wrong offset from a protocol mismatch, or a hand-crafted packet.","commonSituations":"Version mismatch between client and server protocol implementations, packet corruption, or exploit tooling sending arbitrary bytes.","solutions":["Verify client protocol version matches the server's supported Bedrock version","Inspect the raw packet bytes around the ability value field for offset errors","If extending the protocol, add the new val_type to the match arms","Reject the packet and disconnect the sender"],"exampleFix":"// before\nmatch val_type {\n    1 => Ok(Self::Bool(bool_val)),\n    2 => Ok(Self::Float(float_val)),\n    _ => Err(Error::new(std::io::ErrorKind::InvalidData, format!(\"Invalid ability value type: {val_type}\"))),\n}\n// after (if a new type 3 is introduced upstream)\nmatch val_type {\n    1 => Ok(Self::Bool(bool_val)),\n    2 => Ok(Self::Float(float_val)),\n    3 => Ok(Self::NewKind(...)),\n    _ => Err(Error::new(std::io::ErrorKind::InvalidData, format!(\"Invalid ability value type: {val_type}\"))),\n}","handlingStrategy":"try-catch","validationCode":"// before calling: if you hold raw bytes, check the type byte is 1 or 2\nfn is_valid_ability_type(b: u8) -> bool { b == 1 || b == 2 }","typeGuard":"fn as_ability_value(v: Result<AbilityValue, std::io::Error>) -> Option<AbilityValue> { v.ok() }","tryCatchPattern":"match RequestAbilityValue::read(buf) {\n    Ok(v) => apply(v),\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidData => { log::warn!(\"bad ability type: {e}\"); disconnect(peer); }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Pin client versions to protocols the server supports","Keep the enum decoder and official protocol docs in sync when updating","Add exhaustive tests over all byte values 0..=255 for the type field"],"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-16T04:17:20.429Z"}