git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Add initial support for pax extended attributes

From
Junio C Hamano <gitster@pobox.com>
Date
May 23, 2018, 02:34 UTC
Message-ID
<xmqqd0xnw14j.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20180522100548.29881-1-pedro.alvarez@codethink.co.uk>
Pedro Alvarez <pedro.alvarez@codethink.co.uk> writes:
> From: Pedro Alvarez Piedehierro <palvarez89@gmail.com>
> Subject: [PATCH] Add initial support for pax extended attributes

Lead it with the name of the area you are adding support for pax ext header, e.g.

    Subject: [PATCH] import-tars: read overlong names from pax extended header
or something.
Show 6 quoted lines
> Sometimes the tar files will contain pax extended attributes to deal
> with cases where the information needed doesn't fit in a standard
> ustar entry.
>
> One of these cases is when the path is larger than 100 characters. A
> pax entry will appear containing two standard ustart entries. The first
u-start? us-tart? sound yummy.  I think s/ustart entries/ustar headers/
> entry will have an 'x' typeflag, and contain the the extended attributes.
s/contain/&s/
Show 5 quoted lines
>
> The pax extended attributes contain one or multiple records constructed as
> follows:
>
>     "%d %s=%s\n", <length>, <keyword>, <value>
> This commit makes sure that we always read the extended attibutes from
s/This commit makes sure/Make sure/;
Show 7 quoted lines
> pax entries, and in the case of finding one, we parse its records
> looking for 'path' information. If this information is found, it's
> stored to be used in the next ustar entry.
>
> Information about the Pax Interchange Format can be found at:
>
>     https://www.freebsd.org/cgi/man.cgi?manpath=FreeBSD+8-current&query=tar&sektion=5.
Show 9 quoted lines
> Before this change, importing gcc tarballs[1] would fail with the
> following error:
>
>     fast-import crash report:
>         fast-import process: 82899
>         parent process     : 82897
>         at 2018-05-21 12:35:27 +0000
>
>     fatal: Unsupported command: 29 atime=1516870168.93527949

Drop "Before this change, " and move the above to the very beginning of the proposed log message. The problem description is always "without this patch applied, we have this problem that needs to be fixed", so "Before this change" is an unnecessary thing to say.

The remainder of the crash log may or may not be in the problem description, if we want to shoot for brevity. If I were writing a log message for this patch, I'd go for even shorter version, e.g.

	Importing gcc tarballs[1] with import-tars script (in
	contrib/) fails when hitting a pax extended header that
	records a long pathname.
	Teach the code to parse and grab information from pax
	extended headers, and reconstruct a long pathname that is
	split into multiple records, to correct this problem.
        The code to parse pax extended headers were written,
        consulting the Pax Interchange Format documentation [2].
	[1] http://ftp.gnu.org/gnu/gcc/gcc-7.3.0/gcc-7.3.0.tar.xz
	[2] https://www.freebsd.org/cgi/man.cgi?manpath=FreeBSD+8-current&query=tar&sektion=5
Show 41 quoted lines
> index d60b4315ed..c2e54ec7a3 100755
> --- a/contrib/fast-import/import-tars.perl
> +++ b/contrib/fast-import/import-tars.perl
> @@ -63,6 +63,8 @@ foreach my $tar_file (@ARGV)
>  	my $have_top_dir = 1;
>  	my ($top_dir, %files);
>  
> +	my $next_path = '';
> +
>  	while (read(I, $_, 512) == 512) {
>  		my ($name, $mode, $uid, $gid, $size, $mtime,
>  			$chksum, $typeflag, $linkname, $magic,
> @@ -70,6 +72,13 @@ foreach my $tar_file (@ARGV)
>  			$prefix) = unpack 'Z100 Z8 Z8 Z8 Z12 Z12
>  			Z8 Z1 Z100 Z6
>  			Z2 Z32 Z32 Z8 Z8 Z*', $_;
> +
> +		unless ($next_path eq '') {
> +			# Recover name from previous extended header
> +			$name = $next_path;
> +			$next_path = '';
> +		}
> +
>  		last unless length($name);
>  		if ($name eq '././@LongLink') {
>  			# GNU tar extension
> @@ -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)?

If we do get a short-read, would that be an error (in which case, how are we handling it)? If it is not an error, should we continue reading, instead of leaving the loop?

Show 15 quoted lines
> +				$pax_header = $pax_header . substr($_, 0, $size);
> +				$size -= 512;
> +			}
> +
> +			my @lines = split /\n/, $pax_header;
> +			foreach my $line (@lines) {
> +				my ($len, $entry) = split / /, $line;
> +				my ($key, $value) = split /=/, $entry;
> +				if ($key eq 'path') {
> +					$next_path = $value;
> +				}
> +			}
> +			next;
> +		} elsif ($name =~ m{/\z}) {
> +			# If it's a folder, ignore

It is a very good idea to add comment on why we are ignoring and doing 'next' here, but the tar format documentation you cited never uses the word 'folder'. s/folder/directory/, probably.

Show 5 quoted lines
> +			next;
> +		} elsif ($typeflag != 1) { # handle hard links later
>  			print FI "blob\n", "mark :$next_mark\n";
>  			if ($typeflag == 2) { # symbolic link
>  				print FI "data ", length($linkname), "\n",
Thanks.
Previous: Pedro AlvarezNext: Jeff King
Message 2 of 6 in “Add initial support for pax extended attributes”
  1. Add initial support for pax extended attributesPedro Alvarez, May 22, 2018
  2. Junio C HamanoMay 23, 2018
  3. Jeff KingMay 23, 2018
  4. Junio C HamanoMay 23, 2018
  5. 0/1 import-tars: read overlong names from pax extended headerPedro Alvarez, May 23, 2018
  6. 1/1 import-tars: read overlong names from pax extended headerPedro Alvarez, May 23, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.