Skip to content

Commit a612a0f

Browse files
jeffhostetlerderrickstolee
authored andcommitted
t7599: create corrupt blob test
Teach helper/test-gvfs-protocol to be able to send corrupted loose blobs. Add unit test for gvfs-helper to detect receipt of a corrupted loose blob. Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
1 parent 9c2c440 commit a612a0f

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

t/helper/test-gvfs-protocol.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ static enum worker_result send_loose_object(const struct object_id *oid,
510510
unsigned long size;
511511
enum object_type type;
512512
struct object_info oi = OBJECT_INFO_INIT;
513+
int mayhem__corrupt_loose = string_list_has_string(&mayhem_list,
514+
"corrupt_loose");
513515

514516
/*
515517
* Since `test-gvfs-protocol` is mocking a real GVFS server (cache or
@@ -626,7 +628,22 @@ static enum worker_result send_loose_object(const struct object_id *oid,
626628
do {
627629
enum worker_result wr;
628630
unsigned char *in0 = stream.next_in;
631+
632+
/*
633+
* Corrupt a byte in the buffer we compress, but undo it
634+
* before we compute the SHA on the portion of the raw
635+
* buffer included in the chunk we compressed.
636+
*/
637+
if (mayhem__corrupt_loose) {
638+
logmayhem("corrupt_loose");
639+
*in0 = *in0 ^ 0xff;
640+
}
641+
629642
ret = git_deflate(&stream, Z_FINISH);
643+
644+
if (mayhem__corrupt_loose)
645+
*in0 = *in0 ^ 0xff;
646+
630647
the_hash_algo->update_fn(&c, in0, stream.next_in - in0);
631648

632649
/* [5] */

t/t5799-gvfs-helper.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,4 +1047,36 @@ test_expect_success 'integration: fully implicit: diff 2 commits' '
10471047
>OUT.output 2>OUT.stderr
10481048
'
10491049

1050+
#################################################################
1051+
# Ensure that the SHA of the blob we received matches the SHA of
1052+
# the blob we requested.
1053+
#################################################################
1054+
1055+
# Request a loose blob from the server. Verify that we received
1056+
# content matches the requested SHA.
1057+
#
1058+
test_expect_success 'catch corrupted loose object' '
1059+
# test_when_finished "per_test_cleanup" &&
1060+
start_gvfs_protocol_server_with_mayhem corrupt_loose &&
1061+
1062+
test_must_fail \
1063+
git -C "$REPO_T1" gvfs-helper \
1064+
--cache-server=trust \
1065+
--remote=origin \
1066+
get \
1067+
<"$OID_ONE_BLOB_FILE" >OUT.output 2>OUT.stderr &&
1068+
1069+
stop_gvfs_protocol_server &&
1070+
1071+
# Verify corruption detected.
1072+
# Verify valid blob not included in response to client.
1073+
1074+
grep "hash failed for received loose object" OUT.stderr &&
1075+
1076+
# Verify that we did not write the corrupted blob to the ODB.
1077+
1078+
! verify_objects_in_shared_cache "$OID_ONE_BLOB_FILE" &&
1079+
git -C "$REPO_T1" fsck
1080+
'
1081+
10501082
test_done

0 commit comments

Comments
 (0)