{"record":{"id":"7db96cffc19ff87b","repo":"Pumpkin-MC/Pumpkin","slug":"raw-token-length-raw-token-len-exceeds-limit-ma","errorCode":null,"errorMessage":"Raw token length {raw_token_len} exceeds limit {MAX_PACKET_DATA_SIZE}","messagePattern":"Raw token length (.+?) exceeds limit (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/pumpkin-protocol/src/bedrock/server/login.rs","lineNumber":43,"sourceCode":"                format!(\n                    \"Connection request length {connection_request_len} exceeds limit {MAX_PACKET_DATA_SIZE}\"\n                ),\n            ));\n        }\n\n        let jwt_len = u32::read(reader)? as usize;\n        if jwt_len > MAX_PACKET_DATA_SIZE {\n            return Err(Error::new(\n                ErrorKind::InvalidData,\n                format!(\"JWT length {jwt_len} exceeds limit {MAX_PACKET_DATA_SIZE}\"),\n            ));\n        }\n        let mut jwt = vec![0; jwt_len];\n        reader.read_exact(&mut jwt)?;\n\n        let raw_token_len = u32::read(reader)? as usize;\n        if raw_token_len > MAX_PACKET_DATA_SIZE {\n            return Err(Error::new(\n                ErrorKind::InvalidData,\n                format!(\"Raw token length {raw_token_len} exceeds limit {MAX_PACKET_DATA_SIZE}\"),\n            ));\n        }\n        let mut raw_token = vec![0; raw_token_len];\n        reader.read_exact(&mut raw_token)?;\n\n        Ok(Self {\n            protocol_version,\n            jwt,\n            raw_token,\n        })\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use std::io::Cursor;","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/Pumpkin-MC/Pumpkin/blob/8d4639e25a57c15e47448ec327c780d41bbf2356/crates/pumpkin-protocol/src/bedrock/server/login.rs#L25-L61","documentation":"Thrown when the raw (identity) token length field in the Bedrock Login packet exceeds MAX_PACKET_DATA_SIZE. Like the other login guards, it validates the declared size before allocating, protecting the server from hostile oversized allocations. The packet fails with an InvalidData error.","triggerScenarios":"A Login packet whose raw_token length field exceeds MAX_PACKET_DATA_SIZE; caused by crafted packets, fuzzing, or earlier field misalignment (e.g. wrong JWT length read) shifting the stream so a wrong value is interpreted as the token length.","commonSituations":"DoS probes on the login route, corrupted connections through proxies, or client/server protocol version mismatch.","solutions":["Check protocol version parity between client and server","Decode the packet offline to confirm the intended token size","Raise MAX_PACKET_DATA_SIZE only if legitimate tokens genuinely exceed it","Fix upstream length parsing (e.g. 496's JWT length) if the desync originates earlier"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn raw_token_len_ok(len: usize) -> bool { len <= MAX_PACKET_DATA_SIZE }","typeGuard":"fn checked(len: u32) -> Option<usize> { usize::try_from(len).ok().filter(|&l| l <= MAX_PACKET_DATA_SIZE) }","tryCatchPattern":"match SLogin::read(reader) {\n    Err(e) if e.to_string().contains(\"Raw token length\") => { kick(peer, \"oversized token\"); Ok(()) }\n    Err(e) => Err(e),\n    Ok(l) => Ok(l),\n}","preventionTips":["Validate all three login length fields (connection request, JWT, raw token) consistently","Confirm earlier fields parsed correctly — a bad JWT length desyncs this one","Rate-limit malformed login attempts per peer"],"tags":["protocol","bedrock","login","token","size-limit"],"backgroundTag":"payload-too-large","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"}