{"thread":{"id":"66751","subject":"[PATCH v1] hash: handle invalid algorithms when formatting object IDs","startedAt":"2026-11-03T04:20:42Z","lastAt":"2026-11-03T04:20:42Z","messageCount":1,"participants":["shrimech"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"557262","messageId":"20261103042042.39999-1-eddinen77@gmail.com","threadId":"66751","inReplyTo":null,"subject":"[PATCH v1] hash: handle invalid algorithms when formatting object IDs","fromName":"shrimech","fromEmail":"eddinen77@gmail.com","sentAt":"2026-11-03T04:20:42Z","receivedAt":"2026-11-03T04:20:42Z","isPatch":true,"sender":{"key":"eddinen77@gmail.com","avatar":null},"body":"ObjectID::algo is publicly mutable, so an ObjectID may contain an algorithm\nidentifier that is not recognized by HashAlgorithm. Display previously\nunwrapped as_slice(), which returns an error for such identifiers, causing\nformatting to panic.\n\nFormat the full hash storage for invalid identifiers and append an\ninvalid-hash-algo marker containing the unsupported identifier. Add a\nregression test covering this case while preserving the existing output for\nvalid algorithms.\n\nSigned-off-by: shrimech <eddinen77@gmail.com>\n---\n\nNotes:\n    Base Ref: v2.56.0\n    Web-Diff: https://github.com/larsxschneider/git/commit/c95530cf38\n    Checkout: git fetch https://github.com/larsxschneider/git fix/objectid-display-invalid-algo-v1 && git checkout c95530cf38\n\n src/hash.rs | 27 +++++++++++++++++++++++----\n 1 file changed, 23 insertions(+), 4 deletions(-)\n\ndiff --git a/src/hash.rs b/src/hash.rs\nindex e1f2d31fc3..87242d58b1 100644\n--- a/src/hash.rs\n+++ b/src/hash.rs\n@@ -78,13 +78,19 @@ impl ObjectID {\n }\n \n impl Display for ObjectID {\n-    /// Format this object ID as a hex object ID.\n+    /// Format this object ID as a hex object ID, or mark it if its algorithm is invalid.\n     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n-        let hash = self.as_slice().unwrap();\n+        let hash = match self.as_slice() {\n+            Ok(hash) => hash,\n+            Err(_) => &self.hash,\n+        };\n         for x in hash {\n             write!(f, \"{:02x}\", x)?;\n         }\n-        Ok(())\n+        match self.algo() {\n+            Ok(_) => Ok(()),\n+            Err(e) => write!(f, \":invalid-hash-algo-{}\", e.0),\n+        }\n     }\n }\n \n@@ -366,7 +372,7 @@ pub mod c {\n \n #[cfg(test)]\n mod tests {\n-    use super::{CryptoDigest, HashAlgorithm, ObjectID};\n+    use super::{CryptoDigest, HashAlgorithm, ObjectID, GIT_MAX_RAWSZ};\n     use std::io::Write;\n \n     fn all_algos() -> &'static [HashAlgorithm] {\n@@ -439,6 +445,19 @@ mod tests {\n         }\n     }\n \n+    #[test]\n+    fn invalid_object_ids_format_without_panicking() {\n+        let oid = ObjectID {\n+            hash: [0xab; GIT_MAX_RAWSZ],\n+            algo: 0,\n+        };\n+\n+        assert_eq!(\n+            format!(\"{}\", oid),\n+            format!(\"{}:invalid-hash-algo-0\", \"ab\".repeat(GIT_MAX_RAWSZ))\n+        );\n+    }\n+\n     #[test]\n     fn hasher_works_correctly() {\n         for algo in all_algos() {\n\nbase-commit: a018953688f1b10bddf91bff8747068f5f4746a4\n-- \n2.47.3\n\n\n"}]}