{"record":{"id":"ffa0fa97d43afe5d","repo":"gitbutlerapp/gitbutler","slug":"write-to-memory-succeeds","errorCode":null,"errorMessage":"write to memory succeeds","messagePattern":"write to memory succeeds","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-oplog/src/reflog.rs","lineNumber":152,"sourceCode":"            new_oid: new_oid_string.as_str().into(),\n            signature,\n            message: message.as_str().into(),\n        };\n\n        previous_oid = *commit_id;\n\n        log.push_str(&serialize_line(reflog_line));\n        log.push('\\n');\n    }\n\n    log\n}\n\nfn serialize_line(line: gix::refs::file::log::LineRef<'_>) -> String {\n    let mut sig = Vec::new();\n    line.signature\n        .write_to(&mut sig)\n        .expect(\"write to memory succeeds\");\n\n    format!(\n        \"{} {} {}\\t{}\",\n        line.previous_oid,\n        line.new_oid,\n        std::str::from_utf8(&sig).expect(\"no illformed UTF8\"),\n        line.message\n    )\n}\n\n#[cfg(test)]\nmod set_target_ref {\n    use std::str::FromStr;\n\n    use but_testsupport::{CommandExt, git_at_dir};\n    use gix::refs::file::log::LineRef;\n    use pretty_assertions::assert_eq;\n    use tempfile::tempdir;","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-oplog/src/reflog.rs#L134-L170","documentation":"serialize_line serializes a git reflog entry to a string. It writes the entry's signature (committer name/email/timestamp) into an in-memory Vec<u8> via gix's write_to, and panics with 'write to memory succeeds' if that write fails. The panic message encodes the developer's assumption: writing to a growable in-memory buffer cannot fail.","triggerScenarios":"Practically never triggered: Vec::write_all to memory does not error in real conditions; it would only fire if the signature writer itself returned an unexpected error from gix internals.","commonSituations":"Only seen in pathological cases such as a gix internal writer bug, memory exhaustion during buffer growth, or a corrupted signature object that makes gix's serialization fail mid-write.","solutions":["Ignore unless reproducible: this panic indicates a bug in the gix signature writer, not in your data handling.","Reproduce with the specific reflog line's signature and file a bug against gitoxide (gix).","Replace the expect with error propagation: make serialize_line return io::Result<String> and bubble the error to build_reflog_content.","Check memory pressure if it happens on huge reflogs; preallocate the buffer or stream the output to a file."],"exampleFix":"// before\nlet mut sig = Vec::new();\nline.signature.write_to(&mut sig).expect(\"write to memory succeeds\");\n// after\nlet mut sig = Vec::new();\nline.signature\n    .write_to(&mut sig)\n    .map_err(|e| anyhow::anyhow!(\"failed to serialize reflog signature: {e}\"))?;","handlingStrategy":"try-catch","validationCode":"// Not practically pre-checkable; optionally verify signature is well-formed first\nlet mut probe = Vec::with_capacity(128);\n// treat a write error as a real error instead of panicking\nline.signature.write_to(&mut probe)?;","typeGuard":null,"tryCatchPattern":"// Convert the panic-prone expect into error propagation\nfn serialize_line(line: gix::refs::file::log::LineRef<'_>) -> anyhow::Result<String> {\n    let mut sig = Vec::new();\n    line.signature.write_to(&mut sig)?;\n    Ok(format!(\"{} {} {}\\t{}\", line.previous_oid, line.new_oid,\n        std::str::from_utf8(&sig)?, line.message))\n}","preventionTips":["Avoid expect() on fallible writes in library code; propagate errors instead","Fuzz reflog parsing with malformed inputs to catch panics early","Keep gix dependencies updated to pick up writer bug fixes"],"tags":["rust","git","reflog","panic"],"backgroundTag":"internal-invariant-violation","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}