{"record":{"id":"989d88f371e764a9","repo":"atuinsh/atuin","slug":"trailing-bytes-in-encoded-dotfiles-var-record-mal","errorCode":null,"errorMessage":"trailing bytes in encoded dotfiles var record. malformed","messagePattern":"trailing bytes in encoded dotfiles var record\\. malformed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/atuin-dotfiles/src/store/var.rs","lineNumber":78,"sourceCode":"                match record_type {\n                    // create\n                    0 => {\n                        let env = Var::deserialize(&mut bytes)?;\n                        Ok(Self::Create(env))\n                    }\n\n                    // delete\n                    1 => {\n                        let nfields = decode::read_array_len(&mut bytes).map_err(error_report)?;\n                        ensure!(nfields == 1, \"too many entries in v0 dotfiles var delete record\");\n\n                        let bytes = bytes.remaining_slice();\n\n                        let (key, bytes) =\n                            decode::read_str_from_slice(bytes).map_err(error_report)?;\n\n                        if !bytes.is_empty() {\n                            bail!(\"trailing bytes in encoded dotfiles var record. malformed\");\n                        }\n\n                        Ok(Self::Delete(key.to_owned()))\n                    }\n\n                    n => {\n                        bail!(\"unknown Dotfiles var record type {n}\");\n                    }\n                }\n            }\n            other => {\n                bail!(\"unknown var record version {other:?}\");\n            }\n        }\n    }\n}\n\n#[derive(Debug, Clone)]","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/atuinsh/atuin/blob/900007c48045867e7f44b0f9bc55ad9dbe99ee0d/crates/atuin-dotfiles/src/store/var.rs#L60-L96","documentation":"The dotfiles var record decoder reads a length-prefixed key string and then requires the payload to be fully consumed. If bytes remain after reading the key, the payload does not match the expected Delete-record layout, so it bails with this error. It protects against decoding malformed or mis-aligned binary payloads.","triggerScenarios":"Deserializing a var record whose payload contains trailing bytes after the key string — corrupted payload, truncated/mangled encode, or a payload for a different record type fed to the Delete arm.","commonSituations":"Hand-edited or corrupted record payloads in the SQLite store; decode logic drift between encoder and decoder versions; accidentally passing KV or alias payloads to the var decoder.","solutions":["Delete/re-sync the affected var record so it is re-encoded correctly","Verify encoder and decoder use the same layout (version byte, tag, length-prefixed strings)","Check that the record tag matches (var records decoded with the var decoder, not kv/alias)"],"exampleFix":"// before: trust the payload blindly\nlet (key, bytes) = decode::read_str_from_slice(bytes)?;\n// after: reject clearly mis-typed payloads early\nlet (tag, rest) = bytes.split_first().ok_or_else(|| eyre!(\"empty payload\"))?;\nif *tag != VAR_DELETE_TAG { return Err(eyre!(\"wrong record tag\")); }\nlet (key, bytes) = decode::read_str_from_slice(rest)?;","handlingStrategy":"validation","validationCode":"// Validate payload shape before decode: version byte + type byte + exactly one length-prefixed string\n// fn plausible_var_delete(payload: &[u8]) -> bool {\n//     decode::read_str_from_slice(&payload[2..]).map(|(_, rest)| rest.is_empty()).unwrap_or(false)\n// }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never hand-edit record payloads in the SQLite store","Keep encoder and decoder in the same crate version","Re-sync records that fail decode instead of retrying the same bytes"],"tags":["deserialization","record-store","malformed-data"],"backgroundTag":"schema-validation-failed","analyzedSha":"900007c48045867e7f44b0f9bc55ad9dbe99ee0d","analyzedAt":"2026-09-19T12:52:51.491Z","contentChangedAt":"2026-09-19T12:52:51.491Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}