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

poi-excelant/src/main/java9/module-info.class
poi-scratchpad/src/main/java/org/apache/poi/hslf/record/SoundData.java
poi-scratchpad/src/main/java/org/apache/poi/hwmf/record/HwmfText.java
poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocumentCore.java
poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFOldDocument.java
poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/OldTextPieceTable.java
poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/TextPieceTable.java

index bb1e0378df57187faba456c5b5c22861aeb9132d..271b567453affe97d9dd6768cdd2550a29e5991f 100644 (file)
Binary files a/poi-excelant/src/main/java9/module-info.class and b/poi-excelant/src/main/java9/module-info.class differ
index f51e059a21292d69fa5e92dd29d33caf8b4cc34c..57561abd3e8b79fbf14030d6c0714a3a3de4015f 100644 (file)
@@ -34,7 +34,22 @@ public final class SoundData extends RecordAtom {
 
 
     //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 SoundData
+     */
+    public static void setMaxRecordLength(int length) {
+        MAX_RECORD_LENGTH = length;
+    }
+
+    /**
+     * @return the max record length allowed for SoundData
+     */
+    public static int getMaxRecordLength() {
+        return MAX_RECORD_LENGTH;
+    }
 
     /**
      * Record header.
index 6f72d2865036863b9abe18a83d2fd0683f4935fb..f81c7dd49ca2bf0524828aaf3670c32b2a2c0f80 100644 (file)
@@ -49,7 +49,22 @@ import org.apache.poi.util.LocaleUtil;
 
 public class HwmfText {
     private static final Logger LOG = LogManager.getLogger(HwmfText.class);
-    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 HwmfText
+     */
+    public static void setMaxRecordLength(int length) {
+        MAX_RECORD_LENGTH = length;
+    }
+
+    /**
+     * @return the max record length allowed for HwmfText
+     */
+    public static int getMaxRecordLength() {
+        return MAX_RECORD_LENGTH;
+    }
 
     /**
      * The META_SETTEXTCHAREXTRA record defines inter-character spacing for text justification in the
index 66c3b51bcc338da8f941c38f65ca370daa377f96..08815263cf5ebab938dbc776e01cb85cc45ca1bb 100644 (file)
@@ -67,7 +67,22 @@ public abstract class HWPFDocumentCore extends POIDocument {
     protected static final String STREAM_TABLE_1 = "1Table";
 
     //arbitrarily selected; may need to increase
-    private static final int MAX_RECORD_LENGTH = 500_000_000;
+    private static final int DEFAULT_MAX_RECORD_LENGTH = 500_000_000;
+    private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
+
+    /**
+     * @param length the max record length allowed for HWPFDocumentCore
+     */
+    public static void setMaxRecordLength(int length) {
+        MAX_RECORD_LENGTH = length;
+    }
+
+    /**
+     * @return the max record length allowed for HWPFDocumentCore
+     */
+    public static int getMaxRecordLength() {
+        return MAX_RECORD_LENGTH;
+    }
 
     /**
      * Size of the not encrypted part of the FIB
index a5a3d441cb36ffb10e95c891e102efd4af4e38dc..fa2310b7ef1a44ba93604def791cd0707393a6ef 100644 (file)
@@ -46,15 +46,29 @@ import org.apache.poi.util.NotImplemented;
 import org.apache.poi.util.StringUtil;
 
 /**
- * Provides very simple support for old (Word 6 / Word 95)
- *  files.
+ * Provides very simple support for old (Word 6 / Word 95) files.
  */
 public class HWPFOldDocument extends HWPFDocumentCore {
 
     private static final Logger LOG = LogManager.getLogger(HWPFOldDocument.class);
 
     //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;
+
+    /**
+     * @param length the max record length allowed for HWPFOldDocument
+     */
+    public static void setMaxRecordLength(int length) {
+        MAX_RECORD_LENGTH = length;
+    }
+
+    /**
+     * @return the max record length allowed for HWPFOldDocument
+     */
+    public static int getMaxRecordLength() {
+        return MAX_RECORD_LENGTH;
+    }
 
     private static final Charset DEFAULT_CHARSET = StringUtil.WIN_1252;
 
index 478af6a272719cf9648a99b46d23f4992e401f33..384803469e179caf6a78dbcd96385b69e787cfa9 100644 (file)
@@ -26,8 +26,6 @@ import org.apache.poi.util.Internal;
 
 @Internal
 public class OldTextPieceTable extends TextPieceTable {
-    //arbitrarily selected; may need to increase
-    private static final int MAX_RECORD_LENGTH = 100_000_000;
 
     public OldTextPieceTable() {
         super();
@@ -82,7 +80,7 @@ public class OldTextPieceTable extends TextPieceTable {
             int textSizeBytes = textSizeChars * multiple;
 
             // Grab the data that makes up the piece
-            byte[] buf = IOUtils.safelyClone(documentStream, start, textSizeBytes, MAX_RECORD_LENGTH);
+            byte[] buf = IOUtils.safelyClone(documentStream, start, textSizeBytes, getMaxRecordLength());
 
             // And now build the piece
             final TextPiece newTextPiece = newTextPiece(nodeStartChars, nodeEndChars, buf, pieces[x]);
index 5f8c4da5ee415ea8c0419f8d620b736bbaf5df11..ded50c135764d8ea82a7cfd2165f310175413b19 100644 (file)
@@ -36,13 +36,28 @@ import static org.apache.logging.log4j.util.Unbox.box;
 /**
  * The piece table for matching up character positions to bits of text. This
  * mostly works in bytes, but the TextPieces themselves work in characters. This
- * does the icky convertion.
+ * does the icky conversion.
  */
 @Internal
 public class TextPieceTable implements CharIndexTranslator {
     private static final Logger LOG = LogManager.getLogger(TextPieceTable.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;
+
+    /**
+     * @param length the max record length allowed for TextPieceTable
+     */
+    public static void setMaxRecordLength(int length) {
+        MAX_RECORD_LENGTH = length;
+    }
+
+    /**
+     * @return the max record length allowed for TextPieceTable
+     */
+    public static int getMaxRecordLength() {
+        return MAX_RECORD_LENGTH;
+    }
 
 
     // int _multiple;