Skip to content

Commit

Permalink
t7599: create corrupt blob test
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jeffhostetler authored and vdye committed Jul 19, 2023
1 parent 76ca12f commit ae0852f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
17 changes: 17 additions & 0 deletions t/helper/test-gvfs-protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ static enum worker_result send_loose_object(const struct object_id *oid,
unsigned long size;
enum object_type type;
struct object_info oi = OBJECT_INFO_INIT;
int mayhem__corrupt_loose = string_list_has_string(&mayhem_list,
"corrupt_loose");

/*
* Since `test-gvfs-protocol` is mocking a real GVFS server (cache or
Expand Down Expand Up @@ -633,7 +635,22 @@ static enum worker_result send_loose_object(const struct object_id *oid,
do {
enum worker_result wr;
unsigned char *in0 = stream.next_in;

/*
* Corrupt a byte in the buffer we compress, but undo it
* before we compute the SHA on the portion of the raw
* buffer included in the chunk we compressed.
*/
if (mayhem__corrupt_loose) {
logmayhem("corrupt_loose");
*in0 = *in0 ^ 0xff;
}

ret = git_deflate(&stream, Z_FINISH);

if (mayhem__corrupt_loose)
*in0 = *in0 ^ 0xff;

the_hash_algo->update_fn(&c, in0, stream.next_in - in0);

/* [5] */
Expand Down
32 changes: 32 additions & 0 deletions t/t5799-gvfs-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1047,4 +1047,36 @@ test_expect_success 'integration: fully implicit: diff 2 commits' '
>OUT.output 2>OUT.stderr
'

#################################################################
# Ensure that the SHA of the blob we received matches the SHA of
# the blob we requested.
#################################################################

# Request a loose blob from the server. Verify that we received
# content matches the requested SHA.
#
test_expect_success 'catch corrupted loose object' '
# test_when_finished "per_test_cleanup" &&
start_gvfs_protocol_server_with_mayhem corrupt_loose &&
test_must_fail \
git -C "$REPO_T1" gvfs-helper \
--cache-server=trust \
--remote=origin \
get \
<"$OID_ONE_BLOB_FILE" >OUT.output 2>OUT.stderr &&
stop_gvfs_protocol_server &&
# Verify corruption detected.
# Verify valid blob not included in response to client.
grep "hash failed for received loose object" OUT.stderr &&
# Verify that we did not write the corrupted blob to the ODB.
! verify_objects_in_shared_cache "$OID_ONE_BLOB_FILE" &&
git -C "$REPO_T1" fsck
'

test_done

0 comments on commit ae0852f

Please sign in to comment.