{"record":{"id":"9f168c8ebf05b4d1","repo":"embassy-rs/embassy","slug":"datalength-64","errorCode":null,"errorMessage":"DataLength > 64","messagePattern":"DataLength > 64","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"embassy-stm32/src/can/fd/message_ram/enums.rs","lineNumber":23,"sourceCode":"\n#[derive(Clone, Copy, Debug, PartialEq)]\npub enum DataLength {\n    Classic(u8),\n    Fdcan(u8),\n}\nimpl DataLength {\n    /// Creates a DataLength type\n    ///\n    /// Uses the byte length and Type of frame as input\n    pub fn new(len: u8, ff: FrameFormat) -> DataLength {\n        match ff {\n            FrameFormat::Classic => match len {\n                0..=8 => DataLength::Classic(len),\n                _ => panic!(\"DataLength > 8\"),\n            },\n            FrameFormat::Fdcan => match len {\n                0..=64 => DataLength::Fdcan(len),\n                _ => panic!(\"DataLength > 64\"),\n            },\n        }\n    }\n    /// Specialised function to create classic frames\n    pub fn new_classic(len: u8) -> DataLength {\n        Self::new(len, FrameFormat::Classic)\n    }\n    /// Specialised function to create FDCAN frames\n    pub fn new_fdcan(len: u8) -> DataLength {\n        Self::new(len, FrameFormat::Fdcan)\n    }\n\n    /// returns the length in bytes\n    pub fn len(&self) -> u8 {\n        match self {\n            DataLength::Classic(l) | DataLength::Fdcan(l) => *l,\n        }\n    }","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/embassy-rs/embassy/blob/463a07b963419a1bfe61d5d597c44acb810afb8b/embassy-stm32/src/can/fd/message_ram/enums.rs#L5-L41","documentation":"`DataLength::new` panics when an FDCAN frame is given a payload length greater than 64 bytes. The CAN-FD protocol allows at most 64 data bytes, so lengths above 64 are rejected as invalid rather than truncated.","triggerScenarios":"Calling `DataLength::new(len, FrameFormat::Fdcan)` with `len > 64`; typically while constructing a transmit frame whose source buffer exceeds 64 bytes.","commonSituations":"Passing a whole application buffer instead of slicing it into CAN-sized chunks; confused protocol limits (thinking FD allows 128 bytes); chunking loop with wrong stride.","solutions":["Slice the payload into chunks of at most 64 bytes and send multiple frames.","Validate `len <= 64` before calling DataLength::new with FrameFormat::Fdcan.","Clamp with `len.min(64)` if truncation is acceptable."],"exampleFix":"// before\nlet dl = DataLength::new(buffer.len() as u8, FrameFormat::Fdcan);\n// after\nassert!(buffer.len() <= 64, \"FD frame payload exceeds 64 bytes\");\nlet dl = DataLength::new(buffer.len() as u8, FrameFormat::Fdcan);","handlingStrategy":"validation","validationCode":"fn valid_fd_len(len: u8) -> bool { len <= 64 }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Chunk payloads larger than 64 bytes into multiple FD frames.","Assert buffer lengths at the boundary where user data meets the CAN driver.","Remember CAN-FD max payload is 64 bytes, not more."],"tags":["embedded","can-fd","panic","payload-size"],"backgroundTag":"value-out-of-range","analyzedSha":"463a07b963419a1bfe61d5d597c44acb810afb8b","analyzedAt":"2026-09-10T13:38:26.660Z","contentChangedAt":"2026-09-10T13:38:26.660Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}