You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2016/02/14 12:03:47 UTC
commons-compress git commit: COMPRESS-336 properly parse prefix in
xstar tar headers
Repository: commons-compress
Updated Branches:
refs/heads/master 7250daa42 -> 32633c39f
COMPRESS-336 properly parse prefix in xstar tar headers
Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/32633c39
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/32633c39
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/32633c39
Branch: refs/heads/master
Commit: 32633c39ffe7aa2ba24899877c7425803b10444d
Parents: 7250daa
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sun Feb 14 12:03:15 2016 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sun Feb 14 12:03:15 2016 +0100
----------------------------------------------------------------------
src/changes/changes.xml | 4 ++
.../compress/archivers/tar/TarArchiveEntry.java | 41 ++++++++++++++++++++
.../compress/archivers/tar/TarConstants.java | 38 ++++++++++++++++++
3 files changed, 83 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/32633c39/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 5612f69..e2a6961 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -44,6 +44,10 @@ The <action> type attribute can be add,update,fix,remove.
<body>
<release version="1.11" date="not released, yet"
description="Release 1.11">
+ <action issue="COMPRESS-336" type="fix" date="2016-02-14">
+ file names of tar archives using the xstar format are now
+ parsed properly.
+ </action>
<action issue="COMPRESS-335" type="fix" date="2016-02-05">
checksums of tars that pad the checksum field to the left are
now calculated properly.
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/32633c39/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
index 8a7af0e..d206d75 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
@@ -110,6 +110,34 @@ import org.apache.commons.compress.utils.ArchiveUtils;
* };
* </pre>
*
+ * <p>
+ * The C structure for a xstar (Jörg Schilling star) Tar Entry's header is:
+ * <pre>
+ * struct star_header {
+ * char name[100]; // offset 0
+ * char mode[8]; // offset100
+ * char uid[8]; // offset108
+ * char gid[8]; // offset116
+ * char size[12]; // offset124
+ * char mtime[12]; // offset136
+ * char chksum[8]; // offset148
+ * char typeflag; // offset156
+ * char linkname[100]; // offset157
+ * char magic[6]; // offset257
+ * char version[2]; // offset263
+ * char uname[32]; // offset265
+ * char gname[32]; // offset297
+ * char devmajor[8]; // offset329
+ * char devminor[8]; // offset337
+ * char prefix[131]; // offset345
+ * char atime[12]; // offset476
+ * char ctime[12]; // offset488
+ * char mfill[8]; // offset500
+ * char xmagic[4]; // offset508 "tar"
+ * };
+ * </pre>
+ * which is identical to new-style POSIX up to the first 130 bytes of the prefix.</p>
+ *
* @NotThreadSafe
*/
@@ -1053,6 +1081,15 @@ public class TarArchiveEntry implements TarConstants, ArchiveEntry {
offset += REALSIZELEN_GNU;
break;
}
+ case FORMAT_XSTAR: {
+ String xstarPrefix = oldStyle
+ ? TarUtils.parseName(header, offset, PREFIXLEN_XSTAR)
+ : TarUtils.parseName(header, offset, PREFIXLEN_XSTAR, encoding);
+ if (xstarPrefix.length() > 0) {
+ name = xstarPrefix + "/" + name;
+ }
+ break;
+ }
case FORMAT_POSIX:
default: {
String prefix = oldStyle
@@ -1124,6 +1161,10 @@ public class TarArchiveEntry implements TarConstants, ArchiveEntry {
return FORMAT_OLDGNU;
}
if (ArchiveUtils.matchAsciiBuffer(MAGIC_POSIX, header, MAGIC_OFFSET, MAGICLEN)) {
+ if (ArchiveUtils.matchAsciiBuffer(MAGIC_XSTAR, header, XSTAR_MAGIC_OFFSET,
+ XSTAR_MAGIC_LEN)) {
+ return FORMAT_XSTAR;
+ }
return FORMAT_POSIX;
}
return 0;
http://git-wip-us.apache.org/repos/asf/commons-compress/blob/32633c39/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
index 000d126..fa4e40a 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarConstants.java
@@ -44,6 +44,11 @@ public interface TarConstants {
int FORMAT_POSIX = 3;
/**
+ * xstar format used by Jörg Schilling's star.
+ */
+ int FORMAT_XSTAR = 4;
+
+ /**
* The length of the name field in a header buffer.
*/
int NAMELEN = 100;
@@ -311,4 +316,37 @@ public interface TarConstants {
*/
String GNU_LONGLINK = "././@LongLink"; // TODO rename as LONGLINK_GNU ?
+ /**
+ * The magix string used in the last four bytes of the header to
+ * identify the xstar format.
+ */
+ String MAGIC_XSTAR = "tar\0";
+
+ /**
+ * Offset inside the header for the xstar magic bytes.
+ */
+ int XSTAR_MAGIC_OFFSET = 508;
+
+ /**
+ * Length of the XSTAR magic.
+ */
+ int XSTAR_MAGIC_LEN = 4;
+
+ /**
+ * Length of the prefix field in xstar archives.
+ *
+ */
+ int PREFIXLEN_XSTAR = 131;
+
+ /**
+ * The length of the access time field in a xstar header buffer.
+ *
+ */
+ int ATIMELEN_XSTAR = 12;
+
+ /**
+ * The length of the created time field in a xstar header buffer.
+ *
+ */
+ int CTIMELEN_XSTAR = 12;
}