This is an automated email from the ASF dual-hosted git repository.
bodewig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
The following commit(s) were added to refs/heads/master by this push:
new 67356a2 not really COMPRESS-529 also use IllegalArgumentException for
big numbers
67356a2 is described below
commit 67356a270ae9553e09dfd6b2ad8ae6e792b5a886
Author: Stefan Bodewig <[email protected]>
AuthorDate: Mon Jun 1 13:13:47 2020 +0200
not really COMPRESS-529 also use IllegalArgumentException for big numbers
---
src/changes/changes.xml | 5 +++++
.../commons/compress/archivers/tar/TarArchiveOutputStream.java | 8 +++++++-
.../compress/archivers/tar/TarArchiveOutputStreamTest.java | 9 +++++++++
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1c05cd1..96410ee 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -115,6 +115,11 @@ The <action> type attribute can be add,update,fix,remove.
Throw IllegalArgumentException instead of RuntimeExceptions if
the file name is longer than 100 bytes with the longFileMode
of LONGFILE_ERROR, and address this in java docs.
+
+ Throw IllegalArgumentException instead of RuntimeExceptions if
+ the any of the numeric values of an entry exceeds the limits
+ of a traditional tar header while bigNumberMode is
+ BIGNUMBER_ERROR, and address this in java docs.
</action>
</release>
<release version="1.20" date="2020-02-08"
diff --git
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
index 0816976..07b3e69 100644
---
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
+++
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
@@ -335,6 +335,12 @@ public class TarArchiveOutputStream extends
ArchiveOutputStream {
* @param archiveEntry The TarEntry to be written to the archive.
* @throws IOException on error
* @throws ClassCastException if archiveEntry is not an instance of
TarArchiveEntry
+ * @throws IllegalArgumentException if the {@link
TarArchiveOutputStream#longFileMode} equals
+ * {@link
TarArchiveOutputStream#LONGFILE_ERROR} and the file
+ * name is too long
+ * @throws IllegalArgumentException if the {@link
TarArchiveOutputStream#bigNumberMode} equals
+ * {@link TarArchiveOutputStream#BIGNUMBER_ERROR} and one of the
numeric values
+ * exceeds the limits of a traditional tar header.
*/
@Override
public void putArchiveEntry(final ArchiveEntry archiveEntry) throws
IOException {
@@ -633,7 +639,7 @@ public class TarArchiveOutputStream extends
ArchiveOutputStream {
private void failForBigNumber(final String field, final long value, final
long maxValue,
final String additionalMsg) {
if (value < 0 || value > maxValue) {
- throw new RuntimeException(field + " '" + value //NOSONAR
+ throw new IllegalArgumentException(field + " '" + value //NOSONAR
+ "' is too big ( > "
+ maxValue + " )." + additionalMsg);
}
diff --git
a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
index 71f49cd..2ee55ad 100644
---
a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
+++
b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
@@ -95,6 +95,15 @@ public class TarArchiveOutputStreamTest extends
AbstractTestCase {
}
}
+ @Test(expected = IllegalArgumentException.class)
+ public void testBigNumberErrorMode() throws Exception {
+ final TarArchiveEntry t = new TarArchiveEntry("foo");
+ t.setSize(0100000000000L);
+ final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ final TarArchiveOutputStream tos = new TarArchiveOutputStream(bos);
+ tos.putArchiveEntry(t);
+ }
+
@Test
public void testBigNumberStarMode() throws Exception {
final TarArchiveEntry t = new TarArchiveEntry("foo");