builtin/pack-objects: avoid using struct object_id for pack hash
We use struct object_id for the names of objects. It isn't intended to be used for other hash values that don't name objects such as the pack hash. Because struct object_id will soon need to have its algorithm member set, using it in this code path would mean that we didn't set that member, only the hash member, which would result in a crash. For both of these reasons, switch to using an unsigned char array of size GIT_MAX_RAWSZ. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Apr 26, 2021 at 01:02 UTC
71b7672b674bc9a44fb41428804be428c2981046
1 file changed
+10
-10
builtin/pack-objects.c
+10
-10
@@ -1030,7 +1030,7 @@ static void write_pack_file(void)
1030
write_order = compute_write_order();
1031
1032
do {
1033
- struct object_id oid;
1033
+ unsigned char hash[GIT_MAX_RAWSZ];
1034
char *pack_tmp_name = NULL;
1035
1036
if (pack_to_stdout)
@@ -1059,13 +1059,13 @@ static void write_pack_file(void)
1059
* If so, rewrite it like in fast-import
1060
*/
1061
if (pack_to_stdout) {
1062
- finalize_hashfile(f, oid.hash, CSUM_HASH_IN_STREAM | CSUM_CLOSE);
1062
+ finalize_hashfile(f, hash, CSUM_HASH_IN_STREAM | CSUM_CLOSE);
1063
} else if (nr_written == nr_remaining) {
1064
- finalize_hashfile(f, oid.hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
1064
+ finalize_hashfile(f, hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
1065
} else {
1066
- int fd = finalize_hashfile(f, oid.hash, 0);
1067
- fixup_pack_header_footer(fd, oid.hash, pack_tmp_name,
1068
- nr_written, oid.hash, offset);
1066
+ int fd = finalize_hashfile(f, hash, 0);
1067
+ fixup_pack_header_footer(fd, hash, pack_tmp_name,
1068
+ nr_written, hash, offset);
1069
close(fd);
1070
if (write_bitmap_index) {
1071
if (write_bitmap_index != WRITE_BITMAP_QUIET)
@@ -1100,17 +1100,17 @@ static void write_pack_file(void)
1100
strbuf_addf(&tmpname, "%s-", base_name);
1101
1102
if (write_bitmap_index) {
1103
- bitmap_writer_set_checksum(oid.hash);
1103
+ bitmap_writer_set_checksum(hash);
1104
bitmap_writer_build_type_index(
1105
&to_pack, written_list, nr_written);
1106
}
1107
1108
finish_tmp_packfile(&tmpname, pack_tmp_name,
1109
written_list, nr_written,
1110
- &pack_idx_opts, oid.hash);
1110
+ &pack_idx_opts, hash);
1111
1112
if (write_bitmap_index) {
1113
- strbuf_addf(&tmpname, "%s.bitmap", oid_to_hex(&oid));
1113
+ strbuf_addf(&tmpname, "%s.bitmap", hash_to_hex(hash));
1114
1115
stop_progress(&progress_state);
1116
@@ -1124,7 +1124,7 @@ static void write_pack_file(void)
1124
1125
strbuf_release(&tmpname);
1126
free(pack_tmp_name);
1127
- puts(oid_to_hex(&oid));
1127
+ puts(hash_to_hex(hash));
1128
}
1129
1130
/* mark written objects as written to previous pack */