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/13 21:50:06 UTC
(commons-compress) 06/06: org.apache.commons.compress.archivers.sevenz.SevenZFile now throws an ArchiveException if a result overflows a long (or an int, depending on the context)
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 40780cfe0a773abc1bb5195318604e8d4eeacc7c
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Wed Aug 13 17:45:42 2025 -0400
org.apache.commons.compress.archivers.sevenz.SevenZFile now throws an
ArchiveException if a result overflows a long (or an int, depending on
the context)
---
.../org/apache/commons/compress/archivers/sevenz/SevenZFile.java | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
index d5c59f03e..0fe7121cb 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
@@ -1233,6 +1233,7 @@ private void readArchiveProperties(final ByteBuffer input) throws IOException {
long nid = readUint64(input);
while (nid != NID.kEnd) {
final int propertySize = readUint64ToIntExact(input);
+ MemoryLimitException.checkKiB(bytesToKiB(propertySize), maxMemoryLimitKiB);
final byte[] property = new byte[propertySize];
get(input, property);
nid = readUint64(input);
@@ -1326,6 +1327,7 @@ private void readFilesInfo(final ByteBuffer header, final Archive archive) throw
}
case NID.kName: {
/* final int external = */ getUnsignedByte(header);
+ MemoryLimitException.checkKiB(bytesToKiB(size - 1), maxMemoryLimitKiB);
final byte[] names = new byte[ArchiveException.toIntExact(size - 1)];
final int namesLength = names.length;
get(header, names);
@@ -1470,7 +1472,8 @@ private Folder readFolder(final ByteBuffer header) throws IOException {
byte[] properties = null;
if (hasAttributes) {
final long propertiesSize = readUint64(header);
- properties = new byte[(int) propertiesSize];
+ MemoryLimitException.checkKiB(bytesToKiB(propertiesSize), maxMemoryLimitKiB);
+ properties = new byte[ArchiveException.toIntExact(propertiesSize)];
get(header, properties);
}
// would need to keep looping as above: