Skip to content

Commit bb6a63a

Browse files
committed
Merge branch 'mt/parallel-checkout-with-padded-oidcpy'
The parallel checkout codepath did not initialize object ID field used to talk to the worker processes in a futureproof way. * mt/parallel-checkout-with-padded-oidcpy: parallel-checkout: send the new object_id algo field to the workers
2 parents 26b25e0 + 3d20ed2 commit bb6a63a

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

hash.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,22 @@ static inline void oidcpy(struct object_id *dst, const struct object_id *src)
263263
dst->algo = src->algo;
264264
}
265265

266+
/* Like oidcpy() but zero-pads the unused bytes in dst's hash array. */
267+
static inline void oidcpy_with_padding(struct object_id *dst,
268+
struct object_id *src)
269+
{
270+
size_t hashsz;
271+
272+
if (!src->algo)
273+
hashsz = the_hash_algo->rawsz;
274+
else
275+
hashsz = hash_algos[src->algo].rawsz;
276+
277+
memcpy(dst->hash, src->hash, hashsz);
278+
memset(dst->hash + hashsz, 0, GIT_MAX_RAWSZ - hashsz);
279+
dst->algo = src->algo;
280+
}
281+
266282
static inline struct object_id *oiddup(const struct object_id *src)
267283
{
268284
struct object_id *dst = xmalloc(sizeof(struct object_id));

parallel-checkout.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ static void send_one_item(int fd, struct parallel_checkout_item *pc_item)
411411
len_data = sizeof(struct pc_item_fixed_portion) + name_len +
412412
working_tree_encoding_len;
413413

414-
data = xcalloc(1, len_data);
414+
data = xmalloc(len_data);
415415

416416
fixed_portion = (struct pc_item_fixed_portion *)data;
417417
fixed_portion->id = pc_item->id;
@@ -421,13 +421,12 @@ static void send_one_item(int fd, struct parallel_checkout_item *pc_item)
421421
fixed_portion->name_len = name_len;
422422
fixed_portion->working_tree_encoding_len = working_tree_encoding_len;
423423
/*
424-
* We use hashcpy() instead of oidcpy() because the hash[] positions
425-
* after `the_hash_algo->rawsz` might not be initialized. And Valgrind
426-
* would complain about passing uninitialized bytes to a syscall
427-
* (write(2)). There is no real harm in this case, but the warning could
428-
* hinder the detection of actual errors.
424+
* We pad the unused bytes in the hash array because, otherwise,
425+
* Valgrind would complain about passing uninitialized bytes to a
426+
* write() syscall. The warning doesn't represent any real risk here,
427+
* but it could hinder the detection of actual errors.
429428
*/
430-
hashcpy(fixed_portion->oid.hash, pc_item->ce->oid.hash);
429+
oidcpy_with_padding(&fixed_portion->oid, &pc_item->ce->oid);
431430

432431
variant = data + sizeof(*fixed_portion);
433432
if (working_tree_encoding_len) {

0 commit comments

Comments
 (0)