Skip to content

Commit ad5505f

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 7750d2c commit ad5505f

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

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
@@ -623,7 +625,22 @@ static enum worker_result send_loose_object(const struct object_id *oid,
623625
do {
624626
enum worker_result wr;
625627
unsigned char *in0 = stream.next_in;
628+
629+
/*
630+
* Corrupt a byte in the buffer we compress, but undo it
631+
* before we compute the SHA on the portion of the raw
632+
* buffer included in the chunk we compressed.
633+
*/
634+
if (mayhem__corrupt_loose) {
635+
logmayhem("corrupt_loose");
636+
*in0 = *in0 ^ 0xff;
637+
}
638+
626639
ret = git_deflate(&stream, Z_FINISH);
640+
641+
if (mayhem__corrupt_loose)
642+
*in0 = *in0 ^ 0xff;
643+
627644
the_hash_algo->update_fn(&c, in0, stream.next_in - in0);
628645

629646
/* [5] */

t/t5799-gvfs-helper.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,4 +1288,37 @@ test_expect_success 'duplicate and busy: vfs- packfile' '
12881288
stop_gvfs_protocol_server
12891289
'
12901290

1291+
#################################################################
1292+
# Ensure that the SHA of the blob we received matches the SHA of
1293+
# the blob we requested.
1294+
#################################################################
1295+
1296+
# Request a loose blob from the server. Verify that we received
1297+
# content matches the requested SHA.
1298+
#
1299+
test_expect_success 'catch corrupted loose object' '
1300+
# test_when_finished "per_test_cleanup" &&
1301+
start_gvfs_protocol_server_with_mayhem corrupt_loose &&
1302+
1303+
test_must_fail \
1304+
git -C "$REPO_T1" gvfs-helper \
1305+
--cache-server=trust \
1306+
--remote=origin \
1307+
get \
1308+
<"$OID_ONE_BLOB_FILE" >OUT.output 2>OUT.stderr &&
1309+
1310+
stop_gvfs_protocol_server &&
1311+
1312+
# Verify corruption detected.
1313+
# Verify valid blob not included in response to client.
1314+
1315+
grep "hash failed for received loose object" OUT.stderr &&
1316+
1317+
# Verify that we did not write the corrupted blob to the ODB.
1318+
1319+
test_must_fail \
1320+
verify_objects_in_shared_cache "$OID_ONE_BLOB_FILE" &&
1321+
git -C "$REPO_T1" fsck
1322+
'
1323+
12911324
test_done

0 commit comments

Comments
 (0)