From dbc6576da49b02c5cfab100b99d48c449f445222 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 21 Oct 2021 16:52:09 +0000 Subject: [PATCH] make max record sizes configurable git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894452 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hslf/record/FontEmbeddedData.java | 17 +++++++++- .../org/apache/poi/hwpf/sprm/SprmUtils.java | 34 +++++++++++++------ .../poi/hwpf/sprm/TableSprmCompressor.java | 12 +++---- .../org/apache/poi/ddf/EscherBSERecord.java | 17 +++++++++- .../org/apache/poi/ddf/EscherBlipRecord.java | 17 +++++++++- .../poi/ddf/EscherClientAnchorRecord.java | 17 +++++++++- .../poi/ddf/EscherClientDataRecord.java | 17 +++++++++- .../apache/poi/ddf/EscherMetafileBlip.java | 17 +++++++++- .../apache/poi/ddf/EscherTextboxRecord.java | 19 +++++++++-- .../main/java/org/apache/poi/hpsf/Blob.java | 17 +++++++++- .../org/apache/poi/hpsf/ClipboardData.java | 17 +++++++++- .../org/apache/poi/hpsf/CodePageString.java | 16 ++++++++- .../poifs/crypt/ChunkedCipherInputStream.java | 17 +++++++++- .../crypt/ChunkedCipherOutputStream.java | 17 +++++++++- .../poi/poifs/crypt/DataSpaceMapUtils.java | 17 +++++++++- .../poi/ss/extractor/EmbeddedExtractor.java | 17 +++++++++- .../function/FunctionMetadataReader.java | 17 +++++++++- .../org/apache/poi/util/LZWDecompresser.java | 17 +++++++++- .../java/org/apache/poi/util/StringUtil.java | 17 +++++++++- 19 files changed, 299 insertions(+), 37 deletions(-) diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/FontEmbeddedData.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/FontEmbeddedData.java index dc0a8e9410..0be9d5e782 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/FontEmbeddedData.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/FontEmbeddedData.java @@ -32,7 +32,8 @@ import org.apache.poi.util.LittleEndian; @SuppressWarnings("WeakerAccess") public class FontEmbeddedData extends RecordAtom implements FontFacet { //arbitrarily selected; may need to increase (increased due to https://bz.apache.org/bugzilla/show_bug.cgi?id=65639) - private static final int MAX_RECORD_LENGTH = 5_000_000; + private static final int DEFAULT_MAX_RECORD_LENGTH = 5_000_000; + private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; /** * Record header. @@ -49,6 +50,20 @@ public class FontEmbeddedData extends RecordAtom implements FontFacet { */ private FontHeader fontHeader; + /** + * @param length the max length allowed for FontEmbeddedData + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max length allowed for FontEmbeddedData + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + /** * Constructs a brand new font embedded record. */ diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/SprmUtils.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/SprmUtils.java index 8563749a64..4e978396ed 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/SprmUtils.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/SprmUtils.java @@ -19,25 +19,37 @@ package org.apache.poi.hwpf.sprm; import java.util.List; -import org.apache.poi.util.IOUtils; -import org.apache.poi.util.Internal; -import org.apache.poi.util.LittleEndian; -import org.apache.poi.util.LittleEndianConsts; +import org.apache.poi.util.*; @Internal -public final class SprmUtils -{ +public final class SprmUtils { //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 length allowed for SPRM data + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } - public SprmUtils() - { + /** + * @return the max length allowed for SPRM data + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; } - public static byte[] shortArrayToByteArray(short[] convert) - { + public SprmUtils() {} + + /** + * @deprecated unused by POI internally + */ + @Removal(version= "6.0.0") + public static byte[] shortArrayToByteArray(short[] convert) { byte[] buf = IOUtils.safelyAllocate(convert.length * (long)LittleEndianConsts.SHORT_SIZE, MAX_RECORD_LENGTH); for (int x = 0; x < convert.length; x++) diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/TableSprmCompressor.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/TableSprmCompressor.java index 9c76e2ec13..2cb073afe4 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/TableSprmCompressor.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/sprm/TableSprmCompressor.java @@ -31,14 +31,10 @@ import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; @Internal -public final class TableSprmCompressor -{ - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; +public final class TableSprmCompressor { + + public TableSprmCompressor() {} - public TableSprmCompressor() - { - } public static byte[] compressTableProperty(TableProperties newTAP) { int size = 0; @@ -85,7 +81,7 @@ public final class TableSprmCompressor 1 + (LittleEndianConsts.SHORT_SIZE*((long)itcMac + 1)) + (TableCellDescriptor.SIZE*(long)itcMac), - MAX_RECORD_LENGTH); + SprmUtils.MAX_RECORD_LENGTH); buf[0] = (byte)itcMac; short[] dxaCenters = newTAP.getRgdxaCenter(); 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 08f3a0c694..0d6ad788fa 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherBSERecord.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherBSERecord.java @@ -36,7 +36,8 @@ import org.apache.poi.util.LittleEndian; public final class EscherBSERecord extends EscherRecord { //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; public static final short RECORD_ID = EscherRecordTypes.BSE.typeID; @@ -55,6 +56,20 @@ public final class EscherBSERecord extends EscherRecord { private byte[] _remainingData = new byte[0]; + /** + * @param length the max length allowed for EscherBSERecord + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max length allowed for EscherBSERecord + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + public EscherBSERecord() { setRecordId(RECORD_ID); } 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 c9e6d73e5c..860798b6fe 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherBlipRecord.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherBlipRecord.java @@ -27,7 +27,8 @@ import org.apache.poi.util.LittleEndian; public class EscherBlipRecord extends EscherRecord { //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 104_857_600; + private static final int DEFAULT_MAX_RECORD_LENGTH = 104_857_600; + private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; public static final short RECORD_ID_START = EscherRecordTypes.BLIP_START.typeID; public static final short RECORD_ID_END = EscherRecordTypes.BLIP_END.typeID; @@ -36,6 +37,20 @@ public class EscherBlipRecord extends EscherRecord { private byte[] field_pictureData; + /** + * @param length the max length allowed for EscherBlipRecord + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max length allowed for EscherBlipRecord + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + public EscherBlipRecord() { } 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 5d182da247..b684014be5 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherClientAnchorRecord.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherClientAnchorRecord.java @@ -36,7 +36,8 @@ import org.apache.poi.util.LittleEndian; */ public class EscherClientAnchorRecord extends EscherRecord { //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; public static final short RECORD_ID = EscherRecordTypes.CLIENT_ANCHOR.typeID; @@ -60,6 +61,20 @@ public class EscherClientAnchorRecord extends EscherRecord { private byte[] remainingData = new byte[0]; private boolean shortRecord; + /** + * @param length the max length allowed for EscherClientAnchorRecord + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max length allowed for EscherClientAnchorRecord + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + public EscherClientAnchorRecord() {} public EscherClientAnchorRecord(EscherClientAnchorRecord other) { 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 80f4f9e7e4..aab9249f8e 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherClientDataRecord.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherClientDataRecord.java @@ -34,11 +34,26 @@ public class EscherClientDataRecord extends EscherRecord { public static final short RECORD_ID = EscherRecordTypes.CLIENT_DATA.typeID; //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 static final byte[] EMPTY = {}; private byte[] remainingData; + /** + * @param length the max length allowed for EscherClientDataRecord + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max length allowed for EscherClientDataRecord + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + public EscherClientDataRecord() {} public EscherClientDataRecord(EscherClientDataRecord other) { 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 c5fac266e3..bb63ce40f5 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherMetafileBlip.java @@ -41,7 +41,8 @@ import org.apache.poi.util.Removal; public final class EscherMetafileBlip extends EscherBlipRecord { private static final Logger LOGGER = LogManager.getLogger(EscherMetafileBlip.class); //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; /** @deprecated use EscherRecordTypes.BLIP_EMF.typeID */ @Deprecated @@ -77,6 +78,20 @@ public final class EscherMetafileBlip extends EscherBlipRecord { private byte[] raw_pictureData; private byte[] remainingData; + /** + * @param length the max length allowed for EscherMetafileBlip + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max length allowed for EscherMetafileBlip + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + public EscherMetafileBlip() {} public EscherMetafileBlip(EscherMetafileBlip other) { 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 dced174318..0105bc5c1e 100644 --- a/poi/src/main/java/org/apache/poi/ddf/EscherTextboxRecord.java +++ b/poi/src/main/java/org/apache/poi/ddf/EscherTextboxRecord.java @@ -34,15 +34,30 @@ import org.apache.poi.util.RecordFormatException; public final class EscherTextboxRecord extends EscherRecord { //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; + private static int DEFAULT_MAX_RECORD_LENGTH = 100_000; + private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; public static final short RECORD_ID = EscherRecordTypes.CLIENT_TEXTBOX.typeID; private static final byte[] NO_BYTES = new byte[0]; - /** The data for this record not including the the 8 byte header */ + /** The data for this record not including the 8 byte header */ private byte[] thedata = NO_BYTES; + /** + * @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 EscherTextboxRecord() {} public EscherTextboxRecord(EscherTextboxRecord 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 6c6e17c660..737462c667 100644 --- a/poi/src/main/java/org/apache/poi/hpsf/Blob.java +++ b/poi/src/main/java/org/apache/poi/hpsf/Blob.java @@ -24,10 +24,25 @@ import org.apache.poi.util.LittleEndianInput; public class Blob { //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 10_000_000; + private static final int DEFAULT_MAX_RECORD_LENGTH = 10_000_000; + private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; private byte[] _value; + /** + * @param length the max length allowed for Blob + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max length allowed for Blob + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + public void read( LittleEndianInput lei ) { int size = lei.readInt(); _value = IOUtils.safelyAllocate(size, 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 d92269a785..94e8edd3c2 100644 --- a/poi/src/main/java/org/apache/poi/hpsf/ClipboardData.java +++ b/poi/src/main/java/org/apache/poi/hpsf/ClipboardData.java @@ -29,13 +29,28 @@ import static org.apache.logging.log4j.util.Unbox.box; @Internal public class ClipboardData { //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 Logger LOG = LogManager.getLogger(ClipboardData.class); private int _format; private byte[] _value; + /** + * @param length the max length allowed for ClipboardData + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max length allowed for ClipboardData + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + public void read( LittleEndianByteArrayInputStream lei ) { int offset = lei.getReadIndex(); long size = lei.readInt(); 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 4ba9b0d063..ee2c69487a 100644 --- a/poi/src/main/java/org/apache/poi/hpsf/CodePageString.java +++ b/poi/src/main/java/org/apache/poi/hpsf/CodePageString.java @@ -34,12 +34,26 @@ import static org.apache.logging.log4j.util.Unbox.box; @Internal public class CodePageString { //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 static final Logger LOG = LogManager.getLogger(CodePageString.class); private byte[] _value; + /** + * @param length the max length allowed for CodePageString + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max length allowed for CodePageString + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } public void read( LittleEndianByteArrayInputStream lei ) { int offset = lei.getReadIndex(); 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 827ee4c0a7..c0ff0fc2d3 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 @@ -32,7 +32,8 @@ import org.apache.poi.util.LittleEndianInputStream; public abstract class ChunkedCipherInputStream extends LittleEndianInputStream { //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 int chunkSize; private final int chunkBits; @@ -45,6 +46,20 @@ 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); 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 9cd5c224ba..014a60c16d 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 @@ -44,7 +44,8 @@ import org.apache.poi.util.TempFile; 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 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 static final int STREAMING = -1; @@ -65,6 +66,20 @@ 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; 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 09a56e2e81..d83754c6f6 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 @@ -36,7 +36,22 @@ import org.apache.poi.util.StringUtil; public class DataSpaceMapUtils { //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; + + /** + * @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( 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 47793a14c1..bfb4caabf5 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 @@ -58,7 +58,8 @@ import org.apache.poi.util.LocaleUtil; public class EmbeddedExtractor implements Iterable { private static final Logger LOG = LogManager.getLogger(EmbeddedExtractor.class); //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; // contentType private static final String CONTENT_TYPE_BYTES = "binary/octet-stream"; @@ -66,6 +67,20 @@ public class EmbeddedExtractor implements Iterable { private static final String CONTENT_TYPE_DOC = "application/msword"; private static final String CONTENT_TYPE_XLS = "application/vnd.ms-excel"; + /** + * @param length the max length allowed for EmbeddedExtractor + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max length allowed for EmbeddedExtractor + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + /** * @return the list of known extractors, if you provide custom extractors, override this method */ 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 236546c3b4..a44379c37a 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 @@ -36,7 +36,8 @@ import org.apache.poi.util.IOUtils; final class FunctionMetadataReader { //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 static final String METADATA_FILE_NAME = "functionMetadata.txt"; private static final String METADATA_FILE_NAME_CETAB = "functionMetadataCetab.txt"; @@ -55,6 +56,20 @@ final class FunctionMetadataReader { }; private static final Set DIGIT_ENDING_FUNCTION_NAMES_SET = new HashSet<>(Arrays.asList(DIGIT_ENDING_FUNCTION_NAMES)); + /** + * @param length the max length allowed for FunctionMetadataReader + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max length allowed for FunctionMetadataReader + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + public static FunctionMetadataRegistry createRegistry() { FunctionDataBuilder fdb = new FunctionDataBuilder(800); readResourceFile(fdb, METADATA_FILE_NAME); 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 1a0052e08b..1fc9573ee0 100644 --- a/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java +++ b/poi/src/main/java/org/apache/poi/util/LZWDecompresser.java @@ -40,7 +40,8 @@ public abstract class LZWDecompresser { public static final int DICT_MASK = 0xFFF; //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; /** * Does the mask bit mean it's compressed or uncompressed? @@ -59,6 +60,20 @@ public abstract class LZWDecompresser { */ private final boolean positionIsBigEndian; + /** + * @param length the max length allowed for LZWDecompresser + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max length allowed for LZWDecompresser + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + protected LZWDecompresser(boolean maskMeansCompressed, int codeLengthIncrease, boolean positionIsBigEndian) { this.maskMeansCompressed = maskMeansCompressed; 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 c635a536cd..c805dd4517 100644 --- a/poi/src/main/java/org/apache/poi/util/StringUtil.java +++ b/poi/src/main/java/org/apache/poi/util/StringUtil.java @@ -29,12 +29,27 @@ import java.util.Locale; @Internal public final class StringUtil { //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 10000000; + private static final int DEFAULT_MAX_RECORD_LENGTH = 10000000; + private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; public static final Charset UTF16LE = StandardCharsets.UTF_16LE; public static final Charset UTF8 = StandardCharsets.UTF_8; public static final Charset WIN_1252 = Charset.forName("cp1252"); + /** + * @param length the max length allowed for StringUtil + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max length allowed for StringUtil + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + private StringUtil() { // no instances of this class } -- 2.39.5