aboutsummaryrefslogtreecommitdiffstats
path: root/poi/src
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-10-23 21:13:08 +0000
committerPJ Fanning <fanningpj@apache.org>2021-10-23 21:13:08 +0000
commit8644c69b4cd01b27992c78046a1dff406ee2861d (patch)
treeffccd674385b820bcf4276fd0db0fa82de031ed0 /poi/src
parentc1ae6ef0e9c37f502b58f70be5a041815f76b71b (diff)
downloadpoi-8644c69b4cd01b27992c78046a1dff406ee2861d.tar.gz
poi-8644c69b4cd01b27992c78046a1dff406ee2861d.zip
configurable max record len
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894516 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi/src')
-rw-r--r--poi/src/main/java/org/apache/poi/hpsf/Section.java4
-rw-r--r--poi/src/main/java/org/apache/poi/hpsf/UnicodeString.java4
-rw-r--r--poi/src/main/java/org/apache/poi/hpsf/VariantSupport.java6
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/extractor/OldExcelExtractor.java20
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/CFRule12Record.java10
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java6
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java5
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/GroupMarkerSubRecord.java6
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/HyperlinkRecord.java6
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/OldLabelRecord.java5
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/OldSheetRecord.java6
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/OldStringRecord.java6
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java7
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/common/ExtRst.java5
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8DecryptingStream.java26
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/dev/POIFSDump.java4
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSDocument.java4
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java2
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/property/PropertyTable.java5
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java6
20 files changed, 40 insertions, 103 deletions
diff --git a/poi/src/main/java/org/apache/poi/hpsf/Section.java b/poi/src/main/java/org/apache/poi/hpsf/Section.java
index 13ae9af603..5636dbd400 100644
--- a/poi/src/main/java/org/apache/poi/hpsf/Section.java
+++ b/poi/src/main/java/org/apache/poi/hpsf/Section.java
@@ -45,8 +45,6 @@ import org.apache.poi.util.LittleEndianOutputStream;
* Represents a section in a {@link PropertySet}.
*/
public class Section {
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
private static final Logger LOG = LogManager.getLogger(Section.class);
@@ -830,7 +828,7 @@ public class Section {
}
try {
- byte[] buf = IOUtils.safelyAllocate(nrBytes, MAX_RECORD_LENGTH);
+ byte[] buf = IOUtils.safelyAllocate(nrBytes, CodePageString.getMaxRecordLength());
leis.readFully(buf, 0, nrBytes);
final String str = CodePageUtil.getStringFromCodePage(buf, 0, nrBytes, cp);
diff --git a/poi/src/main/java/org/apache/poi/hpsf/UnicodeString.java b/poi/src/main/java/org/apache/poi/hpsf/UnicodeString.java
index 866a2b2acd..e89e47e5a0 100644
--- a/poi/src/main/java/org/apache/poi/hpsf/UnicodeString.java
+++ b/poi/src/main/java/org/apache/poi/hpsf/UnicodeString.java
@@ -33,15 +33,13 @@ import org.apache.poi.util.StringUtil;
@Internal
public class UnicodeString {
private static final Logger LOG = LogManager.getLogger(UnicodeString.class);
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
private byte[] _value;
public void read(LittleEndianByteArrayInputStream lei) {
final int length = lei.readInt();
final int unicodeBytes = length*2;
- _value = IOUtils.safelyAllocate(unicodeBytes, MAX_RECORD_LENGTH);
+ _value = IOUtils.safelyAllocate(unicodeBytes, CodePageString.getMaxRecordLength());
// If Length is zero, this field MUST be zero bytes in length. If Length is
// nonzero, this field MUST be a null-terminated array of 16-bit Unicode characters, followed by
diff --git a/poi/src/main/java/org/apache/poi/hpsf/VariantSupport.java b/poi/src/main/java/org/apache/poi/hpsf/VariantSupport.java
index e1720b66b1..1a0cce110c 100644
--- a/poi/src/main/java/org/apache/poi/hpsf/VariantSupport.java
+++ b/poi/src/main/java/org/apache/poi/hpsf/VariantSupport.java
@@ -59,8 +59,6 @@ public class VariantSupport extends Variant {
private static final Logger LOG = LogManager.getLogger(VariantSupport.class);
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
private static boolean logUnsupportedTypes;
@@ -176,7 +174,7 @@ public class VariantSupport extends Variant {
typedPropertyValue.readValue(lei);
} catch ( UnsupportedOperationException exc ) {
try {
- final byte[] v = IOUtils.toByteArray(lei, length, MAX_RECORD_LENGTH);
+ final byte[] v = IOUtils.toByteArray(lei, length, CodePageString.getMaxRecordLength());
throw new ReadingNotSupportedException( type, v );
} catch (IOException e) {
throw new RuntimeException(e);
@@ -254,7 +252,7 @@ public class VariantSupport extends Variant {
default:
final int unpadded = lei.getReadIndex()-offset;
lei.setReadIndex(offset);
- final byte[] v = IOUtils.safelyAllocate(unpadded, MAX_RECORD_LENGTH);
+ final byte[] v = IOUtils.safelyAllocate(unpadded, CodePageString.getMaxRecordLength());
lei.readFully( v, 0, unpadded );
throw new ReadingNotSupportedException( type, v );
}
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 d50ec09d4d..ac1ca9541c 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
@@ -41,6 +41,7 @@ import org.apache.poi.hssf.record.OldSheetRecord;
import org.apache.poi.hssf.record.OldStringRecord;
import org.apache.poi.hssf.record.RKRecord;
import org.apache.poi.hssf.record.RecordInputStream;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.DocumentNode;
import org.apache.poi.poifs.filesystem.FileMagic;
@@ -62,9 +63,6 @@ import org.apache.poi.util.IOUtils;
public class OldExcelExtractor implements POITextExtractor {
private static final int FILE_PASS_RECORD_SID = 0x2f;
- //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 RecordInputStream ris;
@@ -74,20 +72,6 @@ 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);
}
@@ -316,7 +300,7 @@ public class OldExcelExtractor implements POITextExtractor {
break;
default:
- ris.readFully(IOUtils.safelyAllocate(ris.remaining(), MAX_RECORD_LENGTH));
+ ris.readFully(IOUtils.safelyAllocate(ris.remaining(), HSSFWorkbook.getMaxRecordLength()));
}
}
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/CFRule12Record.java b/poi/src/main/java/org/apache/poi/hssf/record/CFRule12Record.java
index fad2fb11a1..4381c52a18 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/CFRule12Record.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/CFRule12Record.java
@@ -42,6 +42,7 @@ import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndianOutput;
import static org.apache.logging.log4j.util.Unbox.box;
+import static org.apache.poi.hssf.usermodel.HSSFWorkbook.getMaxRecordLength;
/**
* Conditional Formatting v12 Rule Record (0x087A).
@@ -55,9 +56,6 @@ import static org.apache.logging.log4j.util.Unbox.box;
*/
public final class CFRule12Record extends CFRuleBase implements FutureRecord {
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
-
public static final short sid = 0x087A;
private FtrHeader futureHeader;
@@ -123,7 +121,7 @@ public final class CFRule12Record extends CFRuleBase implements FutureRecord {
priority = 0;
template_type = getConditionType();
template_param_length = 16;
- template_params = IOUtils.safelyAllocate(template_param_length, MAX_RECORD_LENGTH);
+ template_params = IOUtils.safelyAllocate(template_param_length, getMaxRecordLength());
}
/**
@@ -267,7 +265,7 @@ public final class CFRule12Record extends CFRuleBase implements FutureRecord {
} else {
long len = readFormatOptions(in);
if (len < ext_formatting_length) {
- ext_formatting_data = IOUtils.safelyAllocate(ext_formatting_length-len, MAX_RECORD_LENGTH);
+ ext_formatting_data = IOUtils.safelyAllocate(ext_formatting_length-len, getMaxRecordLength());
in.readFully(ext_formatting_data);
}
}
@@ -283,7 +281,7 @@ public final class CFRule12Record extends CFRuleBase implements FutureRecord {
template_type = in.readUShort();
template_param_length = in.readByte();
if (template_param_length == 0 || template_param_length == 16) {
- template_params = IOUtils.safelyAllocate(template_param_length, MAX_RECORD_LENGTH);
+ template_params = IOUtils.safelyAllocate(template_param_length, getMaxRecordLength());
in.readFully(template_params);
} else {
LOG.atWarn().log("CF Rule v12 template params length should be 0 or 16, found {}", box(template_param_length));
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java
index 98d3112e2d..2ef4f34cfb 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/DConRefRecord.java
@@ -23,6 +23,7 @@ import java.util.Map;
import java.util.function.Supplier;
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndianOutput;
@@ -72,9 +73,6 @@ import org.apache.poi.util.StringUtil;
*/
public class DConRefRecord extends StandardRecord {
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
-
/**
* The id of the record type,
* <code>sid = {@value}</code>
@@ -158,7 +156,7 @@ public class DConRefRecord extends StandardRecord {
// single-byte, 1 if double-byte.
final int byteLength = charCount * (charType + 1);
- path = IOUtils.safelyAllocate(byteLength, MAX_RECORD_LENGTH);
+ path = IOUtils.safelyAllocate(byteLength, HSSFWorkbook.getMaxRecordLength());
inStream.readFully(path);
// If it's a self reference, the last one or two bytes (depending on char type) are the
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
index dab3a2f4b9..07e801175b 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/EmbeddedObjectRefSubRecord.java
@@ -24,6 +24,7 @@ import java.util.function.Supplier;
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.ptg.Area3DPtg;
import org.apache.poi.ss.formula.ptg.AreaPtg;
import org.apache.poi.ss.formula.ptg.Ptg;
@@ -47,8 +48,6 @@ import static org.apache.logging.log4j.util.Unbox.box;
*/
public final class EmbeddedObjectRefSubRecord extends SubRecord {
private static final Logger LOG = LogManager.getLogger(EmbeddedObjectRefSubRecord.class);
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
public static final short sid = 0x0009;
@@ -202,7 +201,7 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
if (size == 0) {
return EMPTY_BYTE_ARRAY;
}
- byte[] result = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
+ byte[] result = IOUtils.safelyAllocate(size, HSSFWorkbook.getMaxRecordLength());
in.readFully(result);
return result;
}
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/GroupMarkerSubRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/GroupMarkerSubRecord.java
index dcbf4ee7d8..64c751a22d 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/GroupMarkerSubRecord.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/GroupMarkerSubRecord.java
@@ -20,6 +20,7 @@ package org.apache.poi.hssf.record;
import java.util.Map;
import java.util.function.Supplier;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndianInput;
@@ -31,9 +32,6 @@ import org.apache.poi.util.LittleEndianOutput;
*/
public final class GroupMarkerSubRecord extends SubRecord {
public static final short sid = 0x0006;
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
-
private static final byte[] EMPTY_BYTE_ARRAY = { };
@@ -54,7 +52,7 @@ public final class GroupMarkerSubRecord extends SubRecord {
}
GroupMarkerSubRecord(LittleEndianInput in, int size, int cmoOt) {
- byte[] buf = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
+ byte[] buf = IOUtils.safelyAllocate(size, HSSFWorkbook.getMaxRecordLength());
in.readFully(buf);
reserved = buf;
}
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/HyperlinkRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/HyperlinkRecord.java
index 78bda25262..c6acf98336 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/HyperlinkRecord.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/HyperlinkRecord.java
@@ -31,6 +31,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.hpsf.ClassID;
import org.apache.poi.hpsf.ClassIDPredefined;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.HexRead;
@@ -48,9 +49,6 @@ import org.apache.poi.util.StringUtil;
public final class HyperlinkRecord extends StandardRecord {
public static final short sid = 0x01B8;
private static final Logger LOG = LogManager.getLogger(HyperlinkRecord.class);
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
-
/*
* Link flags
@@ -391,7 +389,7 @@ public final class HyperlinkRecord extends StandardRecord {
int len = in.readInt();
- byte[] path_bytes = IOUtils.safelyAllocate(len, MAX_RECORD_LENGTH);
+ byte[] path_bytes = IOUtils.safelyAllocate(len, HSSFWorkbook.getMaxRecordLength());
in.readFully(path_bytes);
_address = new String(path_bytes, StringUtil.UTF8);
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/OldLabelRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/OldLabelRecord.java
index e393c8e3d8..2ac572c981 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/OldLabelRecord.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/OldLabelRecord.java
@@ -22,6 +22,7 @@ import java.util.function.Supplier;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.RecordFormatException;
@@ -36,8 +37,6 @@ import static org.apache.poi.util.HexDump.toHex;
*/
public final class OldLabelRecord extends OldCellRecord {
private static final Logger LOG = LogManager.getLogger(OldLabelRecord.class);
- //arbitrarily set, may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
public static final short biff2_sid = 0x0004;
public static final short biff345_sid = 0x0204;
@@ -60,7 +59,7 @@ public final class OldLabelRecord extends OldCellRecord {
}
// Can only decode properly later when you know the codepage
- field_5_bytes = IOUtils.safelyAllocate(field_4_string_len, MAX_RECORD_LENGTH);
+ field_5_bytes = IOUtils.safelyAllocate(field_4_string_len, HSSFWorkbook.getMaxRecordLength());
in.read(field_5_bytes, 0, field_4_string_len);
if (in.remaining() > 0) {
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/OldSheetRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/OldSheetRecord.java
index 9f2120c393..24f67bf8b9 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/OldSheetRecord.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/OldSheetRecord.java
@@ -22,6 +22,7 @@ import java.util.Map;
import java.util.function.Supplier;
import org.apache.poi.common.usermodel.GenericRecord;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.GenericRecordJsonWriter;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.IOUtils;
@@ -35,9 +36,6 @@ import org.apache.poi.util.RecordFormatException;
*/
public final class OldSheetRecord implements GenericRecord {
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
-
public static final short sid = 0x0085;
private final int field_1_position_of_BOF;
@@ -64,7 +62,7 @@ public final class OldSheetRecord implements GenericRecord {
}
}
}
- field_5_sheetname = IOUtils.safelyAllocate(field_4_sheetname_length, MAX_RECORD_LENGTH);
+ field_5_sheetname = IOUtils.safelyAllocate(field_4_sheetname_length, HSSFWorkbook.getMaxRecordLength());
in.read(field_5_sheetname, 0, field_4_sheetname_length);
}
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/OldStringRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/OldStringRecord.java
index e81a2aa4b8..0334925cd8 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/OldStringRecord.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/OldStringRecord.java
@@ -23,6 +23,7 @@ import java.util.function.Supplier;
import org.apache.poi.common.usermodel.GenericRecord;
import org.apache.poi.hpsf.Property;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.CodePageUtil;
import org.apache.poi.util.GenericRecordJsonWriter;
import org.apache.poi.util.GenericRecordUtil;
@@ -35,9 +36,6 @@ import org.apache.poi.util.IOUtils;
*/
public final class OldStringRecord implements GenericRecord {
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
-
public static final short biff2_sid = 0x0007;
public static final short biff345_sid = 0x0207;
@@ -59,7 +57,7 @@ public final class OldStringRecord implements GenericRecord {
}
// Can only decode properly later when you know the codepage
- field_2_bytes = IOUtils.safelyAllocate(field_1_string_len, MAX_RECORD_LENGTH);
+ field_2_bytes = IOUtils.safelyAllocate(field_1_string_len, HSSFWorkbook.getMaxRecordLength());
in.read(field_2_bytes, 0, field_1_string_len);
}
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java b/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java
index 5b7b114cdb..6cb3aacb5e 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/RecordInputStream.java
@@ -24,6 +24,7 @@ import java.util.Locale;
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
import org.apache.poi.hssf.dev.BiffViewer;
import org.apache.poi.hssf.record.crypto.Biff8DecryptingStream;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.crypt.EncryptionInfo;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
@@ -39,12 +40,10 @@ import org.apache.poi.util.RecordFormatException;
*/
public final class RecordInputStream implements LittleEndianInput {
-
/** Maximum size of a single record (minus the 4 byte header) without a continue*/
public static final short MAX_RECORD_DATA_SIZE = 8224;
private static final int INVALID_SID_VALUE = -1;
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
+
/**
* When {@link #_currentDataLength} has this value, it means that the previous BIFF record is
* finished, the next sid has been properly read, but the data size field has not been read yet.
@@ -442,7 +441,7 @@ public final class RecordInputStream implements LittleEndianInput {
if (size ==0) {
return EMPTY_BYTE_ARRAY;
}
- byte[] result = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
+ byte[] result = IOUtils.safelyAllocate(size, HSSFWorkbook.getMaxRecordLength());
readFully(result);
return result;
}
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/common/ExtRst.java b/poi/src/main/java/org/apache/poi/hssf/record/common/ExtRst.java
index bb409edcad..ffd0d03eef 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/common/ExtRst.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/common/ExtRst.java
@@ -26,6 +26,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.common.usermodel.GenericRecord;
import org.apache.poi.hssf.record.cont.ContinuableRecordOutput;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.GenericRecordUtil;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
@@ -37,8 +38,6 @@ import static org.apache.logging.log4j.util.Unbox.box;
@Internal
public class ExtRst implements Comparable<ExtRst>, GenericRecord {
private static final Logger LOG = LogManager.getLogger(ExtRst.class);
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
private short reserved;
@@ -126,7 +125,7 @@ public class ExtRst implements Comparable<ExtRst>, GenericRecord {
LOG.atWarn().log("ExtRst overran by {} bytes", box(-extraDataLength));
extraDataLength = 0;
}
- extraData = IOUtils.safelyAllocate(extraDataLength, MAX_RECORD_LENGTH);
+ extraData = IOUtils.safelyAllocate(extraDataLength, HSSFWorkbook.getMaxRecordLength());
for(int i=0; i<extraData.length; i++) {
extraData[i] = in.readByte();
}
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 6f7370d180..d3dbf38ea2 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
@@ -20,10 +20,8 @@ package org.apache.poi.hssf.record.crypto;
import java.io.InputStream;
import java.io.PushbackInputStream;
-import org.apache.poi.hssf.record.BOFRecord;
-import org.apache.poi.hssf.record.BiffHeaderInput;
-import org.apache.poi.hssf.record.FilePassRecord;
-import org.apache.poi.hssf.record.InterfaceHdrRecord;
+import org.apache.poi.hssf.record.*;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.crypt.ChunkedCipherInputStream;
import org.apache.poi.poifs.crypt.Decryptor;
import org.apache.poi.poifs.crypt.EncryptionInfo;
@@ -37,31 +35,15 @@ import org.apache.poi.util.SuppressForbidden;
public final class Biff8DecryptingStream implements BiffHeaderInput, LittleEndianInput {
public static final int RC4_REKEYING_INTERVAL = 1024;
- //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 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);
+ byte[] initialBuf = IOUtils.safelyAllocate(initialOffset, HSSFWorkbook.getMaxRecordLength());
InputStream stream;
if (initialOffset == 0) {
stream = in;
diff --git a/poi/src/main/java/org/apache/poi/poifs/dev/POIFSDump.java b/poi/src/main/java/org/apache/poi/poifs/dev/POIFSDump.java
index fed8c008bf..a0fc8a5214 100644
--- a/poi/src/main/java/org/apache/poi/poifs/dev/POIFSDump.java
+++ b/poi/src/main/java/org/apache/poi/poifs/dev/POIFSDump.java
@@ -39,8 +39,6 @@ import org.apache.poi.util.IOUtils;
* Dump internal structure of a OLE2 file into file system
*/
public final class POIFSDump {
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
private POIFSDump() {}
@@ -125,7 +123,7 @@ public final class POIFSDump {
try (FileOutputStream out = new FileOutputStream(file)) {
POIFSStream stream = new POIFSStream(fs, startBlock);
- byte[] b = IOUtils.safelyAllocate(fs.getBigBlockSize(), MAX_RECORD_LENGTH);
+ byte[] b = IOUtils.safelyAllocate(fs.getBigBlockSize(), POIFSFileSystem.getMaxRecordLength());
for (ByteBuffer bb : stream) {
int len = bb.remaining();
bb.get(b);
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 d8b6b2cd57..e25d4b8fae 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
@@ -143,7 +143,7 @@ public final class POIFSDocument implements POIFSViewable, Iterable<ByteBuffer>
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);
+ byte[] padding = IOUtils.safelyAllocate(toBlockEnd, POIFSFileSystem.getMaxRecordLength());
Arrays.fill(padding, (byte) 0xFF);
os.write(padding);
}
@@ -208,7 +208,7 @@ public final class POIFSDocument implements POIFSViewable, Iterable<ByteBuffer>
if (getSize() > 0) {
// Get all the data into a single array
- byte[] data = IOUtils.safelyAllocate(getSize(), POIFSFileSystem.MAX_RECORD_LENGTH);
+ byte[] data = IOUtils.safelyAllocate(getSize(), POIFSFileSystem.getMaxRecordLength());
int offset = 0;
for (ByteBuffer buffer : _stream) {
int length = Math.min(_block_size, data.length - offset);
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 343aba35d3..7ac3a2ccdd 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
@@ -62,7 +62,7 @@ public class POIFSFileSystem extends BlockStore
implements POIFSViewable, Closeable {
//arbitrarily selected; may need to increase
private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000;
- static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
+ private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
private static final Logger LOG = LogManager.getLogger(POIFSFileSystem.class);
diff --git a/poi/src/main/java/org/apache/poi/poifs/property/PropertyTable.java b/poi/src/main/java/org/apache/poi/poifs/property/PropertyTable.java
index 596bea5070..42f380f341 100644
--- a/poi/src/main/java/org/apache/poi/poifs/property/PropertyTable.java
+++ b/poi/src/main/java/org/apache/poi/poifs/property/PropertyTable.java
@@ -45,9 +45,6 @@ import static org.apache.logging.log4j.util.Unbox.box;
public final class PropertyTable implements BATManaged {
private static final Logger LOG = LogManager.getLogger(PropertyTable.class);
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
-
private final HeaderBlock _header_block;
private final List<Property> _properties = new ArrayList<>();
private final POIFSBigBlockSize _bigBigBlockSize;
@@ -91,7 +88,7 @@ public final class PropertyTable implements BATManaged {
bb.array().length == _bigBigBlockSize.getBigBlockSize()) {
data = bb.array();
} else {
- data = IOUtils.safelyAllocate(_bigBigBlockSize.getBigBlockSize(), MAX_RECORD_LENGTH);
+ data = IOUtils.safelyAllocate(_bigBigBlockSize.getBigBlockSize(), POIFSFileSystem.getMaxRecordLength());
int toRead = data.length;
if (bb.remaining() < _bigBigBlockSize.getBigBlockSize()) {
diff --git a/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java b/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java
index 190afb71dc..e3a450cfa2 100644
--- a/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java
+++ b/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java
@@ -29,6 +29,7 @@ import org.apache.poi.poifs.common.POIFSConstants;
import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.poifs.filesystem.NotOLE2FileException;
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.IntegerField;
@@ -42,9 +43,6 @@ import org.apache.poi.util.ShortField;
*/
public final class HeaderBlock implements HeaderBlockConstants {
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 100_000;
-
private static final byte _default_value = ( byte ) 0xFF;
/**
@@ -108,7 +106,7 @@ public final class HeaderBlock implements HeaderBlockConstants {
// Fetch the rest of the block if needed
if(bigBlockSize.getBigBlockSize() != 512) {
int rest = bigBlockSize.getBigBlockSize() - 512;
- byte[] tmp = IOUtils.safelyAllocate(rest, MAX_RECORD_LENGTH);
+ byte[] tmp = IOUtils.safelyAllocate(rest, POIFSFileSystem.getMaxRecordLength());
IOUtils.readFully(stream, tmp);
}
}