Skip to content

Commit 7b6257b

Browse files
peffgitster
authored andcommitted
add test for streaming corrupt blobs
We do not have many tests for handling corrupt objects. This new test at least checks that we detect a byte error in a corrupt blob object while streaming it out with cat-file. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 692f0bc commit 7b6257b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

t/t1060-object-corruption.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/sh
2+
3+
test_description='see how we handle various forms of corruption'
4+
. ./test-lib.sh
5+
6+
# convert "1234abcd" to ".git/objects/12/34abcd"
7+
obj_to_file() {
8+
echo "$(git rev-parse --git-dir)/objects/$(git rev-parse "$1" | sed 's,..,&/,')"
9+
}
10+
11+
# Convert byte at offset "$2" of object "$1" into '\0'
12+
corrupt_byte() {
13+
obj_file=$(obj_to_file "$1") &&
14+
chmod +w "$obj_file" &&
15+
printf '\0' | dd of="$obj_file" bs=1 seek="$2" conv=notrunc
16+
}
17+
18+
test_expect_success 'setup corrupt repo' '
19+
git init bit-error &&
20+
(
21+
cd bit-error &&
22+
test_commit content &&
23+
corrupt_byte HEAD:content.t 10
24+
)
25+
'
26+
27+
test_expect_success 'streaming a corrupt blob fails' '
28+
(
29+
cd bit-error &&
30+
test_must_fail git cat-file blob HEAD:content.t
31+
)
32+
'
33+
34+
test_done

0 commit comments

Comments
 (0)