public class HemfEmbeddedIterator implements Iterator<HwmfEmbedded> {
//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<Iterator<?>> 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());
}
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;
*/
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;
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")) {
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;
*/
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
*/
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);
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 */
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
_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
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;
* 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 };
// 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
// 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);
// 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
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);
}
- //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;
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];
}
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;
}
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);
}
*/
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.
*/
_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) {
/**
* 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.
_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());
}
/**
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.
*/
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.
*/
_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) {
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
};
_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());
}
/**
*/
public class HSLFEscherClientDataRecord extends EscherClientDataRecord {
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 1_000_000;
-
private final List<org.apache.poi.hslf.record.Record> _childRecords = new ArrayList<>();
public HSLFEscherClientDataRecord() {}
@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;
}
* 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;
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());
}
/**
* 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
*/
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;
// 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());
}
/**
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;
// 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
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) );
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;
_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());
}
/**
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;
/** 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)
_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
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.
*/
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.
*/
public final class TxInteractiveInfoAtom extends RecordAtom {
- //arbitrarily selected; may need to increase
- private static final int MAX_RECORD_LENGTH = 1_000_000;
-
/**
* Record header.
*/
_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());
}
/**
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