]> source.dussan.org Git - poi.git/commitdiff
configurable max record len
authorPJ Fanning <fanningpj@apache.org>
Sun, 24 Oct 2021 09:37:37 +0000 (09:37 +0000)
committerPJ Fanning <fanningpj@apache.org>
Sun, 24 Oct 2021 09:37:37 +0000 (09:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894525 13f79535-47bb-0310-9956-ffa450edef68

poi/src/main/java/org/apache/poi/ddf/EscherComplexProperty.java
poi/src/main/java/org/apache/poi/hpsf/Thumbnail.java
poi/src/main/java/org/apache/poi/hssf/record/DrawingGroupRecord.java
poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java
poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java
poi/src/test/java/org/apache/poi/hssf/record/TestDrawingGroupRecord.java

index 1f33cd735ada64558515beab352c4c4b4c08c42e..c001707c6c4e56c66b8d50ad68ba2348ed1af43c 100644 (file)
@@ -32,10 +32,25 @@ 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.
index 66f5f178fa5345069f4ad6a7c6b72e1c9068bc22..396462203a5b63beb05b589762a8efc4809146a8 100644 (file)
@@ -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
index 4dbbb70b58d73d40a4779526239d4fe23a3498fe..91d805a381f9c7371dc7caa1411995e593e65936 100644 (file)
@@ -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 );
index 8a1925e102e9f7406f60674cc29470d4112c6b2c..53e836dc007087fda56a0467ee612104e1b506cc 100644 (file)
@@ -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
index 6138fcbb714289a7cfa4416bee533d7f85687b46..246d6cc62ed78f9370783245c4ef27c58e02eaeb 100644 (file)
@@ -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() {}
 
index e7c97e86ec9e88f48482902bd9bcd46d33ff6357..099dcf440ee8f23b41b29c98c1365c4f87a4ce98 100644 (file)
@@ -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