{"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":"warning","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/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/gitbutler-oplog/src/reflog.rs#L140-L176","documentation":"After serializing a reflog line's gix signature into bytes, serialize_line() asserts the bytes are UTF-8 via std::str::from_utf8(&sig).expect(\"no illformed UTF8\"). Unlike its sibling expect one line up, this one is genuinely reachable: gix signatures preserve raw bytes (e.g. latin-1 author names), and reflog files written by git can legitimately contain such non-UTF-8 identities.","triggerScenarios":"Computing the oplog/reflog snapshot for a ref whose reflog lines contain non-UTF-8 bytes in the identity (name/email portion): repos authored on systems with legacy single-byte locales, or reflog files containing binary garbage.","commonSituations":"Windows machines configured with latin-1 user names, old repositories migrated forward, reflog files corrupted or hand-edited, or users whose git identity contains non-UTF-8 bytes. Surfaces whenever GitButler reads the reflog to build undo history.","solutions":["Find the offending ref: check the panic backtrace and scan .git/logs entries with `grep -Pxv '.*' .git/logs/refs/...` (or grep for bytes 0x80-0xFF)","Fix the identity (set user.name/user.email to UTF-8 values) and rewrite or clear the affected reflog (.git/logs/<ref>) so new entries are clean","Switch the code to String::from_utf8_lossy(&sig) so non-UTF-8 bytes are replaced rather than panicking (see exampleFix)"],"exampleFix":"// before\nstd::str::from_utf8(&sig).expect(\"no illformed UTF8\")\n\n// after\nString::from_utf8_lossy(&sig)","handlingStrategy":"fallback","validationCode":"// Scan a reflog for non-UTF-8 bytes before snapshotting it\nfn reflog_is_utf8(path: &std::path::Path) -> bool {\n    std::fs::read(path)\n        .map(|bytes| std::str::from_utf8(&bytes).is_ok())\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"// Lossy conversion keeps the snapshot alive on legacy encodings\nlet sig_str = String::from_utf8_lossy(&sig);","preventionTips":["Set git user.name/user.email to UTF-8 values on machines with legacy locales","Use String::from_utf8_lossy for git-authored metadata - git identities are byte strings by design","Audit .git/logs with a non-UTF-8 byte scan when importing old repositories"],"tags":["rust","utf-8","reflog","encoding","git-identity","oplog","panic"],"backgroundTag":"invalid-utf8-in-git-metadata","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}