Skip to content

Commit

Permalink
Merge branch 'rs/pax-extended-header-length-fix' into next
Browse files Browse the repository at this point in the history
"git archive" recorded incorrect length in extended pax header in
some corner cases, which has been corrected.

* rs/pax-extended-header-length-fix:
  archive-tar: turn length miscalculation warning into BUG
  archive-tar: use size_t in strbuf_append_ext_header()
  archive-tar: fix pax extended header length calculation
  archive-tar: report wrong pax extended header length
  • Loading branch information
gitster committed Aug 23, 2019
2 parents 7b1fffb + 71d41ff commit de88e8e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
14 changes: 10 additions & 4 deletions archive-tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,25 @@ static int stream_blocked(const struct object_id *oid)
* string and appends it to a struct strbuf.
*/
static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword,
const char *value, unsigned int valuelen)
const char *value, size_t valuelen)
{
int len, tmp;
size_t orig_len = sb->len;
size_t len, tmp;

/* "%u %s=%s\n" */
len = 1 + 1 + strlen(keyword) + 1 + valuelen + 1;
for (tmp = len; tmp > 9; tmp /= 10)
for (tmp = 1; len / 10 >= tmp; tmp *= 10)
len++;

strbuf_grow(sb, len);
strbuf_addf(sb, "%u %s=", len, keyword);
strbuf_addf(sb, "%"PRIuMAX" %s=", (uintmax_t)len, keyword);
strbuf_add(sb, value, valuelen);
strbuf_addch(sb, '\n');

if (len != sb->len - orig_len)
BUG("pax extended header length miscalculated as %"PRIuMAX
", should be %"PRIuMAX,
(uintmax_t)len, (uintmax_t)(sb->len - orig_len));
}

/*
Expand Down
19 changes: 19 additions & 0 deletions t/t5004-archive-corner-cases.sh
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,23 @@ test_expect_success EXPENSIVE,LONG_IS_64BIT,UNZIP,UNZIP_ZIP64_SUPPORT,ZIPINFO \
grep $size big.lst
'

build_tree() {
perl -e '
my $hash = $ARGV[0];
foreach my $order (2..6) {
$first = 10 ** $order;
foreach my $i (-13..-9) {
my $name = "a" x ($first + $i);
print "100644 blob $hash\t$name\n"
}
}
' "$1"
}

test_expect_success 'tar archive with long paths' '
blob=$(echo foo | git hash-object -w --stdin) &&
tree=$(build_tree $blob | git mktree) &&
git archive -o long_paths.tar $tree
'

test_done

0 comments on commit de88e8e

Please sign in to comment.