diff options
author | PJ Fanning <fanningpj@apache.org> | 2021-10-21 17:34:29 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2021-10-21 17:34:29 +0000 |
commit | 04c130b8d5d540f1cdfa553ddb1e55fbe532babd (patch) | |
tree | 872bf4da0c71e96675b175ef44f4f506fc887800 /poi/src | |
parent | dbc6576da49b02c5cfab100b99d48c449f445222 (diff) | |
download | poi-04c130b8d5d540f1cdfa553ddb1e55fbe532babd.tar.gz poi-04c130b8d5d540f1cdfa553ddb1e55fbe532babd.zip |
make max record sizes configurable
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894453 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi/src')
26 files changed, 409 insertions, 304 deletions
diff --git a/poi/src/main/java/org/apache/poi/ddf/EscherArrayProperty.java b/poi/src/main/java/org/apache/poi/ddf/EscherArrayProperty.java index f2c555496e..07731c97bb 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherArrayProperty.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherArrayProperty.java @@ -37,7 +37,8 @@ import org.apache.poi.util.Removal; public final class EscherArrayProperty extends EscherComplexProperty implements Iterable<byte[]> { // arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; + private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000; + private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; /** * The size of the header that goes at the start of the array, before the data @@ -55,6 +56,20 @@ public final class EscherArrayProperty extends EscherComplexProperty implements private final boolean emptyComplexPart; /** + * @param length the max record length allowed for EscherArrayProperty + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max record length allowed for EscherArrayProperty + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + + /** * Create an instance of an escher array property. * This constructor can be used to create emptyComplexParts with a complexSize = 0. * Preferably use {@link #EscherArrayProperty(EscherPropertyTypes, boolean, int)} with {@link #setComplexData(byte[])}. diff --git a/poi/src/main/java/org/apache/poi/ddf/EscherBSERecord.java b/poi/src/main/java/org/apache/poi/ddf/EscherBSERecord.java index 0d6ad788fa..255fa212ec 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherBSERecord.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherBSERecord.java @@ -57,14 +57,14 @@ public final class EscherBSERecord extends EscherRecord { private byte[] _remainingData = new byte[0]; /** - * @param length the max length allowed for EscherBSERecord + * @param length the max record length allowed for EscherBSERecord */ public static void setMaxRecordLength(int length) { MAX_RECORD_LENGTH = length; } /** - * @return the max length allowed for EscherBSERecord + * @return the max record length allowed for EscherBSERecord */ public static int getMaxRecordLength() { return MAX_RECORD_LENGTH; diff --git a/poi/src/main/java/org/apache/poi/ddf/EscherBlipRecord.java b/poi/src/main/java/org/apache/poi/ddf/EscherBlipRecord.java index 860798b6fe..8a08fe29ee 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherBlipRecord.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherBlipRecord.java @@ -38,14 +38,14 @@ public class EscherBlipRecord extends EscherRecord { private byte[] field_pictureData; /** - * @param length the max length allowed for EscherBlipRecord + * @param length the max record length allowed for EscherBlipRecord */ public static void setMaxRecordLength(int length) { MAX_RECORD_LENGTH = length; } /** - * @return the max length allowed for EscherBlipRecord + * @return the max record length allowed for EscherBlipRecord */ public static int getMaxRecordLength() { return MAX_RECORD_LENGTH; diff --git a/poi/src/main/java/org/apache/poi/ddf/EscherClientAnchorRecord.java b/poi/src/main/java/org/apache/poi/ddf/EscherClientAnchorRecord.java index b684014be5..a24c816fd6 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherClientAnchorRecord.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherClientAnchorRecord.java @@ -62,14 +62,14 @@ public class EscherClientAnchorRecord extends EscherRecord { private boolean shortRecord; /** - * @param length the max length allowed for EscherClientAnchorRecord + * @param length the max record length allowed for EscherClientAnchorRecord */ public static void setMaxRecordLength(int length) { MAX_RECORD_LENGTH = length; } /** - * @return the max length allowed for EscherClientAnchorRecord + * @return the max record length allowed for EscherClientAnchorRecord */ public static int getMaxRecordLength() { return MAX_RECORD_LENGTH; diff --git a/poi/src/main/java/org/apache/poi/ddf/EscherClientDataRecord.java b/poi/src/main/java/org/apache/poi/ddf/EscherClientDataRecord.java index aab9249f8e..8023438aec 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherClientDataRecord.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherClientDataRecord.java @@ -41,14 +41,14 @@ public class EscherClientDataRecord extends EscherRecord { private byte[] remainingData; /** - * @param length the max length allowed for EscherClientDataRecord + * @param length the max record length allowed for EscherClientDataRecord */ public static void setMaxRecordLength(int length) { MAX_RECORD_LENGTH = length; } /** - * @return the max length allowed for EscherClientDataRecord + * @return the max record length allowed for EscherClientDataRecord */ public static int getMaxRecordLength() { return MAX_RECORD_LENGTH; diff --git a/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java b/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java index bb63ce40f5..8feafedcc1 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java @@ -79,14 +79,14 @@ public final class EscherMetafileBlip extends EscherBlipRecord { private byte[] remainingData; /** - * @param length the max length allowed for EscherMetafileBlip + * @param length the max record length allowed for EscherMetafileBlip */ public static void setMaxRecordLength(int length) { MAX_RECORD_LENGTH = length; } /** - * @return the max length allowed for EscherMetafileBlip + * @return the max record length allowed for EscherMetafileBlip */ public static int getMaxRecordLength() { return MAX_RECORD_LENGTH; diff --git a/poi/src/main/java/org/apache/poi/ddf/EscherTextboxRecord.java b/poi/src/main/java/org/apache/poi/ddf/EscherTextboxRecord.java index 0105bc5c1e..06e21f2fcd 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherTextboxRecord.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherTextboxRecord.java @@ -45,14 +45,14 @@ public final class EscherTextboxRecord extends EscherRecord { private byte[] thedata = NO_BYTES; /** - * @param length the max length allowed for EscherTextboxRecord + * @param length the max record length allowed for EscherTextboxRecord */ public static void setMaxRecordLength(int length) { MAX_RECORD_LENGTH = length; } /** - * @return the max length allowed for EscherTextboxRecord + * @return the max record length allowed for EscherTextboxRecord */ public static int getMaxRecordLength() { return MAX_RECORD_LENGTH; diff --git a/poi/src/main/java/org/apache/poi/ddf/UnknownEscherRecord.java b/poi/src/main/java/org/apache/poi/ddf/UnknownEscherRecord.java index e3b2b8c5c0..28fbfb28c4 100644 --- a/poi/src/main/java/org/apache/poi/ddf/UnknownEscherRecord.java +++ b/poi/src/main/java/org/apache/poi/ddf/UnknownEscherRecord.java @@ -34,7 +34,8 @@ import org.apache.poi.util.LittleEndian; public final class UnknownEscherRecord extends EscherRecord { //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000_000; + private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000_000; + private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; private static final byte[] NO_BYTES = new byte[0]; @@ -42,6 +43,20 @@ public final class UnknownEscherRecord extends EscherRecord { private byte[] thedata = NO_BYTES; private final List<EscherRecord> _childRecords = new ArrayList<>(); + /** + * @param length the max record length allowed for UnknownEscherRecord + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max record length allowed for UnknownEscherRecord + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + public UnknownEscherRecord() {} public UnknownEscherRecord(UnknownEscherRecord other) { diff --git a/poi/src/main/java/org/apache/poi/hpsf/Blob.java b/poi/src/main/java/org/apache/poi/hpsf/Blob.java index 737462c667..8ac5d7bdfe 100644 --- a/poi/src/main/java/org/apache/poi/hpsf/Blob.java +++ b/poi/src/main/java/org/apache/poi/hpsf/Blob.java @@ -30,14 +30,14 @@ public class Blob { private byte[] _value; /** - * @param length the max length allowed for Blob + * @param length the max record length allowed for Blob */ public static void setMaxRecordLength(int length) { MAX_RECORD_LENGTH = length; } /** - * @return the max length allowed for Blob + * @return the max record length allowed for Blob */ public static int getMaxRecordLength() { return MAX_RECORD_LENGTH; diff --git a/poi/src/main/java/org/apache/poi/hpsf/ClipboardData.java b/poi/src/main/java/org/apache/poi/hpsf/ClipboardData.java index 94e8edd3c2..8872b7efc1 100644 --- a/poi/src/main/java/org/apache/poi/hpsf/ClipboardData.java +++ b/poi/src/main/java/org/apache/poi/hpsf/ClipboardData.java @@ -38,14 +38,14 @@ public class ClipboardData { private byte[] _value; /** - * @param length the max length allowed for ClipboardData + * @param length the max record length allowed for ClipboardData */ public static void setMaxRecordLength(int length) { MAX_RECORD_LENGTH = length; } /** - * @return the max length allowed for ClipboardData + * @return the max record length allowed for ClipboardData */ public static int getMaxRecordLength() { return MAX_RECORD_LENGTH; diff --git a/poi/src/main/java/org/apache/poi/hpsf/CodePageString.java b/poi/src/main/java/org/apache/poi/hpsf/CodePageString.java index ee2c69487a..44fde36a21 100644 --- a/poi/src/main/java/org/apache/poi/hpsf/CodePageString.java +++ b/poi/src/main/java/org/apache/poi/hpsf/CodePageString.java @@ -42,14 +42,14 @@ public class CodePageString { private byte[] _value; /** - * @param length the max length allowed for CodePageString + * @param length the max record length allowed for CodePageString */ public static void setMaxRecordLength(int length) { MAX_RECORD_LENGTH = length; } /** - * @return the max length allowed for CodePageString + * @return the max record length allowed for CodePageString */ public static int getMaxRecordLength() { return MAX_RECORD_LENGTH; diff --git a/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java b/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java index 7d359c228b..d50ec09d4d 100644 --- a/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java +++ b/poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java @@ -63,8 +63,8 @@ public class OldExcelExtractor implements POITextExtractor { private static final int FILE_PASS_RECORD_SID = 0x2f; //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; - + private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000; + private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; private RecordInputStream ris; @@ -74,6 +74,20 @@ public class OldExcelExtractor implements POITextExtractor { private int biffVersion; private int fileType; + /** + * @param length the max record length allowed for OldExcelExtractor + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max record length allowed for OldExcelExtractor + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + public OldExcelExtractor(InputStream input) throws IOException { open(input); } diff --git a/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8DecryptingStream.java b/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8DecryptingStream.java index 36776807f2..6f7370d180 100644 --- a/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8DecryptingStream.java +++ b/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8DecryptingStream.java @@ -38,12 +38,27 @@ public final class Biff8DecryptingStream implements BiffHeaderInput, LittleEndia public static final int RC4_REKEYING_INTERVAL = 1024; //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; + private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000; + private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; private final ChunkedCipherInputStream ccis; private final byte[] buffer = new byte[LittleEndianConsts.LONG_SIZE]; private boolean shouldSkipEncryptionOnCurrentRecord; + /** + * @param length the max record length allowed for Biff8DecryptingStream + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max record length allowed for Biff8DecryptingStream + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + public Biff8DecryptingStream(InputStream in, int initialOffset, EncryptionInfo info) throws RecordFormatException { try { byte[] initialBuf = IOUtils.safelyAllocate(initialOffset, MAX_RECORD_LENGTH); diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 65297e5405..f1e190b89a 100644 --- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -138,8 +138,10 @@ import org.apache.poi.util.Removal; public final class HSSFWorkbook extends POIDocument implements Workbook { //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; - private static final int MAX_IMAGE_LENGTH = 50_000_000; + private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000; + private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; + private static final int DEFAULT_MAX_IMAGE_LENGTH = 50_000_000; + private static int MAX_IMAGE_LENGTH = DEFAULT_MAX_IMAGE_LENGTH; private static final Pattern COMMA_PATTERN = Pattern.compile(","); @@ -219,6 +221,34 @@ public final class HSSFWorkbook extends POIDocument implements Workbook { } /** + * @param length the max record length allowed for HSSFWorkbook + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max record length allowed for HSSFWorkbook + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + + /** + * @param length the max image length allowed for HSSFWorkbook + */ + public static void setMaxImageLength(int length) { + MAX_IMAGE_LENGTH = length; + } + + /** + * @return the max image length allowed for HSSFWorkbook + */ + public static int getMaxImageLength() { + return MAX_IMAGE_LENGTH; + } + + /** * Creates new HSSFWorkbook from scratch (start here!) */ public HSSFWorkbook() { diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java b/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java index c0ff0fc2d3..c845d93b1d 100644 --- a/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java +++ b/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherInputStream.java @@ -31,10 +31,6 @@ import org.apache.poi.util.LittleEndianInputStream; @Internal public abstract class ChunkedCipherInputStream extends LittleEndianInputStream { - //arbitrarily selected; may need to increase - private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000; - private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; - private final int chunkSize; private final int chunkBits; @@ -46,20 +42,6 @@ public abstract class ChunkedCipherInputStream extends LittleEndianInputStream { private long pos; private boolean chunkIsValid; - /** - * @param length the max length allowed for ChunkedCipherInputStream - */ - public static void setMaxRecordLength(int length) { - MAX_RECORD_LENGTH = length; - } - - /** - * @return the max length allowed for ChunkedCipherInputStream - */ - public static int getMaxRecordLength() { - return MAX_RECORD_LENGTH; - } - public ChunkedCipherInputStream(InputStream stream, long size, int chunkSize) throws GeneralSecurityException { this(stream, size, chunkSize, 0); @@ -72,8 +54,8 @@ public abstract class ChunkedCipherInputStream extends LittleEndianInputStream { this.pos = initialPos; this.chunkSize = chunkSize; int cs = chunkSize == -1 ? 4096 : chunkSize; - this.chunk = IOUtils.safelyAllocate(cs, MAX_RECORD_LENGTH); - this.plain = IOUtils.safelyAllocate(cs, MAX_RECORD_LENGTH); + this.chunk = IOUtils.safelyAllocate(cs, CryptoFunctions.MAX_RECORD_LENGTH); + this.plain = IOUtils.safelyAllocate(cs, CryptoFunctions.MAX_RECORD_LENGTH); this.chunkBits = Integer.bitCount(chunk.length-1); this.lastIndex = (int)(pos >> chunkBits); this.cipher = initCipherForBlock(null, lastIndex); diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java b/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java index 014a60c16d..b600b20073 100644 --- a/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java +++ b/poi/src/main/java/org/apache/poi/poifs/crypt/ChunkedCipherOutputStream.java @@ -43,9 +43,6 @@ import org.apache.poi.util.TempFile; @Internal public abstract class ChunkedCipherOutputStream extends FilterOutputStream { private static final Logger LOG = LogManager.getLogger(ChunkedCipherOutputStream.class); - //arbitrarily selected; may need to increase - private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000; - private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; private static final int STREAMING = -1; @@ -66,25 +63,11 @@ public abstract class ChunkedCipherOutputStream extends FilterOutputStream { private Cipher cipher; private boolean isClosed; - /** - * @param length the max length allowed for ChunkedCipherOutputStream - */ - public static void setMaxRecordLength(int length) { - MAX_RECORD_LENGTH = length; - } - - /** - * @return the max length allowed for ChunkedCipherOutputStream - */ - public static int getMaxRecordLength() { - return MAX_RECORD_LENGTH; - } - public ChunkedCipherOutputStream(DirectoryNode dir, int chunkSize) throws IOException, GeneralSecurityException { super(null); this.chunkSize = chunkSize; int cs = chunkSize == STREAMING ? 4096 : chunkSize; - this.chunk = IOUtils.safelyAllocate(cs, MAX_RECORD_LENGTH); + this.chunk = IOUtils.safelyAllocate(cs, CryptoFunctions.MAX_RECORD_LENGTH); this.plainByteFlags = new SparseBitSet(cs); this.chunkBits = Integer.bitCount(cs-1); this.fileOut = TempFile.createTempFile("encrypted_package", "crypt"); @@ -98,7 +81,7 @@ public abstract class ChunkedCipherOutputStream extends FilterOutputStream { super(stream); this.chunkSize = chunkSize; int cs = chunkSize == STREAMING ? 4096 : chunkSize; - this.chunk = IOUtils.safelyAllocate(cs, MAX_RECORD_LENGTH); + this.chunk = IOUtils.safelyAllocate(cs, CryptoFunctions.MAX_RECORD_LENGTH); this.plainByteFlags = new SparseBitSet(cs); this.chunkBits = Integer.bitCount(cs-1); this.fileOut = null; diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/CryptoFunctions.java b/poi/src/main/java/org/apache/poi/poifs/crypt/CryptoFunctions.java index 1cc07539e9..ea0298a829 100644 --- a/poi/src/main/java/org/apache/poi/poifs/crypt/CryptoFunctions.java +++ b/poi/src/main/java/org/apache/poi/poifs/crypt/CryptoFunctions.java @@ -47,7 +47,22 @@ import org.apache.poi.util.StringUtil; public final class CryptoFunctions { //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; + private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000; + static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; + + /** + * @param length the max record length allowed for CryptoFunctions + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max record length allowed for CryptoFunctions + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } private CryptoFunctions() { } diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java b/poi/src/main/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java index d83754c6f6..bebd3643cf 100644 --- a/poi/src/main/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java +++ b/poi/src/main/java/org/apache/poi/poifs/crypt/DataSpaceMapUtils.java @@ -35,24 +35,6 @@ import org.apache.poi.util.StringUtil; public class DataSpaceMapUtils { - //arbitrarily selected; may need to increase - private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000; - private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; - - /** - * @param length the max length allowed for EscherTextboxRecord - */ - public static void setMaxRecordLength(int length) { - MAX_RECORD_LENGTH = length; - } - - /** - * @return the max length allowed for EscherTextboxRecord - */ - public static int getMaxRecordLength() { - return MAX_RECORD_LENGTH; - } - public static void addDefaultDataSpace(DirectoryEntry dir) throws IOException { DataSpaceMapEntry dsme = new DataSpaceMapEntry( new int[]{ 0 } @@ -352,7 +334,7 @@ public class DataSpaceMapUtils { return length == 0 ? null : ""; } - byte[] data = IOUtils.safelyAllocate(length, MAX_RECORD_LENGTH); + byte[] data = IOUtils.safelyAllocate(length, CryptoFunctions.MAX_RECORD_LENGTH); is.readFully(data); // Padding (variable): A set of bytes that MUST be of correct size such that the size of the UTF-8-LP-P4 diff --git a/poi/src/main/java/org/apache/poi/poifs/crypt/agile/AgileEncryptor.java b/poi/src/main/java/org/apache/poi/poifs/crypt/agile/AgileEncryptor.java index 97e172915e..0acf5d8241 100644 --- a/poi/src/main/java/org/apache/poi/poifs/crypt/agile/AgileEncryptor.java +++ b/poi/src/main/java/org/apache/poi/poifs/crypt/agile/AgileEncryptor.java @@ -68,11 +68,26 @@ import org.w3c.dom.Document; public class AgileEncryptor extends Encryptor { //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; + private static final int DEFAULT_MAX_RECORD_LENGTH = 1_000_000; + private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; private byte[] integritySalt; private byte[] pwHash; + /** + * @param length the max record length allowed for AgileEncryptor + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max record length allowed for AgileEncryptor + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + protected AgileEncryptor() {} protected AgileEncryptor(AgileEncryptor other) { diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java index 1ce4238f63..9b1545e3b0 100644 --- a/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java +++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/Ole10Native.java @@ -50,9 +50,11 @@ public class Ole10Native { public static final String OLE10_NATIVE = "\u0001Ole10Native"; private static final Charset ISO1 = StandardCharsets.ISO_8859_1; // arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000_000; + private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000_000; + private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; // arbitrarily selected; may need to increase - private static final int MAX_STRING_LENGTH = 1024; + private static final int DEFAULT_MAX_STRING_LENGTH = 1024; + private static int MAX_STRING_LENGTH = DEFAULT_MAX_STRING_LENGTH; /** * Default content of the \u0001Ole entry @@ -139,6 +141,34 @@ public class Ole10Native { } /** + * @param length the max record length allowed for Ole10Native + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max record length allowed for Ole10Native + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + + /** + * @param length the max string length allowed for Ole10Native + */ + public static void setMaxStringLength(int length) { + MAX_STRING_LENGTH = length; + } + + /** + * @return the max string length allowed for Ole10Native + */ + public static int getMaxStringLength() { + return MAX_STRING_LENGTH; + } + + /** * Creates an instance and fills the fields based on ... the fields */ public Ole10Native(String label, String filename, String command, byte[] data) { diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSDocument.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSDocument.java index 2dfb4c3c62..d8b6b2cd57 100644 --- a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSDocument.java +++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSDocument.java @@ -40,139 +40,133 @@ import org.apache.poi.util.IOUtils; */ public final class POIFSDocument implements POIFSViewable, Iterable<ByteBuffer> { - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; - private DocumentProperty _property; - private POIFSFileSystem _filesystem; - private POIFSStream _stream; - private int _block_size; - - /** - * Constructor for an existing Document - */ - public POIFSDocument(DocumentNode document) { - this((DocumentProperty)document.getProperty(), - ((DirectoryNode)document.getParent()).getFileSystem()); - } - - /** - * Constructor for an existing Document - */ - public POIFSDocument(DocumentProperty property, POIFSFileSystem filesystem) { - this._property = property; - this._filesystem = filesystem; - - if(property.getSize() < POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE) { - _stream = new POIFSStream(_filesystem.getMiniStore(), property.getStartBlock()); - _block_size = _filesystem.getMiniStore().getBlockStoreBlockSize(); - } else { - _stream = new POIFSStream(_filesystem, property.getStartBlock()); - _block_size = _filesystem.getBlockStoreBlockSize(); - } - } - - /** - * Constructor for a new Document - * - * @param name the name of the POIFSDocument - * @param stream the InputStream we read data from - */ - public POIFSDocument(String name, POIFSFileSystem filesystem, InputStream stream) - throws IOException - { - this._filesystem = filesystem; - - // Store it - int length = store(stream); - - // Build the property for it - this._property = new DocumentProperty(name, length); - _property.setStartBlock(_stream.getStartBlock()); - _property.setDocument(this); - } - - public POIFSDocument(String name, final int size, POIFSFileSystem filesystem, POIFSWriterListener writer) - throws IOException - { - this._filesystem = filesystem; - - if (size < POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE) { - _stream = new POIFSStream(filesystem.getMiniStore()); - _block_size = _filesystem.getMiniStore().getBlockStoreBlockSize(); - } else { - _stream = new POIFSStream(filesystem); - _block_size = _filesystem.getBlockStoreBlockSize(); - } - - this._property = new DocumentProperty(name, size); - _property.setStartBlock(_stream.getStartBlock()); - _property.setDocument(this); - - try (DocumentOutputStream os = new DocumentOutputStream(this, size)) { - POIFSDocumentPath path = new POIFSDocumentPath(name.split("\\\\")); - String docName = path.getComponent(path.length() - 1); - POIFSWriterEvent event = new POIFSWriterEvent(os, path, docName, size); - writer.processPOIFSWriterEvent(event); - } - } - - /** - * Stores the given data for this Document - */ - private int store(InputStream stream) throws IOException { - final int bigBlockSize = POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE; - BufferedInputStream bis = new BufferedInputStream(stream, bigBlockSize+1); - bis.mark(bigBlockSize); - - // Do we need to store as a mini stream or a full one? - long streamBlockSize = IOUtils.skipFully(bis, bigBlockSize); - if (streamBlockSize < bigBlockSize) { - _stream = new POIFSStream(_filesystem.getMiniStore()); - _block_size = _filesystem.getMiniStore().getBlockStoreBlockSize(); - } else { - _stream = new POIFSStream(_filesystem); - _block_size = _filesystem.getBlockStoreBlockSize(); - } - - // start from the beginning - bis.reset(); - - // Store it - final long length; - try (OutputStream os = _stream.getOutputStream()) { - length = IOUtils.copy(bis, os); - - // Pad to the end of the block with -1s - int usedInBlock = (int) (length % _block_size); - if (usedInBlock != 0 && usedInBlock != _block_size) { - int toBlockEnd = _block_size - usedInBlock; - byte[] padding = IOUtils.safelyAllocate(toBlockEnd, MAX_RECORD_LENGTH); - Arrays.fill(padding, (byte) 0xFF); - os.write(padding); - } - } - - return Math.toIntExact(length); - } - - /** - * Frees the underlying stream and property - */ - void free() throws IOException { - _stream.free(); - _property.setStartBlock(POIFSConstants.END_OF_CHAIN); - } - - POIFSFileSystem getFileSystem() - { - return _filesystem; - } - - int getDocumentBlockSize() { - return _block_size; - } + private POIFSFileSystem _filesystem; + private POIFSStream _stream; + private int _block_size; + + /** + * Constructor for an existing Document + */ + public POIFSDocument(DocumentNode document) { + this((DocumentProperty) document.getProperty(), + ((DirectoryNode) document.getParent()).getFileSystem()); + } + + /** + * Constructor for an existing Document + */ + public POIFSDocument(DocumentProperty property, POIFSFileSystem filesystem) { + this._property = property; + this._filesystem = filesystem; + + if (property.getSize() < POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE) { + _stream = new POIFSStream(_filesystem.getMiniStore(), property.getStartBlock()); + _block_size = _filesystem.getMiniStore().getBlockStoreBlockSize(); + } else { + _stream = new POIFSStream(_filesystem, property.getStartBlock()); + _block_size = _filesystem.getBlockStoreBlockSize(); + } + } + + /** + * Constructor for a new Document + * + * @param name the name of the POIFSDocument + * @param stream the InputStream we read data from + */ + public POIFSDocument(String name, POIFSFileSystem filesystem, InputStream stream) + throws IOException { + this._filesystem = filesystem; + + // Store it + int length = store(stream); + + // Build the property for it + this._property = new DocumentProperty(name, length); + _property.setStartBlock(_stream.getStartBlock()); + _property.setDocument(this); + } + + public POIFSDocument(String name, final int size, POIFSFileSystem filesystem, POIFSWriterListener writer) + throws IOException { + this._filesystem = filesystem; + + if (size < POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE) { + _stream = new POIFSStream(filesystem.getMiniStore()); + _block_size = _filesystem.getMiniStore().getBlockStoreBlockSize(); + } else { + _stream = new POIFSStream(filesystem); + _block_size = _filesystem.getBlockStoreBlockSize(); + } + + this._property = new DocumentProperty(name, size); + _property.setStartBlock(_stream.getStartBlock()); + _property.setDocument(this); + + try (DocumentOutputStream os = new DocumentOutputStream(this, size)) { + POIFSDocumentPath path = new POIFSDocumentPath(name.split("\\\\")); + String docName = path.getComponent(path.length() - 1); + POIFSWriterEvent event = new POIFSWriterEvent(os, path, docName, size); + writer.processPOIFSWriterEvent(event); + } + } + + /** + * Stores the given data for this Document + */ + private int store(InputStream stream) throws IOException { + final int bigBlockSize = POIFSConstants.BIG_BLOCK_MINIMUM_DOCUMENT_SIZE; + BufferedInputStream bis = new BufferedInputStream(stream, bigBlockSize + 1); + bis.mark(bigBlockSize); + + // Do we need to store as a mini stream or a full one? + long streamBlockSize = IOUtils.skipFully(bis, bigBlockSize); + if (streamBlockSize < bigBlockSize) { + _stream = new POIFSStream(_filesystem.getMiniStore()); + _block_size = _filesystem.getMiniStore().getBlockStoreBlockSize(); + } else { + _stream = new POIFSStream(_filesystem); + _block_size = _filesystem.getBlockStoreBlockSize(); + } + + // start from the beginning + bis.reset(); + + // Store it + final long length; + try (OutputStream os = _stream.getOutputStream()) { + length = IOUtils.copy(bis, os); + + // Pad to the end of the block with -1s + int usedInBlock = (int) (length % _block_size); + if (usedInBlock != 0 && usedInBlock != _block_size) { + int toBlockEnd = _block_size - usedInBlock; + byte[] padding = IOUtils.safelyAllocate(toBlockEnd, POIFSFileSystem.MAX_RECORD_LENGTH); + Arrays.fill(padding, (byte) 0xFF); + os.write(padding); + } + } + + return Math.toIntExact(length); + } + + /** + * Frees the underlying stream and property + */ + void free() throws IOException { + _stream.free(); + _property.setStartBlock(POIFSConstants.END_OF_CHAIN); + } + + POIFSFileSystem getFileSystem() { + return _filesystem; + } + + int getDocumentBlockSize() { + return _block_size; + } @Override public Iterator<ByteBuffer> iterator() { @@ -180,83 +174,83 @@ public final class POIFSDocument implements POIFSViewable, Iterable<ByteBuffer> } Iterator<ByteBuffer> getBlockIterator() { - return (getSize() > 0 ? _stream : Collections.<ByteBuffer>emptyList()).iterator(); + return (getSize() > 0 ? _stream : Collections.<ByteBuffer>emptyList()).iterator(); + } + + /** + * @return size of the document + */ + public int getSize() { + return _property.getSize(); + } + + public void replaceContents(InputStream stream) throws IOException { + free(); + int size = store(stream); + _property.setStartBlock(_stream.getStartBlock()); + _property.updateSize(size); + } + + /** + * @return the instance's DocumentProperty + */ + DocumentProperty getDocumentProperty() { + return _property; } - /** - * @return size of the document - */ - public int getSize() { - return _property.getSize(); - } - - public void replaceContents(InputStream stream) throws IOException { - free(); - int size = store(stream); - _property.setStartBlock(_stream.getStartBlock()); - _property.updateSize(size); - } - - /** - * @return the instance's DocumentProperty - */ - DocumentProperty getDocumentProperty() { - return _property; - } - - /** - * Get an array of objects, some of which may implement POIFSViewable - * - * @return an array of Object; may not be null, but may be empty - */ - public Object[] getViewableArray() { - String result = "<NO DATA>"; - - if(getSize() > 0) { - // Get all the data into a single array - byte[] data = IOUtils.safelyAllocate(getSize(), MAX_RECORD_LENGTH); - int offset = 0; - for(ByteBuffer buffer : _stream) { - int length = Math.min(_block_size, data.length-offset); - buffer.get(data, offset, length); - offset += length; - } - - result = HexDump.dump(data, 0, 0); - } - - return new String[]{ result }; - } - - /** - * Get an Iterator of objects, some of which may implement POIFSViewable - * - * @return an Iterator; may not be null, but may have an empty back end - * store - */ - public Iterator<Object> getViewableIterator() { - return emptyIterator(); - } - - /** - * Give viewers a hint as to whether to call getViewableArray or - * getViewableIterator - * - * @return <code>true</code> if a viewer should call getViewableArray, - * <code>false</code> if a viewer should call getViewableIterator - */ - public boolean preferArray() { - return true; - } - - /** - * Provides a short description of the object, to be used when a - * POIFSViewable object has not provided its contents. - * - * @return short description - */ - public String getShortDescription() { - - return "Document: \"" + _property.getName() + "\" size = " + getSize(); - } + /** + * Get an array of objects, some of which may implement POIFSViewable + * + * @return an array of Object; may not be null, but may be empty + */ + public Object[] getViewableArray() { + String result = "<NO DATA>"; + + if (getSize() > 0) { + // Get all the data into a single array + byte[] data = IOUtils.safelyAllocate(getSize(), POIFSFileSystem.MAX_RECORD_LENGTH); + int offset = 0; + for (ByteBuffer buffer : _stream) { + int length = Math.min(_block_size, data.length - offset); + buffer.get(data, offset, length); + offset += length; + } + + result = HexDump.dump(data, 0, 0); + } + + return new String[]{result}; + } + + /** + * Get an Iterator of objects, some of which may implement POIFSViewable + * + * @return an Iterator; may not be null, but may have an empty back end + * store + */ + public Iterator<Object> getViewableIterator() { + return emptyIterator(); + } + + /** + * Give viewers a hint as to whether to call getViewableArray or + * getViewableIterator + * + * @return <code>true</code> if a viewer should call getViewableArray, + * <code>false</code> if a viewer should call getViewableIterator + */ + public boolean preferArray() { + return true; + } + + /** + * Provides a short description of the object, to be used when a + * POIFSViewable object has not provided its contents. + * + * @return short description + */ + public String getShortDescription() { + + return "Document: \"" + _property.getName() + "\" size = " + getSize(); + } } diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java index 3f5e8f4507..343aba35d3 100644 --- a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java +++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java @@ -61,7 +61,8 @@ import org.apache.poi.util.Internal; public class POIFSFileSystem extends BlockStore implements POIFSViewable, Closeable { //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; + private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000; + static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; private static final Logger LOG = LogManager.getLogger(POIFSFileSystem.class); @@ -94,6 +95,20 @@ public class POIFSFileSystem extends BlockStore private POIFSBigBlockSize bigBlockSize = POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS; + /** + * @param length the max record length allowed for POIFSFileSystem + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max record length allowed for POIFSFileSystem + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + private POIFSFileSystem(boolean newFS) { _header = new HeaderBlock(bigBlockSize); _property_table = new PropertyTable(_header); diff --git a/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java b/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java index bfb4caabf5..bdaccb7d6c 100644 --- a/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java +++ b/poi/src/main/java/org/apache/poi/ss/extractor/EmbeddedExtractor.java @@ -68,14 +68,14 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> { private static final String CONTENT_TYPE_XLS = "application/vnd.ms-excel"; /** - * @param length the max length allowed for EmbeddedExtractor + * @param length the max record length allowed for EmbeddedExtractor */ public static void setMaxRecordLength(int length) { MAX_RECORD_LENGTH = length; } /** - * @return the max length allowed for EmbeddedExtractor + * @return the max record length allowed for EmbeddedExtractor */ public static int getMaxRecordLength() { return MAX_RECORD_LENGTH; diff --git a/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionMetadataReader.java b/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionMetadataReader.java index a44379c37a..e7949ecc92 100644 --- a/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionMetadataReader.java +++ b/poi/src/main/java/org/apache/poi/ss/formula/function/FunctionMetadataReader.java @@ -57,14 +57,14 @@ final class FunctionMetadataReader { private static final Set<String> DIGIT_ENDING_FUNCTION_NAMES_SET = new HashSet<>(Arrays.asList(DIGIT_ENDING_FUNCTION_NAMES)); /** - * @param length the max length allowed for FunctionMetadataReader + * @param length the max record length allowed for FunctionMetadataReader */ public static void setMaxRecordLength(int length) { MAX_RECORD_LENGTH = length; } /** - * @return the max length allowed for FunctionMetadataReader + * @return the max record length allowed for FunctionMetadataReader */ public static int getMaxRecordLength() { return MAX_RECORD_LENGTH; diff --git a/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java b/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java index 1fc9573ee0..a883ee3abb 100644 --- a/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java +++ b/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java @@ -61,14 +61,14 @@ public abstract class LZWDecompresser { private final boolean positionIsBigEndian; /** - * @param length the max length allowed for LZWDecompresser + * @param length the max record length allowed for LZWDecompresser */ public static void setMaxRecordLength(int length) { MAX_RECORD_LENGTH = length; } /** - * @return the max length allowed for LZWDecompresser + * @return the max record length allowed for LZWDecompresser */ public static int getMaxRecordLength() { return MAX_RECORD_LENGTH; diff --git a/poi/src/main/java/org/apache/poi/util/StringUtil.java b/poi/src/main/java/org/apache/poi/util/StringUtil.java index c805dd4517..fb9d61b43d 100644 --- a/poi/src/main/java/org/apache/poi/util/StringUtil.java +++ b/poi/src/main/java/org/apache/poi/util/StringUtil.java @@ -37,14 +37,14 @@ public final class StringUtil { public static final Charset WIN_1252 = Charset.forName("cp1252"); /** - * @param length the max length allowed for StringUtil + * @param length the max record length allowed for StringUtil */ public static void setMaxRecordLength(int length) { MAX_RECORD_LENGTH = length; } /** - * @return the max length allowed for StringUtil + * @return the max record length allowed for StringUtil */ public static int getMaxRecordLength() { return MAX_RECORD_LENGTH; |