From 5b554e753474e8ae31cb777635fb7ab214899f8d Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Fri, 22 Oct 2021 20:53:54 +0000 Subject: [PATCH] more support for configurable max record len git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894493 13f79535-47bb-0310-9956-ffa450edef68 --- .../hemf/usermodel/HemfEmbeddedIterator.java | 17 ++++++++++++- .../org/apache/poi/hpbf/model/EscherPart.java | 17 ++++++++++++- .../apache/poi/hpbf/model/QuillContents.java | 4 +-- .../java/org/apache/poi/hslf/blip/DIB.java | 6 ++--- .../org/apache/poi/hslf/record/CString.java | 20 +-------------- .../poi/hslf/record/CurrentUserAtom.java | 14 +++++------ .../apache/poi/hslf/record/DocumentAtom.java | 22 ++++++++-------- .../apache/poi/hslf/record/ExEmbedAtom.java | 5 +--- .../apache/poi/hslf/record/ExMediaAtom.java | 7 ++---- .../apache/poi/hslf/record/ExObjListAtom.java | 25 +++---------------- .../poi/hslf/record/FontEntityAtom.java | 5 +--- .../record/HSLFEscherClientDataRecord.java | 5 +--- .../org/apache/poi/hslf/record/NotesAtom.java | 8 ++---- .../apache/poi/hslf/record/RecordAtom.java | 22 ++++++++++++++-- .../org/apache/poi/hslf/record/SlideAtom.java | 5 +--- .../poi/hslf/record/StyleTextPropAtom.java | 6 ++--- .../apache/poi/hslf/record/TextBytesAtom.java | 4 +-- .../apache/poi/hslf/record/TextCharsAtom.java | 6 ++--- .../poi/hslf/record/TextSpecInfoRun.java | 5 +--- .../hslf/record/TxInteractiveInfoAtom.java | 5 +--- .../poi/hslf/record/TestDocumentAtom.java | 2 +- 21 files changed, 91 insertions(+), 119 deletions(-) diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java b/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java index da67f62fa5..0faf461808 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hemf/usermodel/HemfEmbeddedIterator.java @@ -49,11 +49,26 @@ import org.apache.poi.util.IOUtils; public class HemfEmbeddedIterator implements Iterator { //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 final Deque> iterStack = new ArrayDeque<>(); private Object current; + /** + * @param length the max record length allowed for HemfEmbeddedIterator + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max record length allowed for HemfEmbeddedIterator + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + public HemfEmbeddedIterator(HemfPicture emf) { this(emf.getRecords().iterator()); } 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 c8de838553..42f5ab66cd 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 @@ -31,7 +31,22 @@ import org.apache.poi.util.IOUtils; public abstract class EscherPart extends HPBFPart { //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 CString + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max record length allowed for CString + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } private EscherRecord[] records; diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/QuillContents.java b/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/QuillContents.java index 4ec6add0e9..cd571679c2 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/QuillContents.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hpbf/model/QuillContents.java @@ -35,8 +35,6 @@ import org.apache.poi.util.LocaleUtil; */ public final class QuillContents extends HPBFPart { private static final Logger LOG = LogManager.getLogger(QuillContents.class); - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; private static final String[] PATH = { "Quill", "QuillSub", "CONTENTS", }; private final QCBit[] bits; @@ -69,7 +67,7 @@ public final class QuillContents extends HPBFPart { int from = (int)LittleEndian.getUInt(data, offset+16); int len = (int)LittleEndian.getUInt(data, offset+20); - byte[] bitData = IOUtils.safelyClone(data, from, len, MAX_RECORD_LENGTH); + byte[] bitData = IOUtils.safelyClone(data, from, len, EscherPart.getMaxRecordLength()); // Create if(bitType.equals("TEXT")) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/DIB.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/DIB.java index 8f30cef3ca..7fb2513fc3 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/DIB.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/blip/DIB.java @@ -19,6 +19,7 @@ package org.apache.poi.hslf.blip; import org.apache.poi.ddf.EscherBSERecord; import org.apache.poi.ddf.EscherContainerRecord; +import org.apache.poi.hslf.record.RecordAtom; import org.apache.poi.hslf.usermodel.HSLFSlideShow; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; @@ -30,9 +31,6 @@ import org.apache.poi.util.Removal; */ public final class DIB extends Bitmap { - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; - /** * Size of the BITMAPFILEHEADER structure preceding the actual DIB bytes */ @@ -118,7 +116,7 @@ public final class DIB extends Bitmap { LittleEndian.putInt(header, 10, offset); //DIB data is the header + dib bytes - byte[] dib = IOUtils.safelyAllocate(header.length + (long)data.length, MAX_RECORD_LENGTH); + byte[] dib = IOUtils.safelyAllocate(header.length + (long)data.length, RecordAtom.getMaxRecordLength()); System.arraycopy(header, 0, dib, 0, header.length); System.arraycopy(data, 0, dib, header.length, data.length); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CString.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CString.java index e0004baeee..0edd3cd95e 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CString.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CString.java @@ -36,10 +36,6 @@ import org.apache.poi.util.StringUtil; public final class CString extends RecordAtom { - //arbitrarily selected; may need to increase - private static final int DEFAULT_MAX_RECORD_LENGTH = 1_000_000; - private static int MAX_RECORD_LENGTH = 1_000_000; - private byte[] _header; /** The bytes that make up the text */ @@ -50,20 +46,6 @@ public final class CString extends RecordAtom { return StringUtil.getFromUnicodeLE(_text); } - /** - * @param length the max record length allowed for CString - */ - public static void setMaxRecordLength(int length) { - MAX_RECORD_LENGTH = length; - } - - /** - * @return the max record length allowed for CString - */ - public static int getMaxRecordLength() { - return MAX_RECORD_LENGTH; - } - /** Updates the text in the Atom. */ public void setText(String text) { // Convert to little endian unicode @@ -103,7 +85,7 @@ public final class CString extends RecordAtom { _header = Arrays.copyOfRange(source, start, start+8); // Grab the text - _text = IOUtils.safelyClone(source,start+8, len-8, MAX_RECORD_LENGTH); + _text = IOUtils.safelyClone(source,start+8, len-8, getMaxRecordLength()); } /** * Create an empty CString diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CurrentUserAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CurrentUserAtom.java index 7a2e413dff..9d54004166 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CurrentUserAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/CurrentUserAtom.java @@ -21,6 +21,7 @@ package org.apache.poi.hslf.record; import static org.apache.logging.log4j.util.Unbox.box; +import static org.apache.poi.hslf.record.RecordAtom.getMaxRecordLength; import static org.apache.poi.hslf.usermodel.HSLFSlideShow.PP95_DOCUMENT; import java.io.IOException; @@ -44,11 +45,8 @@ import org.apache.poi.util.StringUtil; * PowerPoint document. Instead, it lives in a separate stream in the * document. As such, it has to be treated specially */ -public class CurrentUserAtom -{ +public class CurrentUserAtom { private static final Logger LOG = LogManager.getLogger(CurrentUserAtom.class); - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; /** Standard Atom header */ private static final byte[] atomHeader = new byte[] { 0, 0, -10, 15 }; @@ -132,7 +130,7 @@ public class CurrentUserAtom // Grab the contents try (InputStream in = dir.createDocumentInputStream("Current User")) { - _contents = IOUtils.toByteArray(in, docProps.getSize(), MAX_RECORD_LENGTH); + _contents = IOUtils.toByteArray(in, docProps.getSize(), getMaxRecordLength()); } // See how long it is. If it's under 28 bytes long, we can't @@ -212,7 +210,7 @@ public class CurrentUserAtom // 4 = revision // 3 * len = ascii + unicode int size = 8 + 20 + 4 + (3 * lastEditUser.length()); - _contents = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH); + _contents = IOUtils.safelyAllocate(size, getMaxRecordLength()); // First we have a 8 byte atom header System.arraycopy(atomHeader,0,_contents,0,4); @@ -231,7 +229,7 @@ public class CurrentUserAtom // The username gets stored twice, once as US // ascii, and again as unicode laster on - byte[] asciiUN = IOUtils.safelyAllocate(lastEditUser.length(), MAX_RECORD_LENGTH); + byte[] asciiUN = IOUtils.safelyAllocate(lastEditUser.length(), getMaxRecordLength()); StringUtil.putCompressedUnicode(lastEditUser,asciiUN,0); // Now we're able to do the length of the last edited user @@ -253,7 +251,7 @@ public class CurrentUserAtom LittleEndian.putInt(_contents,28+asciiUN.length,(int)releaseVersion); // username in unicode - byte [] ucUN = IOUtils.safelyAllocate(lastEditUser.length() * 2L, MAX_RECORD_LENGTH); + byte [] ucUN = IOUtils.safelyAllocate(lastEditUser.length() * 2L, getMaxRecordLength()); StringUtil.putUnicodeLE(lastEditUser,ucUN,0); System.arraycopy(ucUN,0,_contents,28+asciiUN.length+4,ucUN.length); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/DocumentAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/DocumentAtom.java index 4388aa0704..06cd97984f 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/DocumentAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/DocumentAtom.java @@ -60,11 +60,6 @@ public final class DocumentAtom extends RecordAtom { } - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; - - - private final byte[] _header = new byte[8]; private static final long _type = RecordTypes.DocumentAtom.typeID; @@ -111,13 +106,16 @@ public final class DocumentAtom extends RecordAtom { public int getFirstSlideNum() { return firstSlideNum; } /** - * The Size of the Document's slides, @see DocumentAtom.SlideSize for values - * @deprecated to be replaced by enum + * The Size of the Document's slides, {@link DocumentAtom.SlideSize} for values. */ - @Deprecated - @Removal(version = "5.0.0") - public int getSlideSizeType() { return slideSizeType; } + public SlideSize getSlideSizeType() { return SlideSize.values()[slideSizeType]; } + /** + * The Size of the Document's slides, {@link DocumentAtom.SlideSize} for values. + * @deprecated replaced by {@link #getSlideSizeType()} + */ + @Deprecated + @Removal(version = "6.0.0") public SlideSize getSlideSizeTypeEnum() { return SlideSize.values()[slideSizeType]; } @@ -126,7 +124,7 @@ public final class DocumentAtom extends RecordAtom { slideSizeType = size.ordinal(); } - /** Was the document saved with True Type fonts embeded? */ + /** Was the document saved with True Type fonts embedded? */ public boolean getSaveWithFonts() { return saveWithFonts != 0; } @@ -190,7 +188,7 @@ public final class DocumentAtom extends RecordAtom { showComments = leis.readByte(); // If there's any other bits of data, keep them about - reserved = IOUtils.safelyAllocate(maxLen-48L, MAX_RECORD_LENGTH); + reserved = IOUtils.safelyAllocate(maxLen-48L, getMaxRecordLength()); leis.readFully(reserved); } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExEmbedAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExEmbedAtom.java index 08ac291bdf..247b14900d 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExEmbedAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExEmbedAtom.java @@ -43,9 +43,6 @@ import org.apache.poi.util.LittleEndian; */ public class ExEmbedAtom extends RecordAtom { - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; - /** * Embedded document does not follow the color scheme. */ @@ -96,7 +93,7 @@ public class ExEmbedAtom 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 8 bytes long if(_data.length < 8) { diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExMediaAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExMediaAtom.java index c65d1a5603..46dedd9f96 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExMediaAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExMediaAtom.java @@ -33,10 +33,7 @@ import org.apache.poi.util.LittleEndian; /** * An atom record that specifies information about external audio or video data. */ -public final class ExMediaAtom extends RecordAtom -{ - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; +public final class ExMediaAtom extends RecordAtom { /** * A bit that specifies whether the audio or video data is repeated continuously during playback. @@ -91,7 +88,7 @@ public final class ExMediaAtom 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/ExObjListAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExObjListAtom.java index 2baf3f400c..3bf3a006a3 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExObjListAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/ExObjListAtom.java @@ -29,15 +29,10 @@ import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; /** - * Tne atom that holds the seed info used by a ExObjList + * The atom that holds the seed info used by a ExObjList */ -public class ExObjListAtom extends RecordAtom -{ - - //arbitrarily selected; may need to increase - private static final int DEFAULT_MAX_RECORD_LENGTH = 1_000_000; - private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH; +public class ExObjListAtom extends RecordAtom{ /** * Record header. @@ -49,20 +44,6 @@ public class ExObjListAtom extends RecordAtom */ private byte[] _data; - /** - * @param length the max record length allowed for MasterTextPropAtom - */ - public static void setMaxRecordLength(int length) { - MAX_RECORD_LENGTH = length; - } - - /** - * @return the max record length allowed for MasterTextPropAtom - */ - public static int getMaxRecordLength() { - return MAX_RECORD_LENGTH; - } - /** * Constructs a brand new link related atom record. */ @@ -89,7 +70,7 @@ public class ExObjListAtom 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/FontEntityAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/FontEntityAtom.java index 43c1f15190..f172611896 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/FontEntityAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/FontEntityAtom.java @@ -42,9 +42,6 @@ import org.apache.poi.util.StringUtil; public final class FontEntityAtom extends RecordAtom { - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; - private static final int[] FLAGS_MASKS = { 0x0001, 0x0100, 0x0200, 0x0400, 0x0800 }; @@ -75,7 +72,7 @@ public final class FontEntityAtom 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/HSLFEscherClientDataRecord.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java index 47efe8e829..328efb1b29 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java @@ -38,9 +38,6 @@ import org.apache.poi.util.LittleEndian; */ public class HSLFEscherClientDataRecord extends EscherClientDataRecord { - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; - private final List _childRecords = new ArrayList<>(); public HSLFEscherClientDataRecord() {} @@ -68,7 +65,7 @@ public class HSLFEscherClientDataRecord extends EscherClientDataRecord { @Override public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { int bytesRemaining = readHeader( data, offset ); - byte[] remainingData = IOUtils.safelyClone(data, offset+8, bytesRemaining, MAX_RECORD_LENGTH); + byte[] remainingData = IOUtils.safelyClone(data, offset+8, bytesRemaining, RecordAtom.getMaxRecordLength()); setRemainingData(remainingData); return bytesRemaining + 8; } diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/NotesAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/NotesAtom.java index 5e4664293d..606cb042c8 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/NotesAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/NotesAtom.java @@ -32,11 +32,7 @@ import org.apache.poi.util.LittleEndian; * as what slide it is tied to */ -public final class NotesAtom extends RecordAtom -{ - - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; +public final class NotesAtom extends RecordAtom { private byte[] _header; private static long _type = 1009l; @@ -81,7 +77,7 @@ public final class NotesAtom extends RecordAtom followMasterObjects = (flags & 1) == 1; // There might be 2 more bytes, which are a reserved field - reserved = IOUtils.safelyClone(source, start+14, len-14, MAX_RECORD_LENGTH); + reserved = IOUtils.safelyClone(source, start+14, len-14, getMaxRecordLength()); } /** 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 58b87a6355..c4026720e4 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 @@ -21,8 +21,26 @@ package org.apache.poi.hslf.record; * Abstract class which all atom records will extend. */ -public abstract class RecordAtom extends Record -{ +public abstract class RecordAtom extends Record { + + //arbitrarily selected; may need to increase + 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 CString + */ + public static void setMaxRecordLength(int length) { + MAX_RECORD_LENGTH = length; + } + + /** + * @return the max record length allowed for CString + */ + public static int getMaxRecordLength() { + return MAX_RECORD_LENGTH; + } + /** * We are an atom */ diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/SlideAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/SlideAtom.java index 3760f2d2ce..b7dcd38220 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/SlideAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/SlideAtom.java @@ -38,9 +38,6 @@ public final class SlideAtom extends RecordAtom { public static final int USES_MASTER_SLIDE_ID = 0x80000000; // private static final int MASTER_SLIDE_ID = 0x00000000; - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; - private byte[] _header; private static long _type = 1007l; @@ -103,7 +100,7 @@ public final class SlideAtom extends RecordAtom { // If there's any other bits of data, keep them about // 8 bytes header + 20 bytes to flags + 2 bytes flags = 30 bytes - reserved = IOUtils.safelyClone(source,start+30, len-30, MAX_RECORD_LENGTH); + reserved = IOUtils.safelyClone(source,start+30, len-30, getMaxRecordLength()); } /** diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/StyleTextPropAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/StyleTextPropAtom.java index d7e30b3532..62773615e0 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/StyleTextPropAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/StyleTextPropAtom.java @@ -52,8 +52,6 @@ import org.apache.poi.util.LittleEndian; public final class StyleTextPropAtom extends RecordAtom { public static final long _type = RecordTypes.StyleTextPropAtom.typeID; - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; private final byte[] _header; private byte[] reserved; @@ -136,7 +134,7 @@ public final class StyleTextPropAtom extends RecordAtom { // Save the contents of the atom, until we're asked to go and // decode them (via a call to setParentTextSize(int) - rawContents = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH); + rawContents = IOUtils.safelyClone(source, start+8, len-8, getMaxRecordLength()); reserved = new byte[0]; // Set empty lists, ready for when they call setParentTextSize @@ -401,7 +399,7 @@ public final class StyleTextPropAtom extends RecordAtom { out.append(" original byte stream \n"); - byte[] buf = IOUtils.safelyAllocate(rawContents.length + (long)reserved.length, MAX_RECORD_LENGTH); + byte[] buf = IOUtils.safelyAllocate(rawContents.length + (long)reserved.length, getMaxRecordLength()); System.arraycopy(rawContents, 0, buf, 0, rawContents.length); System.arraycopy(reserved, 0, buf, rawContents.length, reserved.length); out.append( HexDump.dump(buf, 0, 0) ); diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextBytesAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextBytesAtom.java index 341693db9b..4ea4e767e9 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextBytesAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextBytesAtom.java @@ -38,8 +38,6 @@ import org.apache.poi.util.StringUtil; public final class TextBytesAtom extends RecordAtom { public static final long _type = RecordTypes.TextBytesAtom.typeID; - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; private byte[] _header; @@ -73,7 +71,7 @@ public final class TextBytesAtom extends RecordAtom { _header = Arrays.copyOfRange(source, start, start+8); // Grab the text - _text = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH); + _text = IOUtils.safelyClone(source, start+8, len-8, getMaxRecordLength()); } /** diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextCharsAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextCharsAtom.java index 4fd297387d..fdc973935d 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextCharsAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextCharsAtom.java @@ -36,8 +36,6 @@ import org.apache.poi.util.StringUtil; public final class TextCharsAtom extends RecordAtom { public static final long _type = RecordTypes.TextCharsAtom.typeID; - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; private byte[] _header; @@ -52,7 +50,7 @@ public final class TextCharsAtom extends RecordAtom { /** Updates the text in the Atom. */ public void setText(String text) { // Convert to little endian unicode - _text = IOUtils.safelyAllocate(text.length() * 2L, MAX_RECORD_LENGTH); + _text = IOUtils.safelyAllocate(text.length() * 2L, getMaxRecordLength()); StringUtil.putUnicodeLE(text,_text,0); // Update the size (header bytes 5-8) @@ -72,7 +70,7 @@ public final class TextCharsAtom extends RecordAtom { _header = Arrays.copyOfRange(source, start, start+8); // Grab the text - _text = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH); + _text = IOUtils.safelyClone(source, start+8, len-8, getMaxRecordLength()); } /** * Create an empty TextCharsAtom diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextSpecInfoRun.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextSpecInfoRun.java index 9c890a2b56..c42e5349d4 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextSpecInfoRun.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TextSpecInfoRun.java @@ -35,9 +35,6 @@ import org.apache.poi.util.LittleEndianByteArrayInputStream; public class TextSpecInfoRun implements GenericRecord { - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; - /** * A enum that specifies the spelling status of a run of text. */ @@ -176,7 +173,7 @@ public class TextSpecInfoRun implements GenericRecord { if (smartTagFld.isSet(mask)) { // An unsigned integer specifies the count of items in rgSmartTagIndex. int count = source.readInt(); - smartTagsBytes = IOUtils.safelyAllocate(4 + count * 4L, MAX_RECORD_LENGTH); + smartTagsBytes = IOUtils.safelyAllocate(4 + count * 4L, RecordAtom.getMaxRecordLength()); LittleEndian.putInt(smartTagsBytes, 0, count); // An array of SmartTagIndex that specifies the indices. // The count of items in the array is specified by count. diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxInteractiveInfoAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxInteractiveInfoAtom.java index 87175331be..995c7b9e3e 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxInteractiveInfoAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/TxInteractiveInfoAtom.java @@ -32,9 +32,6 @@ import org.apache.poi.util.LittleEndian; */ public final class TxInteractiveInfoAtom extends RecordAtom { - //arbitrarily selected; may need to increase - private static final int MAX_RECORD_LENGTH = 1_000_000; - /** * Record header. */ @@ -69,7 +66,7 @@ public final class TxInteractiveInfoAtom 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/test/java/org/apache/poi/hslf/record/TestDocumentAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestDocumentAtom.java index 34f2480ffe..9cdf6f62c4 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestDocumentAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestDocumentAtom.java @@ -66,7 +66,7 @@ public final class TestDocumentAtom { void testSlideDetails() { DocumentAtom da = new DocumentAtom(data_a, 0, data_a.length); assertEquals(1, da.getFirstSlideNum()); - assertEquals(DocumentAtom.SlideSize.ON_SCREEN, da.getSlideSizeTypeEnum()); + assertEquals(DocumentAtom.SlideSize.ON_SCREEN, da.getSlideSizeType()); } @Test -- 2.39.5