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 2025/08/04 18:19:58 UTC
(commons-compress) branch master updated (50dd50ec6 -> 08856525b)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
from 50dd50ec6 org.apache.commons.compress.harmony.unpack200.BandSet now throws ArchiveException instead of Arithmetic exception
new 94a33771a org.apache.commons.compress.harmony.pack200.FileBands now throws ArchiveException instead of Arithmetic exception
new 08856525b org.apache.commons.compress.archivers.cpio.CpioArchiveEntry now throws ArchiveException instead of Arithmetic exception
The 2 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 | 5 ++++-
.../apache/commons/compress/archivers/ArchiveException.java | 8 ++++++--
.../commons/compress/archivers/cpio/CpioArchiveEntry.java | 13 ++++++++-----
.../apache/commons/compress/harmony/pack200/FileBands.java | 11 ++++-------
.../compress/archivers/cpio/CpioArchiveEntryTest.java | 5 ++++-
5 files changed, 26 insertions(+), 16 deletions(-)
(commons-compress) 01/02: org.apache.commons.compress.harmony.pack200.FileBands now throws ArchiveException instead of Arithmetic exception
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 94a33771a468173a50103baa9d8aafb0c698ee31
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Mon Aug 4 14:09:05 2025 -0400
org.apache.commons.compress.harmony.pack200.FileBands now throws
ArchiveException instead of Arithmetic exception
---
src/changes/changes.xml | 1 +
.../apache/commons/compress/harmony/pack200/FileBands.java | 11 ++++-------
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1c80e03d4..1dd800a28 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -69,6 +69,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.pack200.BHSDCodec now throws ArchiveException instead of Arithmetic exception.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.archivers.zip.ExplodingInputStream now throws ArchiveException instead of Arithmetic exception.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.pack200.RunCodec now throws ArchiveException instead of Arithmetic exception.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.pack200.FileBands now throws ArchiveException instead of Arithmetic exception.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.MemoryLimitException.MemoryLimitException(long, long).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.CompressException.CompressException(String, Object...).</action>
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/FileBands.java b/src/main/java/org/apache/commons/compress/harmony/pack200/FileBands.java
index 5214a068a..73487cca2 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/FileBands.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/FileBands.java
@@ -26,9 +26,9 @@
import java.util.Set;
import java.util.TimeZone;
+import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.harmony.pack200.Archive.PackingFile;
import org.apache.commons.compress.harmony.pack200.Archive.SegmentUnit;
-import org.apache.commons.compress.utils.ExactMath;
import org.objectweb.asm.ClassReader;
/**
@@ -47,7 +47,8 @@ public class FileBands extends BandSet {
private final PackingOptions options;
private final CpBands cpBands;
- public FileBands(final CpBands cpBands, final SegmentHeader segmentHeader, final PackingOptions options, final SegmentUnit segmentUnit, final int effort) {
+ public FileBands(final CpBands cpBands, final SegmentHeader segmentHeader, final PackingOptions options, final SegmentUnit segmentUnit, final int effort)
+ throws ArchiveException {
super(effort, segmentHeader);
fileList = segmentUnit.getFileList();
this.options = options;
@@ -60,7 +61,6 @@ public FileBands(final CpBands cpBands, final SegmentHeader segmentHeader, final
int totalSize = 0;
file_bits = new byte[size][];
final int archiveModtime = segmentHeader.getArchive_modtime();
-
final Set<String> classNames = new HashSet<>();
for (final ClassReader reader : segmentUnit.getClassList()) {
classNames.add(reader.getClassName());
@@ -88,18 +88,15 @@ public FileBands(final CpBands cpBands, final SegmentHeader segmentHeader, final
}
final byte[] bytes = packingFile.getContents();
file_size[i] = bytes.length;
- totalSize = ExactMath.add(totalSize, file_size[i]);
-
+ totalSize = ArchiveException.addExact(totalSize, file_size[i]);
// update modification time
modtime = (packingFile.getModtime() + TimeZone.getDefault().getRawOffset()) / 1000L;
file_modtime[i] = (int) (modtime - archiveModtime);
if (isLatest && latestModtime < file_modtime[i]) {
latestModtime = file_modtime[i];
}
-
file_bits[i] = packingFile.getContents();
}
-
if (isLatest) {
Arrays.fill(file_modtime, latestModtime);
}
(commons-compress) 02/02: org.apache.commons.compress.archivers.cpio.CpioArchiveEntry now throws ArchiveException instead of Arithmetic exception
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit 08856525bec4bba25f45db450c7ab363dc25c91e
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Mon Aug 4 14:19:53 2025 -0400
org.apache.commons.compress.archivers.cpio.CpioArchiveEntry now throws
ArchiveException instead of Arithmetic exception
---
src/changes/changes.xml | 4 +++-
.../apache/commons/compress/archivers/ArchiveException.java | 8 ++++++--
.../commons/compress/archivers/cpio/CpioArchiveEntry.java | 13 ++++++++-----
.../compress/archivers/cpio/CpioArchiveEntryTest.java | 5 ++++-
4 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 1dd800a28..6d915d6c7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -70,6 +70,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.archivers.zip.ExplodingInputStream now throws ArchiveException instead of Arithmetic exception.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.pack200.RunCodec now throws ArchiveException instead of Arithmetic exception.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.harmony.pack200.FileBands now throws ArchiveException instead of Arithmetic exception.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.commons.compress.archivers.cpio.CpioArchiveEntry now throws ArchiveException instead of Arithmetic exception.</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.MemoryLimitException.MemoryLimitException(long, long).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.CompressException.CompressException(String, Object...).</action>
@@ -78,8 +79,9 @@ The <action> type attribute can be add,update,fix,remove.
<action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.harmony.pack200.Pack200Exception.Pack200Exception(String, Object...).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.MemoryLimitException.checkBytes(int, long).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.MemoryLimitException.checkKiB(long, long).</action>
- <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.archivers.ArchiveException.addExact(long, long).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.archivers.ArchiveException.addExact(int, int).</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.archivers.ArchiveException.addExact(int, long).</action>
+ <action type="add" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.compress.archivers.ArchiveException.addExact(long, long).</action>
<!-- UPDATE -->
</release>
<release version="1.28.0" date="2025-07-26" description="This is a feature and maintenance release. Java 8 or later is required.">
diff --git a/src/main/java/org/apache/commons/compress/archivers/ArchiveException.java b/src/main/java/org/apache/commons/compress/archivers/ArchiveException.java
index 8fdff7d1f..0d7db4738 100644
--- a/src/main/java/org/apache/commons/compress/archivers/ArchiveException.java
+++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveException.java
@@ -54,12 +54,16 @@ public static int addExact(final int x, final int y) throws ArchiveException {
* @param x the first value.
* @param y the second value.
* @return the result.
- * @throws ArchiveException if the result overflows an {@code int}.
+ * @throws ArchiveException if the result or input overflows an {@code int}.
* @see Math#addExact(int, int)
* @since 1.29.0
*/
public static int addExact(final int x, final long y) throws ArchiveException {
- return addExact(x, Math.toIntExact(y));
+ try {
+ return Math.addExact(x, Math.toIntExact(y));
+ } catch (final ArithmeticException e) {
+ throw new ArchiveException(e);
+ }
}
/**
diff --git a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
index 7acf75601..f809d6951 100644
--- a/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
+++ b/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
@@ -29,7 +29,7 @@
import java.util.Objects;
import org.apache.commons.compress.archivers.ArchiveEntry;
-import org.apache.commons.compress.utils.ExactMath;
+import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.io.file.attribute.FileTimes;
/**
@@ -524,9 +524,10 @@ public long getGID() {
* @deprecated This method doesn't properly work for multi-byte encodings. And creates corrupt archives. Use {@link #getHeaderPadCount(Charset)} or
* {@link #getHeaderPadCount(long)} in any case.
* @return the number of bytes needed to pad the header (0,1,2,3)
+ * @throws ArchiveException if a computation overflows an {@code int}.
*/
@Deprecated
- public int getHeaderPadCount() {
+ public int getHeaderPadCount() throws ArchiveException {
return getHeaderPadCount(null);
}
@@ -535,9 +536,10 @@ public int getHeaderPadCount() {
*
* @param charset The character set used to encode the entry name in the stream.
* @return the number of bytes needed to pad the header (0,1,2,3)
+ * @throws ArchiveException if a computation overflows an {@code int}.
* @since 1.18
*/
- public int getHeaderPadCount(final Charset charset) {
+ public int getHeaderPadCount(final Charset charset) throws ArchiveException {
if (name == null) {
return 0;
}
@@ -552,15 +554,16 @@ public int getHeaderPadCount(final Charset charset) {
*
* @param nameSize The length of the name in bytes, as read in the stream. Without the trailing zero byte.
* @return the number of bytes needed to pad the header (0,1,2,3)
+ * @throws ArchiveException if a computation overflows an {@code int}.
* @since 1.18
*/
- public int getHeaderPadCount(final long nameSize) {
+ public int getHeaderPadCount(final long nameSize) throws ArchiveException {
if (this.alignmentBoundary == 0) {
return 0;
}
int size = this.headerSize + 1; // Name has terminating null
if (name != null) {
- size = ExactMath.add(size, nameSize);
+ size = ArchiveException.addExact(size, nameSize);
}
final int remain = size % this.alignmentBoundary;
if (remain > 0) {
diff --git a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntryTest.java b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntryTest.java
index 05a4d8400..df6ad6910 100644
--- a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntryTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntryTest.java
@@ -16,17 +16,20 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.commons.compress.archivers.cpio;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import org.apache.commons.compress.archivers.ArchiveException;
import org.junit.jupiter.api.Test;
class CpioArchiveEntryTest {
+
@Test
void testGetHeaderPadCountOverflow() throws Exception {
final CpioArchiveEntry entry = new CpioArchiveEntry(CpioConstants.FORMAT_NEW);
entry.setName("test name");
- assertThrows(IllegalArgumentException.class, () -> entry.getHeaderPadCount(Long.MAX_VALUE));
+ assertThrows(ArchiveException.class, () -> entry.getHeaderPadCount(Long.MAX_VALUE));
}
}