From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH] archive-tar: split long paths more carefully
Date: Sat, 05 Jan 2013 23:49:54 +0100 [thread overview]
Message-ID: <50E8AE12.8040102@lsrfire.ath.cx> (raw)
In-Reply-To: <7vwqw7mb09.fsf@alter.siamese.dyndns.org>
The name field of a tar header has a size of 100 characters. This limit
was extended long ago in a backward compatible way by providing the
additional prefix field, which can hold 155 additional characters. The
actual path is constructed at extraction time by concatenating the prefix
field, a slash and the name field.
get_path_prefix() is used to determine which slash in the path is used as
the cutting point and thus which part of it is placed into the field
prefix and which into the field name. It tries to cram as much into the
prefix field as possible. (And only if we can't fit a path into the
provided 255 characters we use a pax extended header to store it.)
If a path is longer than 100 but shorter than 156 characters and ends
with a slash (i.e. is for a directory) then get_path_prefix() puts the
whole path in the prefix field and leaves the name field empty. GNU tar
reconstructs the path without complaint, but the tar included with
NetBSD 6 does not: It reports the header to be invalid.
For compatibility with this version of tar, make sure to never leave the
name field empty. In order to do that, trim the trailing slash from the
part considered as possible prefix, if it exists -- that way the last
path component (or more, but not less) will end up in the name field.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
archive-tar.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/archive-tar.c b/archive-tar.c
index 0ba3f25..923daf5 100644
--- a/archive-tar.c
+++ b/archive-tar.c
@@ -153,6 +153,8 @@ static unsigned int ustar_header_chksum(const struct ustar_header *header)
static size_t get_path_prefix(const char *path, size_t pathlen, size_t maxlen)
{
size_t i = pathlen;
+ if (i > 1 && path[i - 1] == '/')
+ i--;
if (i > maxlen)
i = maxlen;
do {
--
1.7.12
next prev parent reply other threads:[~2013-01-05 22:50 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-24 20:49 [LHF] making t5000 "tar xf" tests more lenient Junio C Hamano
2013-01-05 18:34 ` René Scharfe
2013-01-05 19:43 ` Junio C Hamano
2013-01-05 20:11 ` Junio C Hamano
2013-01-05 22:50 ` René Scharfe
2013-01-05 22:49 ` René Scharfe [this message]
2013-01-05 23:31 ` [PATCH] archive-tar: split long paths more carefully Jonathan Nieder
2013-01-06 6:54 ` Junio C Hamano
2013-01-06 15:20 ` [PATCH] archive-zip: write uncompressed size into header even with streaming René Scharfe
2013-01-06 17:45 ` [PATCH 0/4] ZIP test fixes René Scharfe
2013-01-06 17:47 ` [PATCH 1/4] t0024, t5000: clear variable UNZIP, use GIT_UNZIP instead René Scharfe
2013-01-07 5:16 ` Jonathan Nieder
2013-01-07 16:25 ` René Scharfe
2013-01-06 17:49 ` [PATCH 2/4] t0024, t5000: use test_lazy_prereq for UNZIP René Scharfe
2013-01-06 18:06 ` Matt Kraai
2013-01-06 21:59 ` René Scharfe
2013-01-07 8:45 ` Jonathan Nieder
2013-01-07 16:28 ` René Scharfe
2013-01-06 17:51 ` [PATCH 3/4] t5000, t5002: move ZIP tests into their own script René Scharfe
2013-01-06 17:59 ` [PATCH 4/4] t5002: check if unzip supports symlinks René Scharfe
2013-01-07 8:52 ` Jonathan Nieder
2013-01-07 16:50 ` René Scharfe
2013-01-10 7:36 ` Jonathan Nieder
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50E8AE12.8040102@lsrfire.ath.cx \
--to=rene.scharfe@lsrfire.ath.cx \
--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.
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 NNTP newsgroup(s).