You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2026/08/10 22:39:51 UTC

(commons-compress) branch master updated (daf142e96 -> 571208f7b)

This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


    from daf142e96 TapeInputStream now throws ArchiveException instead of IllegalArgumentException.
     new ba58ca98b TarArchiveInputStream now throws ArchiveException instead of IllegalArgumentException.
     new ed7b72a5a Internal TAR methods now throws ArchiveException instead of IllegalArgumentException.
     new 571208f7b TarUtils now throws ArchiveException instead of IllegalArgumentException.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |  6 ++-
 .../compress/archivers/tar/TarArchiveEntry.java    |  9 ++--
 .../archivers/tar/TarArchiveInputStream.java       | 10 ++--
 .../commons/compress/archivers/tar/TarUtils.java   | 60 ++++++++++++----------
 .../apache/commons/compress/archivers/TarTest.java | 14 +++--
 .../archivers/tar/TarArchiveInputStreamTest.java   |  2 +-
 .../compress/archivers/tar/TarUtilsTest.java       | 50 +++++++++---------
 7 files changed, 77 insertions(+), 74 deletions(-)


(commons-compress) 01/03: TarArchiveInputStream now throws ArchiveException instead of IllegalArgumentException.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit ba58ca98b62be6e20e0de7bae4d4e98c08aea999
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Aug 10 18:17:24 2026 -0400

    TarArchiveInputStream now throws ArchiveException instead of
    IllegalArgumentException.
---
 src/changes/changes.xml                                        |  5 +++--
 .../commons/compress/archivers/tar/TarArchiveInputStream.java  | 10 ++++------
 .../compress/archivers/tar/TarArchiveInputStreamTest.java      |  2 +-
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index dc99f81ce..328054d3a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -92,7 +92,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="KALI 834X, Gary Gregory">Reject negative ZIP64 offsets in positionAtCentralDirectory64 (#794).</action>
       <!-- FIX TAR -->
       <action type="fix" dev="pkarwasz" due-to="Tyler Nighswander, Piotr P. Karwasz, Gary Gregory">>Uniform handling of special tar records in TarFile and TarArchiveInputStream.</action>
-      <action type="fix" dev="ggregory" due-to="Gary Gregory, Stanislav Fort">TarArchiveOutputStream now throws a IllegalArgumentException instead of an OutOfMemoryError.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory, Stanislav Fort">TarArchiveOutputStream now throws a ArchiveException instead of an OutOfMemoryError.</action>
       <action type="fix" dev="ggregory" issue="COMPRESS-707" due-to="Gary Gregory, Roel van Dijk">TarUtils.verifyCheckSum() throws an Exception when checksum could not be parsed.</action>
       <action type="fix" dev="ggregory" issue="COMPRESS-724" due-to="Ruiqi Dong, Gary Gregory">TarUtils.parsePAX1XSparseHeaders(InputStream, int) skips an extra record when sparse headers are already record-aligned.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory, KALI 834X">Reject tar sparse blocks larger than the entry size (#780).</action>
@@ -104,7 +104,8 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary Gregory">TarArchiveEntry.setSize(long) now throw ArchiveException instead of IllegalArgumentException.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">TarArchiveEntry.addPaxHeader(String, String) now throws ArchiveException instead of IllegalArgumentException.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">TAR ParsingUtils now throws the IOException subclass CompressException.</action>
-      <action type="fix" dev="ggregory" due-to="Gary Gregory">TarArchiveOutputStream now throws ArchiveException instead of IllegalArgumentException..</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">TarArchiveOutputStream now throws ArchiveException instead of IllegalArgumentException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">TarArchiveInputStream now throws ArchiveException instead of IllegalArgumentException.</action>
       <!-- FIX ar -->
       <action type="fix" dev="ggregory" due-to="Gary Gregory">ArArchiveInputStream.readGNUStringTable(byte[], int, int) now provides a better exception message, wrapping the underlying exception.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">ArArchiveInputStream.read(byte[], int, int) now throws ArchiveException instead of ArithmeticException.</action>
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
index d01a80060..7607d5ccf 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
@@ -668,9 +668,8 @@ public int read(final byte[] buf, final int offset, final int numToRead) throws
         if (isAtEOF() || isDirectory()) {
             return -1;
         }
-        if (currEntry == null || currentInputStream == null) {
-            throw new IllegalStateException("No current tar entry");
-        }
+        ArchiveException.requireNonNull(currEntry, "No current tar entry (null currEntry)");
+        ArchiveException.requireNonNull(currentInputStream, "No current tar entry (null currentInputStream)");
         return currentInputStream.read(buf, offset, numToRead);
     }
 
@@ -746,9 +745,8 @@ public long skip(final long n) throws IOException {
         if (n <= 0 || isDirectory()) {
             return 0;
         }
-        if (currEntry == null || currentInputStream == null) {
-            throw new IllegalStateException("No current tar entry");
-        }
+        ArchiveException.requireNonNull(currEntry, "No current tar entry (null currEntry)");
+        ArchiveException.requireNonNull(currentInputStream, "No current tar entry (null currentInputStream)");
         // Use Apache Commons IO to skip as it handles skipping fully
         return IOUtils.skip(currentInputStream, n);
     }
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
index c293a53f6..896e31e7e 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
@@ -285,7 +285,7 @@ void testGetAndSetOfPaxEntry() throws Exception {
             assertEquals(entry, is.getCurrentEntry());
             assertNotSame(entry, is.getCurrentEntry());
             assertSame(weaselEntry, is.getCurrentEntry());
-            assertThrows(IllegalStateException.class, () -> {
+            assertThrows(ArchiveException.class, () -> {
                 is.setCurrentEntry(null);
                 is.read();
             }, "should abort because current entry is nulled");


(commons-compress) 02/03: Internal TAR methods now throws ArchiveException instead of IllegalArgumentException.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit ed7b72a5ad6ac280f72f5c538397cc5580c1f225
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Aug 10 18:27:42 2026 -0400

    Internal TAR methods now throws ArchiveException instead of
    IllegalArgumentException.
---
 .../compress/archivers/tar/TarArchiveEntry.java    |  5 ++--
 .../commons/compress/archivers/tar/TarUtils.java   | 32 ++++++++++++----------
 .../compress/archivers/tar/TarUtilsTest.java       | 24 ++++++++--------
 3 files changed, 32 insertions(+), 29 deletions(-)

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 ecbb79ee0..8a8114551 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
@@ -2069,7 +2069,8 @@ public void writeEntryHeader(final byte[] outbuf, final ZipEncoding encoding, fi
         TarUtils.formatCheckSumOctalBytes(chk, outbuf, csOffset, CHKSUMLEN);
     }
 
-    private int writeEntryHeaderField(final long value, final byte[] outbuf, final int offset, final int length, final boolean starMode) {
+    private int writeEntryHeaderField(final long value, final byte[] outbuf, final int offset, final int length, final boolean starMode)
+            throws ArchiveException {
         if (!starMode && (value < 0 || value >= 1L << 3 * (length - 1))) {
             // value doesn't fit into field when written as octal
             // number, will be written to PAX header or causes an
@@ -2079,7 +2080,7 @@ private int writeEntryHeaderField(final long value, final byte[] outbuf, final i
         return TarUtils.formatLongOctalOrBinaryBytes(value, outbuf, offset, length);
     }
 
-    private int writeEntryHeaderOptionalTimeField(final FileTime time, int offset, final byte[] outbuf, final int fieldLength) {
+    private int writeEntryHeaderOptionalTimeField(final FileTime time, int offset, final byte[] outbuf, final int fieldLength) throws ArchiveException {
         if (time != null) {
             offset = writeEntryHeaderField(FileTimes.toUnixTime(time), outbuf, offset, fieldLength, true);
         } else {
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
index b98cefb5d..6d329c00e 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
@@ -150,12 +150,13 @@ private static String exceptionMessage(final byte[] buffer, final int offset, fi
         return "Invalid byte " + currentByte + " at offset " + (current - offset) + " in '" + string + "' len=" + length;
     }
 
-    private static void formatBigIntegerBinary(final long value, final byte[] buf, final int offset, final int length, final boolean negative) {
+    private static void formatBigIntegerBinary(final long value, final byte[] buf, final int offset, final int length, final boolean negative)
+            throws ArchiveException {
         final BigInteger val = BigInteger.valueOf(value);
         final byte[] b = val.toByteArray();
         final int len = b.length;
         if (len > length - 1) {
-            throw new IllegalArgumentException("Value " + value + " is too large for " + length + " byte field.");
+            throw new ArchiveException("Value " + value + " is too large for " + length + " byte field.");
         }
         final int off = offset + length - len;
         System.arraycopy(b, 0, buf, off, len);
@@ -173,9 +174,9 @@ private static void formatBigIntegerBinary(final long value, final byte[] buf, f
      * @param offset The starting offset into the buffer.
      * @param length The size of the buffer.
      * @return The updated value of offset, i.e. offset+length.
-     * @throws IllegalArgumentException if the value (and trailer) will not fit in the buffer.
+     * @throws ArchiveException if the value (and trailer) will not fit in the buffer.
      */
-    public static int formatCheckSumOctalBytes(final long value, final byte[] buf, final int offset, final int length) {
+    public static int formatCheckSumOctalBytes(final long value, final byte[] buf, final int offset, final int length) throws ArchiveException {
         int idx = length - 2; // for NUL and space
         formatUnsignedOctalString(value, buf, offset, idx);
         buf[offset + idx++] = 0; // Trailing null
@@ -183,12 +184,13 @@ public static int formatCheckSumOctalBytes(final long value, final byte[] buf, f
         return offset + length;
     }
 
-    private static void formatLongBinary(final long value, final byte[] buf, final int offset, final int length, final boolean negative) {
+    private static void formatLongBinary(final long value, final byte[] buf, final int offset, final int length, final boolean negative)
+            throws ArchiveException {
         final int bits = (length - 1) * 8;
         final long max = 1L << bits;
         long val = Math.abs(value); // Long.MIN_VALUE stays Long.MIN_VALUE
         if (val < 0 || val >= max) {
-            throw new IllegalArgumentException("Value " + value + " is too large for " + length + " byte field.");
+            throw new ArchiveException("Value " + value + " is too large for " + length + " byte field.");
         }
         if (negative) {
             val ^= max - 1;
@@ -211,9 +213,9 @@ private static void formatLongBinary(final long value, final byte[] buf, final i
      * @param offset The starting offset into the buffer.
      * @param length The length of the buffer.
      * @return The updated offset.
-     * @throws IllegalArgumentException if the value (and trailer) will not fit in the buffer.
+     * @throws ArchiveException if the value (and trailer) will not fit in the buffer.
      */
-    public static int formatLongOctalBytes(final long value, final byte[] buf, final int offset, final int length) {
+    public static int formatLongOctalBytes(final long value, final byte[] buf, final int offset, final int length) throws ArchiveException {
         final int idx = length - 1; // For space
         formatUnsignedOctalString(value, buf, offset, idx);
         buf[offset + idx] = (byte) SP; // Trailing space
@@ -230,10 +232,10 @@ public static int formatLongOctalBytes(final long value, final byte[] buf, final
      * @param offset The starting offset into the buffer.
      * @param length The length of the buffer.
      * @return The updated offset.
-     * @throws IllegalArgumentException if the value (and trailer) will not fit in the buffer.
+     * @throws ArchiveException if the value (and trailer) will not fit in the buffer.
      * @since 1.4
      */
-    public static int formatLongOctalOrBinaryBytes(final long value, final byte[] buf, final int offset, final int length) {
+    public static int formatLongOctalOrBinaryBytes(final long value, final byte[] buf, final int offset, final int length) throws ArchiveException {
         // Check whether we are dealing with UID/GID or SIZE field
         final long maxAsOctalChar = length == TarConstants.UIDLEN ? TarConstants.MAXID : TarConstants.MAXSIZE;
         final boolean negative = value < 0;
@@ -308,9 +310,9 @@ public static int formatNameBytes(final String name, final byte[] buf, final int
      * @param offset The starting offset into the buffer.
      * @param length The size of the output buffer.
      * @return The updated offset, i.e. offset+length.
-     * @throws IllegalArgumentException if the value (and trailer) will not fit in the buffer.
+     * @throws ArchiveException if the value (and trailer) will not fit in the buffer.
      */
-    public static int formatOctalBytes(final long value, final byte[] buf, final int offset, final int length) {
+    public static int formatOctalBytes(final long value, final byte[] buf, final int offset, final int length) throws ArchiveException {
         int idx = length - 2; // For space and trailing null
         formatUnsignedOctalString(value, buf, offset, idx);
         buf[offset + idx++] = (byte) SP; // Trailing space
@@ -325,9 +327,9 @@ public static int formatOctalBytes(final long value, final byte[] buf, final int
      * @param buffer destination buffer.
      * @param offset starting offset in buffer.
      * @param length length of buffer to fill.
-     * @throws IllegalArgumentException if the value will not fit in the buffer.
+     * @throws ArchiveException if the value will not fit in the buffer.
      */
-    public static void formatUnsignedOctalString(final long value, final byte[] buffer, final int offset, final int length) {
+    public static void formatUnsignedOctalString(final long value, final byte[] buffer, final int offset, final int length) throws ArchiveException {
         int remaining = length;
         remaining--;
         if (value == 0) {
@@ -341,7 +343,7 @@ public static void formatUnsignedOctalString(final long value, final byte[] buff
                 // CheckStyle:MagicNumber ON
             }
             if (val != 0) {
-                throw new IllegalArgumentException(value + "=" + Long.toOctalString(value) + " will not fit in octal number buffer of length " + length);
+                throw new ArchiveException(value + "=" + Long.toOctalString(value) + " will not fit in octal number buffer of length " + length);
             }
         }
         for (; remaining >= 0; --remaining) { // leading zeros
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
index 2ef512fa4..351d0586b 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
@@ -184,18 +184,18 @@ private void checkName(final String string) {
         assertEquals(string, TarUtils.parseName(buff, 0, len));
     }
 
-    private void checkRoundTripOctal(final long value) {
+    private void checkRoundTripOctal(final long value) throws ArchiveException {
         checkRoundTripOctal(value, TarConstants.SIZELEN);
     }
 
-    private void checkRoundTripOctal(final long value, final int bufsize) {
+    private void checkRoundTripOctal(final long value, final int bufsize) throws ArchiveException {
         final byte[] buffer = new byte[bufsize];
         TarUtils.formatLongOctalBytes(value, buffer, 0, buffer.length);
         final long parseValue = TarUtils.parseOctal(buffer, 0, buffer.length);
         assertEquals(value, parseValue);
     }
 
-    private void checkRoundTripOctalOrBinary(final long value, final int bufsize) {
+    private void checkRoundTripOctalOrBinary(final long value, final int bufsize) throws ArchiveException {
         final byte[] buffer = new byte[bufsize];
         TarUtils.formatLongOctalOrBinaryBytes(value, buffer, 0, buffer.length);
         final long parseValue = TarUtils.parseOctalOrBinary(buffer, 0, buffer.length);
@@ -223,18 +223,18 @@ void testName() {
     }
 
     @Test
-    void testNegative() {
+    void testNegative() throws ArchiveException {
         final byte[] buffer = new byte[22];
         TarUtils.formatUnsignedOctalString(-1, buffer, 0, buffer.length);
         assertEquals("1777777777777777777777", new String(buffer, UTF_8));
     }
 
     @Test
-    void testOverflow() {
+    void testOverflow() throws ArchiveException {
         final byte[] buffer = new byte[8 - 1]; // a lot of the numbers have 8-byte buffers (nul term)
         TarUtils.formatUnsignedOctalString(07777777L, buffer, 0, buffer.length);
         assertEquals("7777777", new String(buffer, UTF_8));
-        assertThrows(IllegalArgumentException.class, () -> TarUtils.formatUnsignedOctalString(017777777L, buffer, 0, buffer.length),
+        assertThrows(ArchiveException.class, () -> TarUtils.formatUnsignedOctalString(017777777L, buffer, 0, buffer.length),
                 "Should have cause IllegalArgumentException");
     }
 
@@ -640,7 +640,7 @@ void testRoundTripNames() {
     }
 
     @Test
-    void testRoundTripOctal() {
+    void testRoundTripOctal() throws ArchiveException {
         checkRoundTripOctal(0);
         checkRoundTripOctal(1);
 //        checkRoundTripOctal(-1); // TODO What should this do?
@@ -652,7 +652,7 @@ void testRoundTripOctal() {
         checkRoundTripOctal(TarConstants.MAXID, 8);
     }
 
-    private void testRoundTripOctalOrBinary(final int length) {
+    private void testRoundTripOctalOrBinary(final int length) throws ArchiveException {
         checkRoundTripOctalOrBinary(0, length);
         checkRoundTripOctalOrBinary(1, length);
         checkRoundTripOctalOrBinary(TarConstants.MAXSIZE, length); // will need binary format
@@ -662,20 +662,20 @@ private void testRoundTripOctalOrBinary(final int length) {
     }
 
     @Test
-    void testRoundTripOctalOrBinary12() {
+    void testRoundTripOctalOrBinary12() throws ArchiveException {
         testRoundTripOctalOrBinary(12);
         checkRoundTripOctalOrBinary(Long.MAX_VALUE, 12);
         checkRoundTripOctalOrBinary(Long.MIN_VALUE + 1, 12);
     }
 
     @Test
-    void testRoundTripOctalOrBinary8() {
+    void testRoundTripOctalOrBinary8() throws ArchiveException {
         testRoundTripOctalOrBinary(8);
     }
 
     @Test
     void testRoundTripOctalOrBinary8_ValueTooBigForBinary() {
-        final IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> checkRoundTripOctalOrBinary(Long.MAX_VALUE, 8),
+        final ArchiveException e = assertThrows(ArchiveException.class, () -> checkRoundTripOctalOrBinary(Long.MAX_VALUE, 8),
                 "Should throw exception - value is too long to fit buffer of this len");
         assertEquals("Value 9223372036854775807 is too large for 8 byte field.", e.getMessage());
     }
@@ -690,7 +690,7 @@ void testSecondEntryWinsWhenPaxHeaderContainsDuplicateKey() throws Exception {
 
     // Check correct trailing bytes are generated
     @Test
-    void testTrailers() {
+    void testTrailers() throws ArchiveException {
         final byte[] buffer = new byte[12];
         TarUtils.formatLongOctalBytes(123, buffer, 0, buffer.length);
         assertEquals(' ', buffer[buffer.length - 1]);


(commons-compress) 03/03: TarUtils now throws ArchiveException instead of IllegalArgumentException.

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git

commit 571208f7b594b95c9c7680ac6dfc5799b5232084
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Aug 10 18:39:44 2026 -0400

    TarUtils now throws ArchiveException instead of
    IllegalArgumentException.
---
 src/changes/changes.xml                            |  1 +
 .../compress/archivers/tar/TarArchiveEntry.java    |  4 ++--
 .../commons/compress/archivers/tar/TarUtils.java   | 28 ++++++++++++----------
 .../apache/commons/compress/archivers/TarTest.java | 14 +++++------
 .../compress/archivers/tar/TarUtilsTest.java       | 26 ++++++++++----------
 5 files changed, 37 insertions(+), 36 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 328054d3a..34c494af4 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -106,6 +106,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary Gregory">TAR ParsingUtils now throws the IOException subclass CompressException.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">TarArchiveOutputStream now throws ArchiveException instead of IllegalArgumentException.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">TarArchiveInputStream now throws ArchiveException instead of IllegalArgumentException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">TarUtils now throws ArchiveException instead of IllegalArgumentException.</action>
       <!-- FIX ar -->
       <action type="fix" dev="ggregory" due-to="Gary Gregory">ArArchiveInputStream.readGNUStringTable(byte[], int, int) now provides a better exception message, wrapping the underlying exception.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">ArArchiveInputStream.read(byte[], int, int) now throws ArchiveException instead of ArithmeticException.</action>
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 8a8114551..5d7442eb2 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
@@ -298,11 +298,11 @@ private static Instant parseInstantFromDecimalSeconds(final String value) throws
         }
     }
 
-    private static long parseOctalOrBinary(final byte[] header, final int offset, final int length, final boolean lenient) {
+    private static long parseOctalOrBinary(final byte[] header, final int offset, final int length, final boolean lenient) throws ArchiveException {
         if (lenient) {
             try {
                 return TarUtils.parseOctalOrBinary(header, offset, length);
-            } catch (final IllegalArgumentException ex) { // NOSONAR
+            } catch (final ArchiveException ex) { // NOSONAR
                 return UNKNOWN;
             }
         }
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
index 6d329c00e..78132cc90 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java
@@ -420,7 +420,7 @@ static boolean isSpecialTarRecord(final TarArchiveEntry entry) {
         return entry.isGNULongLinkEntry() || entry.isGNULongNameEntry() || entry.isGlobalPaxHeader() || entry.isPaxHeader();
     }
 
-    private static long parseBinaryBigInteger(final byte[] buffer, final int offset, final int length, final boolean negative) {
+    private static long parseBinaryBigInteger(final byte[] buffer, final int offset, final int length, final boolean negative) throws ArchiveException {
         final byte[] remainder = new byte[length - 1];
         System.arraycopy(buffer, offset + 1, remainder, 0, length - 1);
         BigInteger val = new BigInteger(remainder);
@@ -429,14 +429,14 @@ private static long parseBinaryBigInteger(final byte[] buffer, final int offset,
             val = val.add(NEG_1_BIG_INT).not();
         }
         if (val.bitLength() > 63) {
-            throw new IllegalArgumentException("At offset " + offset + ", " + length + " byte binary number exceeds maximum signed long value");
+            throw new ArchiveException("At offset " + offset + ", " + length + " byte binary number exceeds maximum signed long value");
         }
         return negative ? -val.longValue() : val.longValue();
     }
 
-    private static long parseBinaryLong(final byte[] buffer, final int offset, final int length, final boolean negative) {
+    private static long parseBinaryLong(final byte[] buffer, final int offset, final int length, final boolean negative) throws ArchiveException {
         if (length >= 9) {
-            throw new IllegalArgumentException("At offset " + offset + ", " + length + " byte binary number exceeds maximum signed long value");
+            throw new ArchiveException("At offset " + offset + ", " + length + " byte binary number exceeds maximum signed long value");
         }
         long val = 0;
         for (int i = 1; i < length; i++) {
@@ -548,18 +548,18 @@ public static String parseName(final byte[] buffer, final int offset, final int
      * @param offset The offset into the buffer from which to parse.
      * @param length The maximum number of bytes to parse - must be at least 2 bytes.
      * @return The long value of the octal string.
-     * @throws IllegalArgumentException if the trailing space/NUL is missing or if an invalid byte is detected.
+     * @throws ArchiveException if the trailing space/NUL is missing or if an invalid byte is detected.
      */
-    public static long parseOctal(final byte[] buffer, final int offset, final int length) {
+    public static long parseOctal(final byte[] buffer, final int offset, final int length) throws ArchiveException {
         return parseOctal(buffer, offset, length, "parseOctal()", false);
     }
 
-    static long parseOctal(final byte[] buffer, final int offset, final int length, final String context, final boolean lenient) {
+    static long parseOctal(final byte[] buffer, final int offset, final int length, final String context, final boolean lenient) throws ArchiveException {
         long result = 0;
         int end = offset + length;
         int start = offset;
         if (length < 2) {
-            throw new IllegalArgumentException(context + ": Length " + length + " must be at least 2");
+            throw new ArchiveException(context + ": Length " + length + " must be at least 2");
         }
         if (buffer[start] == 0) {
             return 0L;
@@ -587,7 +587,7 @@ static long parseOctal(final byte[] buffer, final int offset, final int length,
                     // When lenient, an early NUL ends the parsing (COMPRESS-707).
                     return result;
                 }
-                throw new IllegalArgumentException(context + ": " + exceptionMessage(buffer, offset, length, start, currentByte));
+                throw new ArchiveException(context + ": " + exceptionMessage(buffer, offset, length, start, currentByte));
             }
             result = (result << 3) + (currentByte - '0'); // convert from ASCII
         }
@@ -602,11 +602,11 @@ static long parseOctal(final byte[] buffer, final int offset, final int length,
      * @param offset The offset into the buffer from which to parse.
      * @param length The maximum number of bytes to parse.
      * @return The long value of the octal or binary string.
-     * @throws IllegalArgumentException if the trailing space/NUL is missing or an invalid byte is detected in an octal number, or if a binary number would
+     * @throws ArchiveException if the trailing space/NUL is missing or an invalid byte is detected in an octal number, or if a binary number would
      *                                  exceed the size of a signed long 64-bit integer.
      * @since 1.4
      */
-    public static long parseOctalOrBinary(final byte[] buffer, final int offset, final int length) {
+    public static long parseOctalOrBinary(final byte[] buffer, final int offset, final int length) throws ArchiveException {
         if ((buffer[offset] & 0x80) == 0) {
             return parseOctal(buffer, offset, length, "parseOctalOrBinary()", false);
         }
@@ -886,11 +886,12 @@ static List<TarArchiveStructSparse> readSparseStructs(final byte[] buffer, final
      *
      * @param header tar header.
      * @return whether the checksum is reasonably good.
+     * @throws ArchiveException Thrown on invalid input.
      * @see <a href="https://en.wikipedia.org/wiki/Tar_(computing)#File_header">TAR header</a>
      * @see <a href="https://issues.apache.org/jira/browse/COMPRESS-191">COMPRESS-191</a>
      * @since 1.5
      */
-    public static boolean verifyCheckSum(final byte[] header) {
+    public static boolean verifyCheckSum(final byte[] header) throws ArchiveException {
         return verifyCheckSum(header, false);
     }
 
@@ -909,11 +910,12 @@ public static boolean verifyCheckSum(final byte[] header) {
      * @param header tar header.
      * @param lenient Whether to allow out-of-spec formatting.
      * @return whether the checksum is reasonably good.
+     * @throws ArchiveException Thrown on invalid input.
      * @see <a href="https://en.wikipedia.org/wiki/Tar_(computing)#File_header">TAR header</a>
      * @see <a href="https://issues.apache.org/jira/browse/COMPRESS-191">COMPRESS-191</a>
      * @see <a href="https://issues.apache.org/jira/browse/COMPRESS-707">COMPRESS-707</a>
      */
-    static boolean verifyCheckSum(final byte[] header, final boolean lenient) {
+    static boolean verifyCheckSum(final byte[] header, final boolean lenient) throws ArchiveException {
         final long storedSum = parseOctal(header, TarConstants.CHKSUM_OFFSET, TarConstants.CHKSUMLEN, "verifyCheckSum()", lenient);
         long unsignedSum = 0;
         long signedSum = 0;
diff --git a/src/test/java/org/apache/commons/compress/archivers/TarTest.java b/src/test/java/org/apache/commons/compress/archivers/TarTest.java
index f80b05f32..1d6861d87 100644
--- a/src/test/java/org/apache/commons/compress/archivers/TarTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/TarTest.java
@@ -19,10 +19,10 @@
 package org.apache.commons.compress.archivers;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.junit.Assert.assertNull;
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertInstanceOf;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -86,9 +86,8 @@ void testCOMPRESS178() throws Exception {
         final File input = getFile("COMPRESS-178-fail.tar");
         try (InputStream is = Files.newInputStream(input.toPath());
                 ArchiveInputStream<?> in = ArchiveStreamFactory.DEFAULT.createArchiveInputStream("tar", is)) {
-            final IOException e = assertThrows(ArchiveException.class, in::getNextEntry, "Expected IOException");
-            final Throwable t = e.getCause();
-            assertInstanceOf(IllegalArgumentException.class, t, "Expected cause = IllegalArgumentException");
+            final ArchiveException e = assertThrows(ArchiveException.class, in::getNextEntry, "Expected IOException");
+            assertNull(e.getCause());
         }
     }
 
@@ -303,13 +302,12 @@ void testTarFileCOMPRESS114() throws Exception {
     @Test
     void testTarFileCOMPRESS178() throws Exception {
         final File input = getFile("COMPRESS-178-fail.tar");
-        final IOException e = assertThrows(ArchiveException.class, () -> {
+        final ArchiveException e = assertThrows(ArchiveException.class, () -> {
             try (TarFile tarFile = TarFile.builder().setFile(input).get()) {
                 // Compared to the TarArchiveInputStream all entries are read when instantiating the tar file
             }
-        }, "Expected IOException");
-        final Throwable t = e.getCause();
-        assertInstanceOf(IllegalArgumentException.class, t, "Expected cause = IllegalArgumentException");
+        });
+        assertNull(e.getCause());
     }
 
     @Test
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
index 351d0586b..326e406a0 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
@@ -278,7 +278,7 @@ void testParseFromPAX01SparseHeadersRejectsOddNumberOfEntries() throws Exception
     }
 
     @Test
-    void testParseOctal() {
+    void testParseOctal() throws ArchiveException {
         long value;
         byte[] buffer;
         final long MAX_OCTAL = 077777777777L; // Allowed 11 digits
@@ -305,7 +305,7 @@ void testParseOctal() {
     }
 
     @Test
-    void testParseOctalCompress330() {
+    void testParseOctalCompress330() throws ArchiveException {
         final long expected = 0100000;
         final byte[] buffer = { 32, 32, 32, 32, 32, 49, 48, 48, 48, 48, 48, 32 };
         assertEquals(expected, TarUtils.parseOctalOrBinary(buffer, 0, buffer.length));
@@ -314,25 +314,25 @@ void testParseOctalCompress330() {
     @Test
     void testParseOctalEmbeddedSpace() {
         final byte[] buffer4 = " 0 07 ".getBytes(UTF_8); // Invalid - embedded space
-        assertThrows(IllegalArgumentException.class, () -> TarUtils.parseOctal(buffer4, 0, buffer4.length),
+        assertThrows(ArchiveException.class, () -> TarUtils.parseOctal(buffer4, 0, buffer4.length),
                 "Expected IllegalArgumentException - embedded space");
     }
 
     @Test
     void testParseOctalInvalid() {
         final byte[] buffer1 = ArrayUtils.EMPTY_BYTE_ARRAY;
-        assertThrows(IllegalArgumentException.class, () -> TarUtils.parseOctal(buffer1, 0, buffer1.length),
-                "Expected IllegalArgumentException - should be at least 2 bytes long");
+        assertThrows(ArchiveException.class, () -> TarUtils.parseOctal(buffer1, 0, buffer1.length),
+                "Expected ArchiveException - should be at least 2 bytes long");
 
         final byte[] buffer2 = { 0 }; // 1-byte array
-        assertThrows(IllegalArgumentException.class, () -> TarUtils.parseOctal(buffer2, 0, buffer2.length),
-                "Expected IllegalArgumentException - should be at least 2 bytes long");
+        assertThrows(ArchiveException.class, () -> TarUtils.parseOctal(buffer2, 0, buffer2.length),
+                "Expected ArchiveException - should be at least 2 bytes long");
 
         final byte[] buffer3 = "abcdef ".getBytes(UTF_8); // Invalid input
-        assertThrows(IllegalArgumentException.class, () -> TarUtils.parseOctal(buffer3, 0, buffer3.length), "Expected IllegalArgumentException");
+        assertThrows(ArchiveException.class, () -> TarUtils.parseOctal(buffer3, 0, buffer3.length), "Expected IllegalArgumentException");
 
         final byte[] buffer5 = " 0\00007 ".getBytes(UTF_8); // Invalid - embedded NUL
-        assertThrows(IllegalArgumentException.class, () -> TarUtils.parseOctal(buffer5, 0, buffer5.length), "Expected IllegalArgumentException - embedded NUL");
+        assertThrows(ArchiveException.class, () -> TarUtils.parseOctal(buffer5, 0, buffer5.length), "Expected IllegalArgumentException - embedded NUL");
     }
 
     @Test
@@ -502,14 +502,14 @@ void testReadLongNameThrowsOnTruncation(final long size) throws IOException {
     }
 
     @Test
-    void testReadNegativeBinary12Byte() {
+    void testReadNegativeBinary12Byte() throws ArchiveException {
         final byte[] b = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff,
                 (byte) 0xf1, (byte) 0xef, };
         assertEquals(-3601L, TarUtils.parseOctalOrBinary(b, 0, 12));
     }
 
     @Test
-    void testReadNegativeBinary8Byte() {
+    void testReadNegativeBinary8Byte() throws ArchiveException {
         final byte[] b = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xf1, (byte) 0xef, };
         assertEquals(-3601L, TarUtils.parseOctalOrBinary(b, 0, 8));
     }
@@ -707,7 +707,7 @@ void testTrailers() throws ArchiveException {
 
     // https://issues.apache.org/jira/browse/COMPRESS-191
     @Test
-    void testVerifyHeaderCheckSum() {
+    void testVerifyHeaderCheckSum() throws ArchiveException {
         final byte[] valid = { // from bla.tar
                 116, 101, 115, 116, 49, 46, 120, 109, 108, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -759,7 +759,7 @@ void testVerifyHeaderCheckSum() {
     }
 
     @Test
-    void testWriteNegativeBinary8Byte() {
+    void testWriteNegativeBinary8Byte() throws ArchiveException {
         final byte[] b = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xf1, (byte) 0xef, };
         assertEquals(-3601L, TarUtils.parseOctalOrBinary(b, 0, 8));
     }