more support for configurable max record len

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894494 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-10-22 21:08:53 +00:00
parent 5b554e7534
commit c0cc881114
22 changed files with 82 additions and 128 deletions

View File

@ -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

View File

@ -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) {

View File

@ -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;

View File

@ -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());
}
/**

View File

@ -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());
}
/**

View File

@ -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) {

View File

@ -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());
}
/**

View File

@ -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) {

View File

@ -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) {

View File

@ -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;

View File

@ -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 {

View File

@ -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.

View File

@ -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 {

View File

@ -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.
*

View File

@ -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<CHPX> _chpxList = new ArrayList<>();
private ArrayList<CHPX> _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 )

View File

@ -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);

View File

@ -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
{

View File

@ -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;

View File

@ -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
{

View File

@ -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;
}

View File

@ -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));
}
}

Binary file not shown.