aboutsummaryrefslogtreecommitdiffstats
path: root/poi
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2021-10-24 09:37:37 +0000
committerPJ Fanning <fanningpj@apache.org>2021-10-24 09:37:37 +0000
commite823df80293490f6d6763e089ab3e74887da25b8 (patch)
tree93b7e75f366b076a9974ed92cb3ae8096f6df47d /poi
parent8644c69b4cd01b27992c78046a1dff406ee2861d (diff)
downloadpoi-e823df80293490f6d6763e089ab3e74887da25b8.tar.gz
poi-e823df80293490f6d6763e089ab3e74887da25b8.zip
configurable max record len
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894525 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
-rw-r--r--poi/src/main/java/org/apache/poi/ddf/EscherComplexProperty.java17
-rw-r--r--poi/src/main/java/org/apache/poi/hpsf/Thumbnail.java16
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/DrawingGroupRecord.java29
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java16
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java17
-rw-r--r--poi/src/test/java/org/apache/poi/hssf/record/TestDrawingGroupRecord.java2
6 files changed, 87 insertions, 10 deletions
diff --git a/poi/src/main/java/org/apache/poi/ddf/EscherComplexProperty.java b/poi/src/main/java/org/apache/poi/ddf/EscherComplexProperty.java
index 1f33cd735a..c001707c6c 100644
--- a/poi/src/main/java/org/apache/poi/ddf/EscherComplexProperty.java
+++ b/poi/src/main/java/org/apache/poi/ddf/EscherComplexProperty.java
@@ -32,11 +32,26 @@ import org.apache.poi.util.LittleEndian;
*/
public class EscherComplexProperty extends EscherProperty {
//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 byte[] complexData;
/**
+ * @param length the max record length allowed for EscherComplexProperty
+ */
+ public static void setMaxRecordLength(int length) {
+ MAX_RECORD_LENGTH = length;
+ }
+
+ /**
+ * @return the max record length allowed for EscherComplexProperty
+ */
+ public static int getMaxRecordLength() {
+ return MAX_RECORD_LENGTH;
+ }
+
+ /**
* Create a complex property using the property id and a byte array containing the complex
* data value size.
*
diff --git a/poi/src/main/java/org/apache/poi/hpsf/Thumbnail.java b/poi/src/main/java/org/apache/poi/hpsf/Thumbnail.java
index 66f5f178fa..396462203a 100644
--- a/poi/src/main/java/org/apache/poi/hpsf/Thumbnail.java
+++ b/poi/src/main/java/org/apache/poi/hpsf/Thumbnail.java
@@ -19,6 +19,7 @@ package org.apache.poi.hpsf;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndian;
+
/**
* <p>Class to manipulate data in the Clipboard Variant ({@link
* Variant#VT_CF VT_CF}) format.</p>
@@ -121,7 +122,8 @@ public final class Thumbnail {
public static final int CF_BITMAP = 2;
//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;
/**
* <p>A <code>byte[]</code> to hold a thumbnail image in ({@link
@@ -129,7 +131,19 @@ public final class Thumbnail {
*/
private byte[] _thumbnailData;
+ /**
+ * @param length the max record length allowed for SubRecord
+ */
+ public static void setMaxRecordLength(int length) {
+ MAX_RECORD_LENGTH = length;
+ }
+ /**
+ * @return the max record length allowed for SubRecord
+ */
+ public static int getMaxRecordLength() {
+ return MAX_RECORD_LENGTH;
+ }
/**
* <p>Default Constructor. If you use it then one you'll have to add
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/DrawingGroupRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/DrawingGroupRecord.java
index 4dbbb70b58..91d805a381 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/DrawingGroupRecord.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/DrawingGroupRecord.java
@@ -38,8 +38,26 @@ import org.apache.poi.util.Removal;
public final class DrawingGroupRecord extends AbstractEscherHolderRecord {
public static final short sid = 0xEB;
- static final int MAX_RECORD_SIZE = 8228;
- private static final int MAX_DATA_SIZE = MAX_RECORD_SIZE - 4;
+ private static final int DEFAULT_MAX_RECORD_SIZE = 8228;
+ private static int MAX_RECORD_SIZE = DEFAULT_MAX_RECORD_SIZE;
+
+ /**
+ * @param size the max record size allowed for DrawingGroupRecord
+ */
+ public static void setMaxRecordSize(int size) {
+ MAX_RECORD_SIZE = size;
+ }
+
+ /**
+ * @return the max record size allowed for DrawingGroupRecord
+ */
+ public static int getMaxRecordSize() {
+ return MAX_RECORD_SIZE;
+ }
+
+ private static int getMaxDataSize() {
+ return MAX_RECORD_SIZE - 4;
+ }
public DrawingGroupRecord() {}
@@ -112,7 +130,7 @@ public final class DrawingGroupRecord extends AbstractEscherHolderRecord {
static int grossSizeFromDataSize(int dataSize)
{
- return dataSize + ( (dataSize - 1) / MAX_DATA_SIZE + 1 ) * 4;
+ return dataSize + ( (dataSize - 1) / getMaxDataSize() + 1 ) * 4;
}
private int writeData( int offset, byte[] data, byte[] rawData )
@@ -121,8 +139,9 @@ public final class DrawingGroupRecord extends AbstractEscherHolderRecord {
int writtenRawData = 0;
while (writtenRawData < rawData.length)
{
- int segmentLength = Math.min( rawData.length - writtenRawData, MAX_DATA_SIZE);
- if (writtenRawData / MAX_DATA_SIZE >= 2)
+ final int maxDataSize = getMaxDataSize();
+ int segmentLength = Math.min( rawData.length - writtenRawData, maxDataSize);
+ if (writtenRawData / maxDataSize >= 2)
writeContinueHeader( data, offset, segmentLength );
else
writeHeader( data, offset, segmentLength );
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java b/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java
index 8a1925e102..53e836dc00 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java
@@ -92,8 +92,22 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
// not a real sid - dummy value
public static final short sid = 9876;
//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;
+ /**
+ * @param length the max record length allowed for EscherAggregate
+ */
+ public static void setMaxRecordLength(int length) {
+ MAX_RECORD_LENGTH = length;
+ }
+
+ /**
+ * @return the max record length allowed for EscherAggregate
+ */
+ public static int getMaxRecordLength() {
+ return MAX_RECORD_LENGTH;
+ }
/** @deprecated not used */
@Deprecated
diff --git a/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java b/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java
index 6138fcbb71..246d6cc62e 100644
--- a/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java
+++ b/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java
@@ -86,7 +86,22 @@ public abstract class SubRecord implements Duplicatable, GenericRecord {
//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;
+
+ /**
+ * @param length the max record length allowed for SubRecord
+ */
+ public static void setMaxRecordLength(int length) {
+ MAX_RECORD_LENGTH = length;
+ }
+
+ /**
+ * @return the max record length allowed for SubRecord
+ */
+ public static int getMaxRecordLength() {
+ return MAX_RECORD_LENGTH;
+ }
protected SubRecord() {}
diff --git a/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingGroupRecord.java b/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingGroupRecord.java
index e7c97e86ec..099dcf440e 100644
--- a/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingGroupRecord.java
+++ b/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingGroupRecord.java
@@ -26,7 +26,7 @@ import org.apache.poi.util.HexDump;
import org.junit.jupiter.api.Test;
final class TestDrawingGroupRecord {
- private static final int MAX_RECORD_SIZE = 8228;
+ private static final int MAX_RECORD_SIZE = DrawingGroupRecord.getMaxRecordSize();
private static final int MAX_DATA_SIZE = MAX_RECORD_SIZE - 4;
@Test