diff --git a/WHATSNEW b/WHATSNEW index d91276fc5..a1a5311a5 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -109,6 +109,9 @@ Fixed bugs: * and create a new parser for every file in a fileset, and so validate multiple files properly. Bugzilla Report 32791 + +* / now accepts files upto 8GB, gives an error if larger + files are to be included. This is the POSIX size limit. Other changes: -------------- diff --git a/src/main/org/apache/tools/ant/taskdefs/Tar.java b/src/main/org/apache/tools/ant/taskdefs/Tar.java index 29f1ddaa6..f2278f5a7 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Tar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Tar.java @@ -371,6 +371,11 @@ public class Tar extends MatchingTask { TarEntry te = new TarEntry(vPath); te.setModTime(file.lastModified()); if (!file.isDirectory()) { + if (file.length() > TarConstants.MAXSIZE) + { + throw new BuildException("File: " + file + " larger than " + + TarConstants.MAXSIZE + " bytes."); + } te.setSize(file.length()); te.setMode(tarFileSet.getMode()); } else { diff --git a/src/main/org/apache/tools/tar/TarConstants.java b/src/main/org/apache/tools/tar/TarConstants.java index 59beb71d1..c4c3a88d5 100644 --- a/src/main/org/apache/tools/tar/TarConstants.java +++ b/src/main/org/apache/tools/tar/TarConstants.java @@ -58,6 +58,11 @@ public interface TarConstants { * The length of the size field in a header buffer. */ 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. diff --git a/src/main/org/apache/tools/tar/TarInputStream.java b/src/main/org/apache/tools/tar/TarInputStream.java index 7b7e9859f..c460356a4 100644 --- a/src/main/org/apache/tools/tar/TarInputStream.java +++ b/src/main/org/apache/tools/tar/TarInputStream.java @@ -38,8 +38,8 @@ public class TarInputStream extends FilterInputStream { protected boolean debug; protected boolean hasHitEOF; - protected int entrySize; - protected int entryOffset; + protected long entrySize; + protected long entryOffset; protected byte[] readBuf; protected TarBuffer buffer; protected TarEntry currEntry; @@ -119,13 +119,18 @@ public class TarInputStream extends FilterInputStream { * is left in the entire archive, only in the current entry. * This value is determined from the entry's size header field * 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. * @throws IOException for signature */ 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) { - int numToSkip = this.entrySize - this.entryOffset; + long numToSkip = this.entrySize - this.entryOffset; if (this.debug) { System.err.println("TarInputStream: SKIP currENTRY '" @@ -249,8 +254,7 @@ public class TarInputStream extends FilterInputStream { 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()) { @@ -308,7 +312,7 @@ public class TarInputStream extends FilterInputStream { } if ((numToRead + this.entryOffset) > this.entrySize) { - numToRead = (this.entrySize - this.entryOffset); + numToRead = (int) (this.entrySize - this.entryOffset); } if (this.readBuf != null) { diff --git a/src/main/org/apache/tools/tar/TarOutputStream.java b/src/main/org/apache/tools/tar/TarOutputStream.java index 03c3dc968..c9a9d86cf 100644 --- a/src/main/org/apache/tools/tar/TarOutputStream.java +++ b/src/main/org/apache/tools/tar/TarOutputStream.java @@ -43,8 +43,8 @@ public class TarOutputStream extends FilterOutputStream { public static final int LONGFILE_GNU = 2; protected boolean debug; - protected int currSize; - protected int currBytes; + protected long currSize; + protected long currBytes; protected byte[] oneBuf; protected byte[] recordBuf; protected int assemLen; @@ -189,7 +189,7 @@ public class TarOutputStream extends FilterOutputStream { if (entry.isDirectory()) { this.currSize = 0; } else { - this.currSize = (int) entry.getSize(); + this.currSize = entry.getSize(); } }