{"record":{"id":"6ee542eab5119c2d","repo":"Pumpkin-MC/Pumpkin","slug":"bitset-too-large","errorCode":null,"errorMessage":"Bitset too large","messagePattern":"Bitset too large","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin-protocol/src/codec/bitset.rs","lineNumber":46,"sourceCode":"impl<const N: usize> Default for Bitset<N> {\n    fn default() -> Self {\n        assert!(N <= 80,);\n        Self { bits: 0 }\n    }\n}\n\nimpl<const N: usize> PacketRead for Bitset<N> {\n    fn read<R: Read>(reader: &mut R) -> Result<Self, Error> {\n        let mut bitset = Self::default();\n\n        for i in 0..N.div_ceil(7) {\n            let byte = u8::read(reader)?;\n            bitset.bits |= (u128::from(byte) & 0x7F) << (i * 7);\n            if byte & 0x80 == 0 {\n                return Ok(bitset);\n            }\n        }\n        Err(Error::new(ErrorKind::InvalidData, \"Bitset too large\"))\n    }\n}\n","sourceCodeStart":28,"sourceCodeEnd":49,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-protocol/src/codec/bitset.rs#L28-L49","documentation":"Thrown when decoding a VarInt-encoded bitset that exceeds the maximum supported size of the u128 backing storage (more than 18 7-bit groups / 128 bits of data). The reader stops after the fixed loop bound and returns InvalidData rather than silently truncating.","triggerScenarios":"Reading a bitset whose VarInt payload has more continuation groups than the read loop allows (a bitset larger than 128 bits, or a corrupted/missing terminator byte so the loop runs to exhaustion).","commonSituations":"Server/client disagreement on bitset width for a field (e.g. abilities or recipe flags); malicious or corrupt packets on the wire; a protocol version that widened the bitset.","solutions":["Confirm the client protocol version matches the pumpkin-protocol definitions; update if the field's bitset width changed.","Validate the bitset's length prefix before decoding; reject oversized inputs at the packet boundary.","Check for packet corruption — a missing terminator byte (0x80 flag never cleared) will also hit this limit.","If a wider bitset is genuinely required, widen the internal storage (e.g. to a larger integer or array) in the codec."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Reject bitsets wider than u128 before decoding\nif declared_len > 18 { return Err(Error::new(ErrorKind::InvalidData, \"bitset too large\")); }","typeGuard":null,"tryCatchPattern":"match Bitset::read(reader) {\n    Ok(b) => Ok(b),\n    Err(e) if e.kind() == ErrorKind::InvalidData => {\n        log::warn!(\"oversized bitset; likely corrupt stream\");\n        Err(DecodeError::Desync)\n    }\n    Err(e) => Err(e.into()),\n}","preventionTips":["Enforce the field's documented bitset width at the packet boundary.","Always consume exactly the encoded length; never guess.","Disconnect on first decode failure to avoid cascading desync."],"tags":["protocol","deserialization","overflow","bitset"],"backgroundTag":"value-out-of-range","analyzedSha":"8d4639e25a57c15e47448ec327c780d41bbf2356","analyzedAt":"2026-09-09T15:32:22.916Z","contentChangedAt":"2026-09-09T15:32:22.916Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}