git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Git Mailing List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 1/4] archive-tar: report wrong pax extended header length
Date: Sat, 17 Aug 2019 18:23:52 +0200	[thread overview]
Message-ID: <c9915187-cb18-2619-f50b-12fe93c2578c@web.de> (raw)
In-Reply-To: <c77a0081-93ab-7b97-e322-9616f6e7f86c@web.de>

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>
---
 archive-tar.c                   |  6 ++++++
 t/t5004-archive-corner-cases.sh | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/archive-tar.c b/archive-tar.c
index 3e53aac1e6..355c8142c6 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -144,6 +144,7 @@ static int stream_blocked(const struct object_id *oid)
 static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword,
 				     const char *value, unsigned int valuelen)
 {
+	size_t orig_len = sb->len;
 	int len, tmp;

 	/* "%u %s=%s\n" */
@@ -155,6 +156,11 @@ static void strbuf_append_ext_header(struct strbuf *sb, const char *keyword,
 	strbuf_addf(sb, "%u %s=", len, keyword);
 	strbuf_add(sb, value, valuelen);
 	strbuf_addch(sb, '\n');
+
+	if (len != sb->len - orig_len)
+		warning("pax extended header length miscalculated as %d"
+			", should be %"PRIuMAX,
+			len, (uintmax_t)(sb->len - orig_len));
 }

 /*
diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh
index 271eb5a1fd..2f15d1899d 100755
--- a/t/t5004-archive-corner-cases.sh
+++ b/t/t5004-archive-corner-cases.sh
@@ -204,4 +204,24 @@ 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_failure '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 2>stderr &&
+	test_must_be_empty stderr
+'
+
 test_done
--
2.23.0

  reply	other threads:[~2019-08-17 16:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-17 16:19 [PATCH 0/4] fix pax extended header length calculation René Scharfe
2019-08-17 16:23 ` René Scharfe [this message]
2019-08-17 16:24 ` [PATCH 2/4] archive-tar: " René Scharfe
2019-08-17 18:03   ` Eric Sunshine
2019-08-17 16:24 ` [PATCH 3/4] archive-tar: use size_t in strbuf_append_ext_header() René Scharfe
2019-08-17 16:24 ` [PATCH 4/4] archive-tar: turn length miscalculation warning into BUG René Scharfe
2019-08-17 16:40 ` [PATCH 0/4] fix pax extended header length calculation brian m. carlson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c9915187-cb18-2619-f50b-12fe93c2578c@web.de \
    --to=l.s.r@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).