Browse Source

PR: 34241

Tar task now accepts files <8GB (was <2GB), according to POSIX tar standard.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278407 13f79535-47bb-0310-9956-ffa450edef68
master
Jacobus Martinus Kruithof 20 years ago
parent
commit
17c03de41c
5 changed files with 28 additions and 11 deletions
  1. +3
    -0
      WHATSNEW
  2. +5
    -0
      src/main/org/apache/tools/ant/taskdefs/Tar.java
  3. +5
    -0
      src/main/org/apache/tools/tar/TarConstants.java
  4. +12
    -8
      src/main/org/apache/tools/tar/TarInputStream.java
  5. +3
    -3
      src/main/org/apache/tools/tar/TarOutputStream.java

+ 3
- 0
WHATSNEW View File

@@ -109,6 +109,9 @@ Fixed bugs:


* <xmlvalidate> and <schemavalidate> create a new parser for every file in a * <xmlvalidate> and <schemavalidate> create a new parser for every file in a
fileset, and so validate multiple files properly. Bugzilla Report 32791 fileset, and so validate multiple files properly. Bugzilla Report 32791
* <tar> / <untar> now accepts files upto 8GB, <tar> gives an error if larger
files are to be included. This is the POSIX size limit.


Other changes: Other changes:
-------------- --------------


+ 5
- 0
src/main/org/apache/tools/ant/taskdefs/Tar.java View File

@@ -371,6 +371,11 @@ public class Tar extends MatchingTask {
TarEntry te = new TarEntry(vPath); TarEntry te = new TarEntry(vPath);
te.setModTime(file.lastModified()); te.setModTime(file.lastModified());
if (!file.isDirectory()) { if (!file.isDirectory()) {
if (file.length() > TarConstants.MAXSIZE)
{
throw new BuildException("File: " + file + " larger than " +
TarConstants.MAXSIZE + " bytes.");
}
te.setSize(file.length()); te.setSize(file.length());
te.setMode(tarFileSet.getMode()); te.setMode(tarFileSet.getMode());
} else { } else {


+ 5
- 0
src/main/org/apache/tools/tar/TarConstants.java View File

@@ -58,6 +58,11 @@ public interface TarConstants {
* The length of the size field in a header buffer. * The length of the size field in a header buffer.
*/ */
int SIZELEN = 12; int SIZELEN = 12;
/**
* The maximum size of a file in a tar archive (That's 11 sevens, octal).
*/
long MAXSIZE = 077777777777L;


/** /**
* The length of the magic field in a header buffer. * The length of the magic field in a header buffer.


+ 12
- 8
src/main/org/apache/tools/tar/TarInputStream.java View File

@@ -38,8 +38,8 @@ public class TarInputStream extends FilterInputStream {


protected boolean debug; protected boolean debug;
protected boolean hasHitEOF; protected boolean hasHitEOF;
protected int entrySize;
protected int entryOffset;
protected long entrySize;
protected long entryOffset;
protected byte[] readBuf; protected byte[] readBuf;
protected TarBuffer buffer; protected TarBuffer buffer;
protected TarEntry currEntry; protected TarEntry currEntry;
@@ -119,13 +119,18 @@ public class TarInputStream extends FilterInputStream {
* is left in the entire archive, only in the current entry. * is left in the entire archive, only in the current entry.
* This value is determined from the entry's size header field * This value is determined from the entry's size header field
* and the amount of data already read from the current entry. * and the amount of data already read from the current entry.
*
* Integer.MAX_VALUE is returen in case more than Integer.MAX_VALUE
* bytes are left in the current entry in the archive.
* *
* @return The number of available bytes for the current entry. * @return The number of available bytes for the current entry.
* @throws IOException for signature * @throws IOException for signature
*/ */
public int available() throws IOException { public int available() throws IOException {
return this.entrySize - this.entryOffset;
if (this.entrySize - this.entryOffset > Integer.MAX_VALUE)
{
return Integer.MAX_VALUE;
}
return (int) (this.entrySize - this.entryOffset);
} }


/** /**
@@ -198,7 +203,7 @@ public class TarInputStream extends FilterInputStream {
} }


if (this.currEntry != null) { if (this.currEntry != null) {
int numToSkip = this.entrySize - this.entryOffset;
long numToSkip = this.entrySize - this.entryOffset;


if (this.debug) { if (this.debug) {
System.err.println("TarInputStream: SKIP currENTRY '" System.err.println("TarInputStream: SKIP currENTRY '"
@@ -249,8 +254,7 @@ public class TarInputStream extends FilterInputStream {


this.entryOffset = 0; this.entryOffset = 0;


// REVIEW How do we resolve this discrepancy?!
this.entrySize = (int) this.currEntry.getSize();
this.entrySize = this.currEntry.getSize();
} }


if (this.currEntry != null && this.currEntry.isGNULongNameEntry()) { if (this.currEntry != null && this.currEntry.isGNULongNameEntry()) {
@@ -308,7 +312,7 @@ public class TarInputStream extends FilterInputStream {
} }


if ((numToRead + this.entryOffset) > this.entrySize) { if ((numToRead + this.entryOffset) > this.entrySize) {
numToRead = (this.entrySize - this.entryOffset);
numToRead = (int) (this.entrySize - this.entryOffset);
} }


if (this.readBuf != null) { if (this.readBuf != null) {


+ 3
- 3
src/main/org/apache/tools/tar/TarOutputStream.java View File

@@ -43,8 +43,8 @@ public class TarOutputStream extends FilterOutputStream {
public static final int LONGFILE_GNU = 2; public static final int LONGFILE_GNU = 2;


protected boolean debug; protected boolean debug;
protected int currSize;
protected int currBytes;
protected long currSize;
protected long currBytes;
protected byte[] oneBuf; protected byte[] oneBuf;
protected byte[] recordBuf; protected byte[] recordBuf;
protected int assemLen; protected int assemLen;
@@ -189,7 +189,7 @@ public class TarOutputStream extends FilterOutputStream {
if (entry.isDirectory()) { if (entry.isDirectory()) {
this.currSize = 0; this.currSize = 0;
} else { } else {
this.currSize = (int) entry.getSize();
this.currSize = entry.getSize();
} }
} }




Loading…
Cancel
Save