Skip to content

Commit 19ee294

Browse files
rscharfegitster
authored andcommitted
t5004: test ZIP archives with many entries
A ZIP file directory has a 16-bit field for the number of entries it contains. There are 64-bit extensions to deal with that. Demonstrate that git archive --format=zip currently doesn't use them and instead overflows the field. InfoZIP's unzip doesn't care about this field and extracts all files anyway. Software that uses the directory for presenting a filesystem like view quickly -- notably Windows -- depends on it, but doesn't lend itself to an automatic test case easily. Use InfoZIP's zipinfo, which probably isn't available everywhere but at least can provides *some* way to check this field. To speed things up a bit create and commit only a subset of the files and build a fake tree out of duplicates and pass that to git archive. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8545932 commit 19ee294

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

t/t5004-archive-corner-cases.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,44 @@ test_expect_success 'archive empty subtree by direct pathspec' '
115115
check_dir extract sub
116116
'
117117

118+
ZIPINFO=zipinfo
119+
120+
test_lazy_prereq ZIPINFO '
121+
n=$("$ZIPINFO" "$TEST_DIRECTORY"/t5004/empty.zip | sed -n "2s/.* //p")
122+
test "x$n" = "x0"
123+
'
124+
125+
test_expect_failure ZIPINFO 'zip archive with many entries' '
126+
# add a directory with 256 files
127+
mkdir 00 &&
128+
for a in 0 1 2 3 4 5 6 7 8 9 a b c d e f
129+
do
130+
for b in 0 1 2 3 4 5 6 7 8 9 a b c d e f
131+
do
132+
: >00/$a$b
133+
done
134+
done &&
135+
git add 00 &&
136+
git commit -m "256 files in 1 directory" &&
137+
138+
# duplicate it to get 65536 files in 256 directories
139+
subtree=$(git write-tree --prefix=00/) &&
140+
for c in 0 1 2 3 4 5 6 7 8 9 a b c d e f
141+
do
142+
for d in 0 1 2 3 4 5 6 7 8 9 a b c d e f
143+
do
144+
echo "040000 tree $subtree $c$d"
145+
done
146+
done >tree &&
147+
tree=$(git mktree <tree) &&
148+
149+
# zip them
150+
git archive -o many.zip $tree &&
151+
152+
# check the number of entries in the ZIP file directory
153+
expr 65536 + 256 >expect &&
154+
"$ZIPINFO" many.zip | head -2 | sed -n "2s/.* //p" >actual &&
155+
test_cmp expect actual
156+
'
157+
118158
test_done

0 commit comments

Comments
 (0)