Author: fanningpj
Date: Sun Oct 24 09:37:37 2021
New Revision: 1894525

URL: http://svn.apache.org/viewvc?rev=1894525&view=rev
Log:
configurable max record len

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

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/ddf/EscherComplexProperty.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ddf/EscherComplexProperty.java?rev=1894525&r1=1894524&r2=1894525&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ddf/EscherComplexProperty.java 
(original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ddf/EscherComplexProperty.java 
Sun Oct 24 09:37:37 2021
@@ -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.
      *

Modified: poi/trunk/poi/src/main/java/org/apache/poi/hpsf/Thumbnail.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hpsf/Thumbnail.java?rev=1894525&r1=1894524&r2=1894525&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hpsf/Thumbnail.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hpsf/Thumbnail.java Sun Oct 24 
09:37:37 2021
@@ -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

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/DrawingGroupRecord.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/DrawingGroupRecord.java?rev=1894525&r1=1894524&r2=1894525&view=diff
==============================================================================
--- 
poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/DrawingGroupRecord.java 
(original)
+++ 
poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/DrawingGroupRecord.java 
Sun Oct 24 09:37:37 2021
@@ -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 ex
 
     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 ex
         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 );

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java?rev=1894525&r1=1894524&r2=1894525&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java 
(original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/EscherAggregate.java 
Sun Oct 24 09:37:37 2021
@@ -92,8 +92,22 @@ public final class EscherAggregate exten
     // 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

Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java?rev=1894525&r1=1894524&r2=1894525&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java 
(original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/SubRecord.java Sun 
Oct 24 09:37:37 2021
@@ -86,7 +86,22 @@ public abstract class SubRecord implemen
 
 
     //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() {}
 

Modified: 
poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingGroupRecord.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingGroupRecord.java?rev=1894525&r1=1894524&r2=1894525&view=diff
==============================================================================
--- 
poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingGroupRecord.java
 (original)
+++ 
poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestDrawingGroupRecord.java
 Sun Oct 24 09:37:37 2021
@@ -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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to