Skip to content

Commit c5049f1

Browse files
jeffhostetlerdscho
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 <[email protected]>
1 parent ec3d8e4 commit c5049f1

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
@@ -518,6 +518,8 @@ static enum worker_result send_loose_object(const struct object_id *oid,
518518
unsigned long size;
519519
enum object_type type;
520520
struct object_info oi = OBJECT_INFO_INIT;
521+
int mayhem__corrupt_loose = string_list_has_string(&mayhem_list,
522+
"corrupt_loose");
521523

522524
/*
523525
* Since `test-gvfs-protocol` is mocking a real GVFS server (cache or
@@ -639,7 +641,22 @@ static enum worker_result send_loose_object(const struct object_id *oid,
639641
do {
640642
enum worker_result wr;
641643
unsigned char *in0 = stream.next_in;
644+
645+
/*
646+
* Corrupt a byte in the buffer we compress, but undo it
647+
* before we compute the SHA on the portion of the raw
648+
* buffer included in the chunk we compressed.
649+
*/
650+
if (mayhem__corrupt_loose) {
651+
logmayhem("corrupt_loose");
652+
*in0 = *in0 ^ 0xff;
653+
}
654+
642655
ret = git_deflate(&stream, Z_FINISH);
656+
657+
if (mayhem__corrupt_loose)
658+
*in0 = *in0 ^ 0xff;
659+
643660
the_hash_algo->update_fn(&c, in0, stream.next_in - in0);
644661

645662
/* [5] */

t/t5799-gvfs-helper.sh

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

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

0 commit comments

Comments
 (0)