git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Pedro Alvarez <pedro.alvarez@codethink.co.uk>,
	git@vger.kernel.org,
	Pedro Alvarez Piedehierro <palvarez89@gmail.com>,
	Felipe Contreras <felipe.contreras@gmail.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH] Add initial support for pax extended attributes
Date: Wed, 23 May 2018 00:57:15 -0400	[thread overview]
Message-ID: <20180523045714.GA5567@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqqd0xnw14j.fsf@gitster-ct.c.googlers.com>

On Wed, May 23, 2018 at 11:34:52AM +0900, Junio C Hamano wrote:

> > @@ -90,13 +99,32 @@ foreach my $tar_file (@ARGV)
> >  			Z8 Z1 Z100 Z6
> >  			Z2 Z32 Z32 Z8 Z8 Z*', $_;
> >  		}
> > -		next if $name =~ m{/\z};
> >  		$mode = oct $mode;
> >  		$size = oct $size;
> >  		$mtime = oct $mtime;
> >  		next if $typeflag == 5; # directory
> >  
> > -		if ($typeflag != 1) { # handle hard links later
> > +		if ($typeflag eq 'x') { # extended header
> > +			# If extended header, check for path
> > +			my $pax_header = '';
> > +			while ($size > 0 && read(I, $_, 512) == 512) {
> 
> Would we ever get a short-read (i.e. we ask to read 512 bytes,
> syscall returns after reading only 256 bytes, even though next call
> to read would give the remaining 256 bytes and later ones)?

No, because perl's read() is buffered (you need sysread() to get a real
syscall read). We might read fewer than 512 if we hit EOF, but I think
that would be a truncated input, then, since ustar does everything in
512-byte records.

I do think we'd fail to notice the truncation, which isn't ideal. But it
looks like the rest of the script suffers from the same issue.

If anybody cares, it might not be too hard to wrap all of the 512-byte
read calls into a helper that dies on bogus input. I sort of assumed
this was mostly a proof of concept script and nobody used it, though. :)

It makes me wonder if there is a better-tested tar-reading module in
CPAN that could be used (though at the expense of requiring an extra
dependency).

-Peff

  reply	other threads:[~2018-05-23  4:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-22 10:05 [PATCH] Add initial support for pax extended attributes Pedro Alvarez
2018-05-23  2:34 ` Junio C Hamano
2018-05-23  4:57   ` Jeff King [this message]
2018-05-23 23:38     ` Junio C Hamano
2018-05-23 22:54 ` [PATCH v2 0/1] import-tars: read overlong names from pax extended header Pedro Alvarez
2018-05-23 22:54   ` [PATCH v2 1/1] " Pedro Alvarez

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=20180523045714.GA5567@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=palvarez89@gmail.com \
    --cc=pedro.alvarez@codethink.co.uk \
    /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).