Skip to content

Commit 7c2115a

Browse files
peffgitster
authored andcommitted
t5313: make extended-table test more deterministic
Commit a128386 (t5313: test bounds-checks of corrupted/malicious pack/idx files, 2016-02-25) added a test that requires our corrupted pack index to have two objects. The entry for the first one remains untouched, but we corrupt the entry for second one. Since the index stores the entries in sha1-sorted order, this means that the test must make sure that the sha1 of the object we expect to be corrupted ("$object") sorts after the other placeholder object. That commit used the HEAD commit as the placeholder, but the script never calls test_tick. That means that the commit object (and thus its sha1) depends on the timestamp when the test script is run. This usually works in practice, because the sha1 of $object starts with "fff". The commit object will sort after that only 1 in 4096 times, but when it does the test will fail. One obvious solution is to add the test_tick call to get a deterministic commit sha1. But since we're relying on the sort order for the test to function, let's make that very explicit by just generating a second blob with a known sha1. Reported-by: Lars Schneider <larsxschneider@gmail.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 7465feb commit 7c2115a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

t/t5313-pack-bounds-checks.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ test_expect_success 'bogus offset into v2 extended table' '
139139
test_expect_success 'bogus offset inside v2 extended table' '
140140
# We need two objects here, so we can plausibly require
141141
# an extended table (if the first object were larger than 2^31).
142-
do_pack "$object $(git rev-parse HEAD)" --index-version=2 &&
142+
#
143+
# Note that the value is important here. We want $object as
144+
# the second entry in sorted-sha1 order. The sha1 of 1485 starts
145+
# with "000", which sorts before that of $object (which starts
146+
# with "fff").
147+
second=$(echo 1485 | git hash-object -w --stdin) &&
148+
do_pack "$object $second" --index-version=2 &&
143149
144150
# We have to make extra room for the table, so we cannot
145151
# just munge in place as usual.

0 commit comments

Comments
 (0)