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
This commit is contained in:
Junio C Hamano 2021-06-10 12:04:22 +09:00
commit bb6a63a4e5
2 changed files with 22 additions and 7 deletions

16
hash.h
View File

@ -263,6 +263,22 @@ static inline void oidcpy(struct object_id *dst, const struct object_id *src)
dst->algo = src->algo;
}
/* Like oidcpy() but zero-pads the unused bytes in dst's hash array. */
static inline void oidcpy_with_padding(struct object_id *dst,
struct object_id *src)
{
size_t hashsz;
if (!src->algo)
hashsz = the_hash_algo->rawsz;
else
hashsz = hash_algos[src->algo].rawsz;
memcpy(dst->hash, src->hash, hashsz);
memset(dst->hash + hashsz, 0, GIT_MAX_RAWSZ - hashsz);
dst->algo = src->algo;
}
static inline struct object_id *oiddup(const struct object_id *src)
{
struct object_id *dst = xmalloc(sizeof(struct object_id));

View File

@ -411,7 +411,7 @@ static void send_one_item(int fd, struct parallel_checkout_item *pc_item)
len_data = sizeof(struct pc_item_fixed_portion) + name_len +
working_tree_encoding_len;
data = xcalloc(1, len_data);
data = xmalloc(len_data);
fixed_portion = (struct pc_item_fixed_portion *)data;
fixed_portion->id = pc_item->id;
@ -421,13 +421,12 @@ static void send_one_item(int fd, struct parallel_checkout_item *pc_item)
fixed_portion->name_len = name_len;
fixed_portion->working_tree_encoding_len = working_tree_encoding_len;
/*
* We use hashcpy() instead of oidcpy() because the hash[] positions
* after `the_hash_algo->rawsz` might not be initialized. And Valgrind
* would complain about passing uninitialized bytes to a syscall
* (write(2)). There is no real harm in this case, but the warning could
* hinder the detection of actual errors.
* We pad the unused bytes in the hash array because, otherwise,
* Valgrind would complain about passing uninitialized bytes to a
* write() syscall. The warning doesn't represent any real risk here,
* but it could hinder the detection of actual errors.
*/
hashcpy(fixed_portion->oid.hash, pc_item->ce->oid.hash);
oidcpy_with_padding(&fixed_portion->oid, &pc_item->ce->oid);
variant = data + sizeof(*fixed_portion);
if (working_tree_encoding_len) {