Skip to content

Commit 4c9355f

Browse files
committed
repack: check error writing to pack-objects subprocess
When "git repack" repacks promisor objects, it starts a pack-objects subprocess and uses xwrite() to send object names over the pipe to it, but without any error checking. An I/O error or short write (even though a short write is unlikely for such a small amount of data) can result in a packfile that lacks certain objects we wanted to put in there, leading to a silent repository corruption. Use write_in_full(), instead of xwrite(), to mitigate short write risks, check errors from it, and abort if we see a failure. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 36ffba1 commit 4c9355f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

builtin/repack.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,9 @@ static int write_oid(const struct object_id *oid,
314314
die(_("could not start pack-objects to repack promisor objects"));
315315
}
316316

317-
xwrite(cmd->in, oid_to_hex(oid), the_hash_algo->hexsz);
318-
xwrite(cmd->in, "\n", 1);
317+
if (write_in_full(cmd->in, oid_to_hex(oid), the_hash_algo->hexsz) < 0 ||
318+
write_in_full(cmd->in, "\n", 1) < 0)
319+
die(_("failed to feed promisor objects to pack-objects"));
319320
return 0;
320321
}
321322

0 commit comments

Comments
 (0)