{"record":{"id":"702f16f1cfbe92e5","repo":"gitbutlerapp/gitbutler","slug":"no-illformed-utf8","errorCode":null,"errorMessage":"no illformed UTF8","messagePattern":"no illformed UTF8","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gitbutler-oplog/src/reflog.rs","lineNumber":158,"sourceCode":"\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;\n\n    use super::{\n        GITBUTLER_COMMIT_AUTHOR_EMAIL, GITBUTLER_COMMIT_AUTHOR_NAME, ReflogCommits,\n        set_reference_to_oplog,\n    };\n","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/gitbutler-oplog/src/reflog.rs#L140-L176","documentation":"After writing the signature into memory, serialize_line converts the bytes to &str with std::str::from_utf8 and panics on invalid UTF-8. Git signatures are specified to be UTF-8 (name/email and a timestamp), so ill-formed bytes indicate corrupted reflog data.","triggerScenarios":"Called by build_reflog_content for each reflog line; fires only when the serialized signature bytes are not valid UTF-8, i.e. the reflog file contains non-UTF-8 committer data.","commonSituations":"Hand-edited or corrupted .git/logs files; reflogs copied from a filesystem with different encoding; repos created by non-conforming git tooling that wrote raw bytes into the committer name.","solutions":["Inspect the reflog file with a hex editor to find the non-UTF-8 bytes in the committer name and fix or remove the line.","Sanitize the bytes before conversion (e.g. String::from_utf8_lossy) if lossy output is acceptable for display.","Propagate the error instead of panicking: return anyhow::Result<String> and report the offending reflog line to the user.","If the repo came from a third-party tool, re-clone or rewrite the reflog to normalize the signature."],"exampleFix":"// before\nstd::str::from_utf8(&sig).expect(\"no illformed UTF8\"),\n// after\nString::from_utf8_lossy(&sig),","handlingStrategy":"validation","validationCode":"// Validate the reflog line bytes decode as UTF-8 before serializing\nif std::str::from_utf8(&sig).is_err() {\n    eprintln!(\"reflog line has non-UTF-8 signature, skipping/lossy-decoding\");\n}","typeGuard":null,"tryCatchPattern":"// Use lossy conversion or propagate instead of panicking\nlet sig_str = String::from_utf8_lossy(&sig);\n// or: std::str::from_utf8(&sig).map_err(|e| anyhow!(\"reflog signature not UTF-8: {e}\"))?","preventionTips":["Never hand-edit .git/logs files with a non-UTF-8-safe editor","Validate repo integrity (git fsck) after copying repos across systems","Prefer from_utf8_lossy for display paths and strict conversion only for storage"],"tags":["rust","git","reflog","utf8","panic"],"backgroundTag":"invalid-argument-format","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"}