Skip to contentSkip to conversation

index-pack, unpack-objects: restore missing ->init_fn

PATCH In review Jensen Huang 3 participants 5 messages Mar 18, 2025 – Mar 21, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 index-pack, unpack-objects: restore missing ->init_fn

Commit 0578f1e66a ("global: adapt callers to use generic hash context helpers") accidentally removed ->init_fn, which is required for OpenSSL 3+ SHA1.

This fixes the following error on fetch:
fatal: fetch-pack: invalid index-pack output

---
 builtin/index-pack.c     | 1 +
 builtin/unpack-objects.c | 1 +
 2 files changed, 2 insertions(+)
builtin/index-pack.c +1 -0
index 52cc97d52c..50573ba049 100644
@@ -1286,6 +1286,7 @@ static void parse_pack_objects(unsigned char *hash)
 
 	/* Check pack integrity */
 	flush();
+	the_hash_algo->init_fn(&tmp_ctx);
 	git_hash_clone(&tmp_ctx, &input_ctx);
 	git_hash_final(hash, &tmp_ctx);
 	if (!hasheq(fill(the_hash_algo->rawsz), hash, the_repository->hash_algo))
builtin/unpack-objects.c +1 -0
index 8383bcf404..c5a6dca856 100644
@@ -668,6 +668,7 @@ int cmd_unpack_objects(int argc,
 	the_hash_algo->init_fn(&ctx);
 	unpack_all();
 	git_hash_update(&ctx, buffer, offset);
+	the_hash_algo->init_fn(&tmp_ctx);
 	git_hash_clone(&tmp_ctx, &ctx);
 	git_hash_final_oid(&oid, &tmp_ctx);
 	if (strict) {
Signature · 1 line
2.49.0-1
#1 lore raw
Quoted 5 lines · Jensen Huang

Commit 0578f1e66a ("global: adapt callers to use generic hash context helpers") accidentally removed ->init_fn, which is required for OpenSSL 3+ SHA1.

This fixes the following error on fetch:
fatal: fetch-pack: invalid index-pack output

The change makes sense indeed. I do wonder though: can we maybe improve git_hash_clone() so that it is not required to initialize the context beforehand?

Thanks!

Patrick

#2 lore raw
Quoted 11 lines · Patrick Steinhardt
Quoted 5 lines · Jensen Huang

Commit 0578f1e66a ("global: adapt callers to use generic hash context helpers") accidentally removed ->init_fn, which is required for OpenSSL 3+ SHA1.

This fixes the following error on fetch:
fatal: fetch-pack: invalid index-pack output

The change makes sense indeed. I do wonder though: can we maybe improve git_hash_clone() so that it is not required to initialize the context beforehand?

Thanks for the review!
The idea of improving git_hash_clone() so that it doesn't require explicit init_fn() calls sounds interesting. However, based on my current understanding of the code, I'm not sure how to implement this properly while ensuring it works correctly for all hash implementations.
If you have any suggestions or guidance on how this could be approached, I'd appreciate the input!

BR,
Jensen

#3 lore raw
Quoted 13 lines · gtXfined H.
Quoted 11 lines · Patrick Steinhardt
Quoted 5 lines · Jensen Huang

Commit 0578f1e66a ("global: adapt callers to use generic hash context helpers") accidentally removed ->init_fn, which is required for OpenSSL 3+ SHA1.

This fixes the following error on fetch:
fatal: fetch-pack: invalid index-pack output

The change makes sense indeed. I do wonder though: can we maybe improve git_hash_clone() so that it is not required to initialize the context beforehand?

Quoted 8 lines

Thanks for the review!
The idea of improving git_hash_clone() so that it doesn't require explicit init_fn() calls sounds interesting. However, based on my current understanding of the code, I'm not sure how to implement this properly while ensuring it works correctly for all hash implementations.
If you have any suggestions or guidance on how this could be approached, I'd appreciate the input!

Fair enough. I'm also fine with the patch as-is as it addresses the issue true to the original spirit. Improving git_hash_clone() would be an extra step that doesn't need to be part of this series, nor does it have to be you who implements it.

Thanks!

Patrick

#4 lore raw
Quoted 4 lines · Patrick Steinhardt

Fair enough. I'm also fine with the patch as-is as it addresses the issue true to the original spirit. Improving git_hash_clone() would be an extra step that doesn't need to be part of this series, nor does it have to be you who implements it.

Sounds sensible.