From: PJ Fanning Date: Fri, 22 Oct 2021 21:08:53 +0000 (+0000) Subject: more support for configurable max record len X-Git-Tag: REL_5_2_0~317 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c0cc8811145ebed58b0e380e802d263d12da96c4;p=poi.git more support for configurable max record len git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894494 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfText.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfText.java index 9a8f629afc..b7b7ef698c 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfText.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/record/emf/HemfText.java @@ -52,7 +52,22 @@ import org.apache.poi.util.RecordFormatException; @SuppressWarnings("WeakerAccess") public class HemfText { - 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 HemfText + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max record length allowed for HemfText + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } public enum EmfGraphicsMode { GM_COMPATIBLE, GM_ADVANCED diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hmef/dev/HMEFDumper.java b/poi-scratchpad/src/main/java/org/apache/poi/hmef/dev/HMEFDumper.java index d0019cebf4..72f40b65f9 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hmef/dev/HMEFDumper.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hmef/dev/HMEFDumper.java @@ -38,7 +38,22 @@ import org.apache.poi.util.LittleEndian; public final class HMEFDumper { //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 HMEFDumper + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max record length allowed for HMEFDumper + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } public static void main(String[] args) throws Exception { if(args.length < 1) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherPart.java b/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherPart.java index 42f5ab66cd..44cc2aee7f 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherPart.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/EscherPart.java @@ -35,14 +35,14 @@ public abstract class EscherPart extends HPBFPart { private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; /** - * @param length the max record length allowed for CString + * @param length the max record length allowed for EscherPart */ public static void setMaxRecordLength(int length) { MAX_RECORD_LENGTH = length; } /** - * @return the max record length allowed for CString + * @return the max record length allowed for EscherPart */ public static int getMaxRecordLength() { return MAX_RECORD_LENGTH; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/AnimationInfoAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/AnimationInfoAtom.java index 95e076e83b..e686ab0ca4 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/AnimationInfoAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/AnimationInfoAtom.java @@ -34,9 +34,6 @@ import org.apache.poi.util.LittleEndian; */ public final class AnimationInfoAtom extends RecordAtom { - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; - /** * whether the animation plays in the reverse direction */ @@ -127,7 +124,7 @@ public final class AnimationInfoAtom extends RecordAtom { _header = Arrays.copyOfRange(source, start, start+8); // Grab the record data - _recdata = IOUtils.safelyClone(source,start+8, len-8, MAX_RECORD_LENGTH); + _recdata = IOUtils.safelyClone(source,start+8, len-8, getMaxRecordLength()); } /** diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/Comment2000Atom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/Comment2000Atom.java index 07b9457b5f..1d984d6e19 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/Comment2000Atom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/Comment2000Atom.java @@ -33,11 +33,7 @@ import org.apache.poi.util.LittleEndian; * An atomic record containing information about a comment. */ -public final class Comment2000Atom extends RecordAtom -{ - - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; +public final class Comment2000Atom extends RecordAtom { /** * Record header. @@ -74,7 +70,7 @@ public final class Comment2000Atom extends RecordAtom _header = Arrays.copyOfRange(source, start, start+8); // Get the record data. - _data = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH); + _data = IOUtils.safelyClone(source, start+8, len-8, getMaxRecordLength()); } /** diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExHyperlinkAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExHyperlinkAtom.java index a0765a43e3..e73f7cbaf5 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExHyperlinkAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExHyperlinkAtom.java @@ -33,9 +33,6 @@ import org.apache.poi.util.LittleEndian; */ public final class ExHyperlinkAtom extends RecordAtom { - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; - /** * Record header. */ @@ -72,7 +69,7 @@ public final class ExHyperlinkAtom extends RecordAtom { _header = Arrays.copyOfRange(source, start, start+8); // Get the record data. - _data = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH); + _data = IOUtils.safelyClone(source, start+8, len-8, getMaxRecordLength()); // Must be at least 4 bytes long if(_data.length < 4) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HeadersFootersAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HeadersFootersAtom.java index eca4eb2704..552ec50ff0 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HeadersFootersAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HeadersFootersAtom.java @@ -61,9 +61,6 @@ public final class HeadersFootersAtom extends RecordAtom { CHINESE3 } - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; - /** * A bit that specifies whether the date is displayed in the footer. * @see #getMask() @@ -144,7 +141,7 @@ public final class HeadersFootersAtom extends RecordAtom { _header = Arrays.copyOfRange(source, start, start+8); // Grab the record data - _recdata = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH); + _recdata = IOUtils.safelyClone(source, start+8, len-8, getMaxRecordLength()); } /** diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/InteractiveInfoAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/InteractiveInfoAtom.java index fbe51f35eb..fe48a9395f 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/InteractiveInfoAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/InteractiveInfoAtom.java @@ -36,9 +36,6 @@ import org.apache.poi.util.LittleEndian; */ public class InteractiveInfoAtom extends RecordAtom { - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; - public enum Action { NONE, MACRO, @@ -154,7 +151,7 @@ public class InteractiveInfoAtom extends RecordAtom { _header = Arrays.copyOfRange(source, start, start+8); // Get the record data. - _data = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH); + _data = IOUtils.safelyClone(source, start+8, len-8, getMaxRecordLength()); // Must be at least 16 bytes long if(_data.length < 16) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PersistPtrHolder.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PersistPtrHolder.java index 92772e1413..db3482f0aa 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PersistPtrHolder.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/PersistPtrHolder.java @@ -45,11 +45,7 @@ import org.apache.poi.util.LittleEndianConsts; * (via CurrentUserAtom and UserEditAtom) pointing to the new slide location */ -public final class PersistPtrHolder extends PositionDependentRecordAtom -{ - - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; +public final class PersistPtrHolder extends PositionDependentRecordAtom { private final byte[] _header; private byte[] _ptrData; // Will need to update this once we allow updates to _slideLocations @@ -113,7 +109,7 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom // count * 32 bit offsets // Repeat as many times as you have data _slideLocations = new HashMap<>(); - _ptrData = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH); + _ptrData = IOUtils.safelyClone(source, start+8, len-8, RecordAtom.getMaxRecordLength()); int pos = 0; while(pos < _ptrData.length) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/RecordAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/RecordAtom.java index c4026720e4..cd1e77901e 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/RecordAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/RecordAtom.java @@ -28,14 +28,14 @@ public abstract class RecordAtom extends Record { private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; /** - * @param length the max record length allowed for CString + * @param length the max record length allowed for RecordAtom */ public static void setMaxRecordLength(int length) { MAX_RECORD_LENGTH = length; } /** - * @return the max record length allowed for CString + * @return the max record length allowed for RecordAtom */ public static int getMaxRecordLength() { return MAX_RECORD_LENGTH; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextRulerAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextRulerAtom.java index a9b083b236..d9e18a30d0 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextRulerAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextRulerAtom.java @@ -42,9 +42,6 @@ import org.apache.poi.util.LittleEndianOutputStream; */ public final class TextRulerAtom extends RecordAtom { - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; - private static final BitField DEFAULT_TAB_SIZE = getInstance(0x0001); private static final BitField C_LEVELS = getInstance(0x0002); private static final BitField TAB_STOPS = getInstance(0x0004); @@ -87,7 +84,7 @@ public final class TextRulerAtom extends RecordAtom { * @param len the length of the slice in the byte array. */ TextRulerAtom(final byte[] source, final int start, final int len) { - final LittleEndianByteArrayInputStream leis = new LittleEndianByteArrayInputStream(source, start, Math.min(len, MAX_RECORD_LENGTH)); + final LittleEndianByteArrayInputStream leis = new LittleEndianByteArrayInputStream(source, start, Math.min(len, getMaxRecordLength())); try { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextSpecInfoAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextSpecInfoAtom.java index da2a40ffba..aa71d41540 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextSpecInfoAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextSpecInfoAtom.java @@ -38,9 +38,6 @@ import org.apache.poi.util.LittleEndianByteArrayInputStream; */ public final class TextSpecInfoAtom extends RecordAtom { - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; - private static final long _type = RecordTypes.TextSpecInfoAtom.typeID; /** @@ -75,7 +72,7 @@ public final class TextSpecInfoAtom extends RecordAtom { _header = Arrays.copyOfRange(source, start, start+8); // Get the record data. - _data = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH); + _data = IOUtils.safelyClone(source, start+8, len-8, getMaxRecordLength()); } /** * Gets the record type. diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxMasterStyleAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxMasterStyleAtom.java index ee419faf31..ca94a6acfd 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxMasterStyleAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxMasterStyleAtom.java @@ -54,8 +54,6 @@ import org.apache.poi.util.LittleEndianOutputStream; */ public final class TxMasterStyleAtom extends RecordAtom { private static final Logger LOG = LogManager.getLogger(TxMasterStyleAtom.class); - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; /** * Maximum number of indentation levels allowed in PowerPoint documents @@ -73,7 +71,7 @@ public final class TxMasterStyleAtom extends RecordAtom { protected TxMasterStyleAtom(byte[] source, int start, int len) { _header = Arrays.copyOfRange(source, start, start+8); - _data = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH); + _data = IOUtils.safelyClone(source, start+8, len-8, getMaxRecordLength()); //read available styles try { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocument.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocument.java index 6571c650af..e103c3367b 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocument.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/HWPFDocument.java @@ -83,7 +83,8 @@ public final class HWPFDocument extends HWPFDocumentCore { /*package*/ static final String PROPERTY_PRESERVE_BIN_TABLES = "org.apache.poi.hwpf.preserveBinTables"; private static final String PROPERTY_PRESERVE_TEXT_TABLE = "org.apache.poi.hwpf.preserveTextTable"; //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; + private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000; + private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; private static final String STREAM_DATA = "Data"; @@ -193,6 +194,20 @@ public final class HWPFDocument extends HWPFDocumentCore { */ private Fields _fields; + /** + * @param length the max record length allowed for HWPFDocument + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max record length allowed for HWPFDocument + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + /** * This constructor loads a Word document from an InputStream. * diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java index 91dfcf6c1f..50948b8869 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.sprm.SprmBuffer; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; @@ -42,36 +43,16 @@ import org.apache.poi.util.RecordFormatException; * differently for CHP fkps and PAP fkps. */ @Internal -public final class CHPFormattedDiskPage extends FormattedDiskPage -{ +public final class CHPFormattedDiskPage extends FormattedDiskPage { private static final int FC_SIZE = 4; - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; - private ArrayList _chpxList = new ArrayList<>(); private ArrayList _overFlow; - public CHPFormattedDiskPage() { } - /** - * This constructs a CHPFormattedDiskPage from a raw fkp (512 byte array - * read from a Word file). - * - * @deprecated Use - * {@link #CHPFormattedDiskPage(byte[], int, CharIndexTranslator)} - * instead - */ - @Deprecated - public CHPFormattedDiskPage( byte[] documentStream, int offset, int fcMin, - TextPieceTable tpt ) - { - this( documentStream, offset, tpt ); - } - /** * This constructs a CHPFormattedDiskPage from a raw fkp (512 byte array * read from a Word file). @@ -138,7 +119,7 @@ public final class CHPFormattedDiskPage extends FormattedDiskPage int size = LittleEndian.getUByte(_fkp, _offset + chpxOffset); - return IOUtils.safelyClone(_fkp, _offset + chpxOffset + 1, size, MAX_RECORD_LENGTH); + return IOUtils.safelyClone(_fkp, _offset + chpxOffset + 1, size, HWPFDocument.getMaxRecordLength()); } protected byte[] toByteArray( CharIndexTranslator translator ) diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/ComplexFileTable.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/ComplexFileTable.java index 7dc6081cc5..22eaadae52 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/ComplexFileTable.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/ComplexFileTable.java @@ -23,6 +23,7 @@ import java.nio.charset.Charset; import java.util.LinkedList; import java.util.List; +import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.model.io.HWPFFileSystem; import org.apache.poi.hwpf.sprm.SprmBuffer; import org.apache.poi.util.IOUtils; @@ -34,9 +35,6 @@ import org.apache.poi.util.StringUtil; @Internal public class ComplexFileTable { - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; - private static final byte GRPPRL_TYPE = 1; private static final byte TEXT_PIECE_TABLE_TYPE = 2; @@ -57,7 +55,7 @@ public class ComplexFileTable { offset++; int size = LittleEndian.getShort(tableStream, offset); offset += LittleEndianConsts.SHORT_SIZE; - byte[] bs = IOUtils.safelyClone(tableStream, offset, size, MAX_RECORD_LENGTH); + byte[] bs = IOUtils.safelyClone(tableStream, offset, size, HWPFDocument.getMaxRecordLength()); offset += size; SprmBuffer sprmBuffer = new SprmBuffer(bs, false, 0); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/DocumentProperties.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/DocumentProperties.java index 963c0f5942..40ccd73cc5 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/DocumentProperties.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/DocumentProperties.java @@ -20,34 +20,16 @@ package org.apache.poi.hwpf.model; import java.io.ByteArrayOutputStream; import java.io.IOException; +import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.model.types.DOPAbstractType; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; @Internal -public final class DocumentProperties extends DOPAbstractType -{ - - //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; +public final class DocumentProperties extends DOPAbstractType { private byte[] _preserved; - /** - * @param length the max record length allowed for DocumentProperties - */ - public static void setMaxRecordLength(int length) { - MAX_RECORD_LENGTH = length; - } - - /** - * @return the max record length allowed for DocumentProperties - */ - public static int getMaxRecordLength() { - return MAX_RECORD_LENGTH; - } - /** * @deprecated Use {@link #DocumentProperties(byte[],int,int)} instead */ @@ -63,7 +45,8 @@ public final class DocumentProperties extends DOPAbstractType final int supportedSize = DOPAbstractType.getSize(); if ( length != supportedSize ) { - this._preserved = IOUtils.safelyClone( tableStream, offset + supportedSize, length - supportedSize, MAX_RECORD_LENGTH ); + this._preserved = IOUtils.safelyClone( tableStream, offset + supportedSize, + length - supportedSize, HWPFDocument.getMaxRecordLength()); } else { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/Ffn.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/Ffn.java index 346f5aabf8..bea8b2e581 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/Ffn.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/Ffn.java @@ -19,6 +19,7 @@ package org.apache.poi.hwpf.model; import java.util.Arrays; +import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.IOUtils; @@ -34,10 +35,6 @@ import org.apache.poi.util.LittleEndianConsts; @Internal public final class Ffn { - //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 int _cbFfnM1;//total length of FFN - 1. private byte _info; private static BitField _prq = BitFieldFactory.getInstance(0x0003);// pitch request @@ -57,20 +54,6 @@ public final class Ffn { // extra facilitator members private int _xszFfnLength; - /** - * @param length the max record length allowed for Ffn - */ - public static void setMaxRecordLength(int length) { - MAX_RECORD_LENGTH = length; - } - - /** - * @return the max record length allowed for Ffn - */ - public static int getMaxRecordLength() { - return MAX_RECORD_LENGTH; - } - public Ffn(byte[] buf, int offset) { int offsetTmp = offset; @@ -155,7 +138,7 @@ public final class Ffn { // changed protected to public public byte[] toByteArray() { int offset = 0; - byte[] buf = IOUtils.safelyAllocate(this.getSize(), MAX_RECORD_LENGTH); + byte[] buf = IOUtils.safelyAllocate(this.getSize(), HWPFDocument.getMaxRecordLength()); buf[offset] = (byte) _cbFfnM1; offset += LittleEndianConsts.BYTE_SIZE; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/FileInformationBlock.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/FileInformationBlock.java index 9c29edc297..a3b7086580 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/FileInformationBlock.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/FileInformationBlock.java @@ -26,6 +26,7 @@ import java.util.Locale; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.model.types.FibBaseAbstractType; import org.apache.poi.hwpf.model.types.FibRgLw97AbstractType; import org.apache.poi.hwpf.model.types.FibRgW97AbstractType; @@ -50,9 +51,6 @@ import static org.apache.logging.log4j.util.Unbox.box; @Internal public final class FileInformationBlock { - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; - private static final Logger LOG = LogManager.getLogger(FileInformationBlock.class); private final FibBase _fibBase; @@ -124,7 +122,7 @@ public final class FileInformationBlock { // first short is already read as _nFibNew final int fibRgCswNewLength = ( _cswNew - 1 ) * LittleEndianConsts.SHORT_SIZE; - _fibRgCswNew = IOUtils.safelyClone(mainDocument, offset, fibRgCswNewLength, MAX_RECORD_LENGTH); + _fibRgCswNew = IOUtils.safelyClone(mainDocument, offset, fibRgCswNewLength, HWPFDocument.getMaxRecordLength()); } else { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/PICFAndOfficeArtData.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/PICFAndOfficeArtData.java index fb34604169..59163a578c 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/PICFAndOfficeArtData.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/PICFAndOfficeArtData.java @@ -25,17 +25,14 @@ import org.apache.poi.ddf.EscherBlipRecord; import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherRecord; import org.apache.poi.ddf.EscherRecordTypes; +import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.model.types.PICFAbstractType; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; @Internal -public class PICFAndOfficeArtData -{ - - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; +public class PICFAndOfficeArtData { /** * Can contain either a {@link EscherBlipRecord} or a {@link EscherBSERecord}. @@ -65,7 +62,7 @@ public class PICFAndOfficeArtData short _cchPicName = LittleEndian.getUByte(dataStream, offset); offset += 1; - _stPicName = IOUtils.safelyClone(dataStream, offset, _cchPicName, MAX_RECORD_LENGTH); + _stPicName = IOUtils.safelyClone(dataStream, offset, _cchPicName, HWPFDocument.getMaxRecordLength()); offset += _cchPicName; } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/SectionTable.java b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/SectionTable.java index 547960c185..35e74bf10d 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/SectionTable.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hwpf/model/SectionTable.java @@ -24,6 +24,7 @@ import java.util.List; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.model.io.HWPFFileSystem; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; @@ -31,11 +32,7 @@ import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; @Internal -public class SectionTable -{ - - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 100_000; +public class SectionTable { private static final Logger LOG = LogManager.getLogger(SectionTable.class); private static final int SED_SIZE = 12; @@ -82,7 +79,7 @@ public class SectionTable // The first short at the offset is the size of the grpprl. int sepxSize = LittleEndian.getShort(documentStream, fileOffset); fileOffset += LittleEndianConsts.SHORT_SIZE; - byte[] buf = IOUtils.safelyClone(documentStream, fileOffset, sepxSize, MAX_RECORD_LENGTH); + byte[] buf = IOUtils.safelyClone(documentStream, fileOffset, sepxSize, HWPFDocument.getMaxRecordLength()); _sections.add(new SEPX(sed, startAt, endAt, buf)); } } diff --git a/poi/src/test/java9/module-info.class b/poi/src/test/java9/module-info.class index 438e778ab5..028b943d0a 100644 Binary files a/poi/src/test/java9/module-info.class and b/poi/src/test/java9/module-info.class differ