Commit

251e7af9924f9d3132a7b2f1f0f9563c829bc419

hash: initialize context before cloning

Our C-based clone helper requires that the context be initialized, but
we neglect to do that in our Clone implementation for CryptoHasher.
This does not matter when using our default block SHA-256
implementation, but it does cause a crash when using OpenSSL as the
backend.  Fix this by properly initializing the context before cloning
into it.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson <sandals@crustytoothpaste.net> · 2026-07-19 01:08 UTC · committed by Junio C Hamano

Browse files
1 file changed, +4 −1
modified src/hash.rs
@@ -181,7 +181,10 @@ impl CryptoDigest for CryptoHasher {
181 181 impl Clone for CryptoHasher {
182 182 fn clone(&self) -> Self {
183 183 let ctx = unsafe { c::git_hash_alloc() };
184 - unsafe { c::git_hash_clone(ctx, self.ctx) };
184 + unsafe {
185 + c::git_hash_init(ctx, self.algo.hash_algo_ptr());
186 + c::git_hash_clone(ctx, self.ctx)
187 + };
185 188 Self {
186 189 algo: self.algo,
187 190 ctx,