From c0cc8811145ebed58b0e380e802d263d12da96c4 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 22 Oct 2021 21:08:53 +0000 Subject: [PATCH] more support for configurable max record len git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894494 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hemf/record/emf/HemfText.java | 17 +++++++++++- .../org/apache/poi/hmef/dev/HMEFDumper.java | 17 +++++++++++- .../org/apache/poi/hpbf/model/EscherPart.java | 4 +-- .../poi/hslf/record/AnimationInfoAtom.java | 5 +--- .../poi/hslf/record/Comment2000Atom.java | 8 ++---- .../poi/hslf/record/ExHyperlinkAtom.java | 5 +--- .../poi/hslf/record/HeadersFootersAtom.java | 5 +--- .../poi/hslf/record/InteractiveInfoAtom.java | 5 +--- .../poi/hslf/record/PersistPtrHolder.java | 8 ++---- .../apache/poi/hslf/record/RecordAtom.java | 4 +-- .../apache/poi/hslf/record/TextRulerAtom.java | 5 +--- .../poi/hslf/record/TextSpecInfoAtom.java | 5 +--- .../poi/hslf/record/TxMasterStyleAtom.java | 4 +-- .../org/apache/poi/hwpf/HWPFDocument.java | 17 +++++++++++- .../poi/hwpf/model/CHPFormattedDiskPage.java | 25 +++--------------- .../poi/hwpf/model/ComplexFileTable.java | 6 ++--- .../poi/hwpf/model/DocumentProperties.java | 25 +++--------------- .../java/org/apache/poi/hwpf/model/Ffn.java | 21 ++------------- .../poi/hwpf/model/FileInformationBlock.java | 6 ++--- .../poi/hwpf/model/PICFAndOfficeArtData.java | 9 +++---- .../apache/poi/hwpf/model/SectionTable.java | 9 +++---- poi/src/test/java9/module-info.class | Bin 4198 -> 4145 bytes 22 files changed, 82 insertions(+), 128 deletions(-) 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 438e778ab515b0d480b1fb79ccaffeeafa4e55c6..028b943d0ae7577c19f08d4b20ce352134f4f685 100644 GIT binary patch literal 4145 zcmai1`Fj*a5PgH_iXbRkf)@fR9w<9RgZF``2r7z1#ak!4lg%W%Gvmx`LOk)l@B6;* z`}Xq({{a6eKkL=*Cd2Fy^L=?Q(_P(NU9Y;j^UuG3{S9Cf{;c3G2ZxMAouuw>4O+f~ z!`e}!)ABb2;aF6g@TNQm2ko$?D!eL29aM&fY8z`q8>^^S(Wt_&Vyud$+MQ7w8m00%V!_>lM34$HK}Rqpm=^32%n0rg+$*?G zaKGRI!GnUmf`zBx!?=Imx8YZUkknwd@J}) z@O>3O2!5>KrwV?q;Fk)1t>Cu`ey`vU2a9u2bg(>1nl&%>>f?SbjspHVSj6DgM!i&n zzB*@6kJ{}hOl$S1)$;3EpnnfLII`5D;ny7;+8@#Ovhgz=EE$QtB=xrh*@&O*JF*ou zn?cyDDGyJmrMb{+?0+`=bTW%#2g@cJleJEmcH%fnGQXiKg??5Woyq*sPNOm7;0QW3 z(Fuc0F%B|6(Ov4+%-Mb0)g`Z;I#{Yh+-@jb3j^oKHMrf)bVD-O?sif?(b)Q$OzTQV z&RMu)QJCqHjDCKmMq{k&V!qMelOVQ=xt!{2qY5%m}YE6dGbXYQL z%2`(yXVq4>;ZHd@uB^wO^24mR{p0s*kc(06|Bc*6r`?`O{CbqA!~@%)L%D4pRW@PI zqod3E`V$w`8t25_PS_3NQ!>gWQ+yvZ5) zQ(no%Q81vVlf3TcS#7Kn+STl!n9I4z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