Skip to content

Commit 71b7672

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 72871b1 commit 71b7672

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

builtin/pack-objects.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ static void write_pack_file(void)
10301030
write_order = compute_write_order();
10311031

10321032
do {
1033-
struct object_id oid;
1033+
unsigned char hash[GIT_MAX_RAWSZ];
10341034
char *pack_tmp_name = NULL;
10351035

10361036
if (pack_to_stdout)
@@ -1059,13 +1059,13 @@ static void write_pack_file(void)
10591059
* If so, rewrite it like in fast-import
10601060
*/
10611061
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);
10631063
} 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);
10651065
} 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);
10691069
close(fd);
10701070
if (write_bitmap_index) {
10711071
if (write_bitmap_index != WRITE_BITMAP_QUIET)
@@ -1100,17 +1100,17 @@ static void write_pack_file(void)
11001100
strbuf_addf(&tmpname, "%s-", base_name);
11011101

11021102
if (write_bitmap_index) {
1103-
bitmap_writer_set_checksum(oid.hash);
1103+
bitmap_writer_set_checksum(hash);
11041104
bitmap_writer_build_type_index(
11051105
&to_pack, written_list, nr_written);
11061106
}
11071107

11081108
finish_tmp_packfile(&tmpname, pack_tmp_name,
11091109
written_list, nr_written,
1110-
&pack_idx_opts, oid.hash);
1110+
&pack_idx_opts, hash);
11111111

11121112
if (write_bitmap_index) {
1113-
strbuf_addf(&tmpname, "%s.bitmap", oid_to_hex(&oid));
1113+
strbuf_addf(&tmpname, "%s.bitmap", hash_to_hex(hash));
11141114

11151115
stop_progress(&progress_state);
11161116

@@ -1124,7 +1124,7 @@ static void write_pack_file(void)
11241124

11251125
strbuf_release(&tmpname);
11261126
free(pack_tmp_name);
1127-
puts(oid_to_hex(&oid));
1127+
puts(hash_to_hex(hash));
11281128
}
11291129

11301130
/* mark written objects as written to previous pack */

0 commit comments

Comments
 (0)