archive-tar: report wrong pax extended header length
Extended header entries contain a length value that is a bit tricky to calculate because it includes its own length (number of decimal digits) as well. We get it wrong in corner cases. Add a check, report wrong results as a warning and add a test for exercising it. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Aug 17, 2019 at 18:23 UTC
4060c1990a9cceb710808bd4b4ab94d2355aefff
2 files changed
+26
archive-tar.c
+6
@@ -144,6 +144,7 @@ static int stream_blocked(const struct object_id *oid)
144
static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword,
145
const char *value, unsigned int valuelen)
146
{
147
+ size_t orig_len = sb->len;
148
int len, tmp;
149
150
/* "%u %s=%s\n" */
@@ -155,6 +156,11 @@ static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword,
156
strbuf_addf(sb, "%u %s=", len, keyword);
157
strbuf_add(sb, value, valuelen);
158
strbuf_addch(sb, '\n');
159
+
160
+ if (len != sb->len - orig_len)
161
+ warning("pax extended header length miscalculated as %d"
162
+ ", should be %"PRIuMAX,
163
+ len, (uintmax_t)(sb->len - orig_len));
164
}
165
166
/*
t/t5004-archive-corner-cases.sh
+20
@@ -204,4 +204,24 @@ test_expect_success EXPENSIVE,LONG_IS_64BIT,UNZIP,UNZIP_ZIP64_SUPPORT,ZIPINFO \
204
grep $size big.lst
205
'
206
207
+build_tree() {
208
+ perl -e '
209
+ my $hash = $ARGV[0];
210
+ foreach my $order (2..6) {
211
+ $first = 10 ** $order;
212
+ foreach my $i (-13..-9) {
213
+ my $name = "a" x ($first + $i);
214
+ print "100644 blob $hash\t$name\n"
215
+ }
216
+ }
217
+ ' "$1"
218
+}
219
+
220
+test_expect_failure 'tar archive with long paths' '
221
+ blob=$(echo foo | git hash-object -w --stdin) &&
222
+ tree=$(build_tree $blob | git mktree) &&
223
+ git archive -o long_paths.tar $tree 2>stderr &&
224
+ test_must_be_empty stderr
225
+'
226
+
227
test_done