Issue #901: Sparse files with long name get renamed.

The original ustar header has a 100 character limit for the file name.
With the POSIX interchange format, an additional header attribute
contains the full path and libarchive tries to cut it to something
sensible. The GNU sparse file extension on the other hand also likes to
mangle the ustar header field to include a marker and contains yet
another attribute for the original path. If the name was truncated
earlier, this attribute would get the incorrect truncated name.
diff --git a/libarchive/archive_write_set_format_pax.c b/libarchive/archive_write_set_format_pax.c
index 5fdfd9d..0eaf733 100644
--- a/libarchive/archive_write_set_format_pax.c
+++ b/libarchive/archive_write_set_format_pax.c
@@ -1196,8 +1196,12 @@
 			    "GNU.sparse.major", 1);
 			add_pax_attr_int(&(pax->pax_header),
 			    "GNU.sparse.minor", 0);
+			/*
+			 * Make sure to store the original path, since
+			 * truncation to ustar limit happened already.
+			 */
 			add_pax_attr(&(pax->pax_header),
-			    "GNU.sparse.name", entry_name.s);
+			    "GNU.sparse.name", path);
 			add_pax_attr_int(&(pax->pax_header),
 			    "GNU.sparse.realsize",
 			    archive_entry_size(entry_main));
diff --git a/libarchive/test/test_write_format_pax.c b/libarchive/test/test_write_format_pax.c
index 1bae005..41a423a 100644
--- a/libarchive/test/test_write_format_pax.c
+++ b/libarchive/test/test_write_format_pax.c
@@ -80,13 +80,19 @@
 	/*
 	 * "file3" is sparse file and has hole size of which is
 	 * 1024000 bytes, and has 8 bytes data after the hole.
+	 *
+	 * Pad the filename to make it larger than the ustar limit.
+	 * It should still read back correctly.
 	 */
 	assert((ae = archive_entry_new()) != NULL);
 	archive_entry_set_atime(ae, 2, 20);
 	archive_entry_set_birthtime(ae, 3, 30);
 	archive_entry_set_ctime(ae, 4, 40);
 	archive_entry_set_mtime(ae, 5, 50);
-	archive_entry_copy_pathname(ae, "file3");
+	archive_entry_copy_pathname(ae, "file3"
+	    "_123456789_123456789_123456789_123456789_123456789"
+	    "_123456789_123456789_123456789_123456789_123456789"
+	    "_123456789_123456789_123456789_123456789_123456789");
 	archive_entry_set_mode(ae, S_IFREG | 0755);
 	archive_entry_set_size(ae, 1024008);
 	archive_entry_sparse_add_entry(ae, 1024000, 8);
@@ -171,7 +177,11 @@
 	assertEqualInt(40, archive_entry_ctime_nsec(ae));
 	assertEqualInt(5, archive_entry_mtime(ae));
 	assertEqualInt(50, archive_entry_mtime_nsec(ae));
-	assertEqualString("file3", archive_entry_pathname(ae));
+	assertEqualString("file3"
+	    "_123456789_123456789_123456789_123456789_123456789"
+	    "_123456789_123456789_123456789_123456789_123456789"
+	    "_123456789_123456789_123456789_123456789_123456789",
+	    archive_entry_pathname(ae));
 	assert((S_IFREG | 0755) == archive_entry_mode(ae));
 	assertEqualInt(1024008, archive_entry_size(ae));
 	assertEqualInt(1, archive_entry_sparse_reset(ae));