make max record sizes configurable

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894452 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-10-21 16:52:09 +00:00
parent 0727874584
commit dbc6576da4
19 changed files with 299 additions and 37 deletions

View File

@ -32,7 +32,8 @@ import org.apache.poi.util.LittleEndian;
@SuppressWarnings("WeakerAccess")
public class FontEmbeddedData extends RecordAtom implements FontFacet {
//arbitrarily selected; may need to increase (increased due to https://bz.apache.org/bugzilla/show_bug.cgi?id=65639)
private static final int MAX_RECORD_LENGTH = 5_000_000;
private static final int DEFAULT_MAX_RECORD_LENGTH = 5_000_000;
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
/**
* Record header.
@ -49,6 +50,20 @@ public class FontEmbeddedData extends RecordAtom implements FontFacet {
*/
private FontHeader fontHeader;
/**
* @param length the max length allowed for FontEmbeddedData
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for FontEmbeddedData
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
/**
* Constructs a brand new font embedded record.
*/

View File

@ -19,25 +19,37 @@ package org.apache.poi.hwpf.sprm;
import java.util.List;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.*;
@Internal
public final class SprmUtils
{
public final class SprmUtils {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000;
static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
public SprmUtils()
{
/**
* @param length the max length allowed for SPRM data
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
public static byte[] shortArrayToByteArray(short[] convert)
{
/**
* @return the max length allowed for SPRM data
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
public SprmUtils() {}
/**
* @deprecated unused by POI internally
*/
@Removal(version= "6.0.0")
public static byte[] shortArrayToByteArray(short[] convert) {
byte[] buf = IOUtils.safelyAllocate(convert.length * (long)LittleEndianConsts.SHORT_SIZE, MAX_RECORD_LENGTH);
for (int x = 0; x < convert.length; x++)

View File

@ -31,14 +31,10 @@ import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts;
@Internal
public final class TableSprmCompressor
{
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
public final class TableSprmCompressor {
public TableSprmCompressor() {}
public TableSprmCompressor()
{
}
public static byte[] compressTableProperty(TableProperties newTAP)
{
int size = 0;
@ -85,7 +81,7 @@ public final class TableSprmCompressor
1
+ (LittleEndianConsts.SHORT_SIZE*((long)itcMac + 1))
+ (TableCellDescriptor.SIZE*(long)itcMac),
MAX_RECORD_LENGTH);
SprmUtils.MAX_RECORD_LENGTH);
buf[0] = (byte)itcMac;
short[] dxaCenters = newTAP.getRgdxaCenter();

View File

@ -36,7 +36,8 @@ import org.apache.poi.util.LittleEndian;
public final class EscherBSERecord extends EscherRecord {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000;
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
public static final short RECORD_ID = EscherRecordTypes.BSE.typeID;
@ -55,6 +56,20 @@ public final class EscherBSERecord extends EscherRecord {
private byte[] _remainingData = new byte[0];
/**
* @param length the max length allowed for EscherBSERecord
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for EscherBSERecord
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
public EscherBSERecord() {
setRecordId(RECORD_ID);
}

View File

@ -27,7 +27,8 @@ import org.apache.poi.util.LittleEndian;
public class EscherBlipRecord extends EscherRecord {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 104_857_600;
private static final int DEFAULT_MAX_RECORD_LENGTH = 104_857_600;
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
public static final short RECORD_ID_START = EscherRecordTypes.BLIP_START.typeID;
public static final short RECORD_ID_END = EscherRecordTypes.BLIP_END.typeID;
@ -36,6 +37,20 @@ public class EscherBlipRecord extends EscherRecord {
private byte[] field_pictureData;
/**
* @param length the max length allowed for EscherBlipRecord
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for EscherBlipRecord
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
public EscherBlipRecord() {
}

View File

@ -36,7 +36,8 @@ import org.apache.poi.util.LittleEndian;
*/
public class EscherClientAnchorRecord extends EscherRecord {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000;
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
public static final short RECORD_ID = EscherRecordTypes.CLIENT_ANCHOR.typeID;
@ -60,6 +61,20 @@ public class EscherClientAnchorRecord extends EscherRecord {
private byte[] remainingData = new byte[0];
private boolean shortRecord;
/**
* @param length the max length allowed for EscherClientAnchorRecord
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for EscherClientAnchorRecord
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
public EscherClientAnchorRecord() {}
public EscherClientAnchorRecord(EscherClientAnchorRecord other) {

View File

@ -34,11 +34,26 @@ public class EscherClientDataRecord extends EscherRecord {
public static final short RECORD_ID = EscherRecordTypes.CLIENT_DATA.typeID;
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000;
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
private static final byte[] EMPTY = {};
private byte[] remainingData;
/**
* @param length the max length allowed for EscherClientDataRecord
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for EscherClientDataRecord
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
public EscherClientDataRecord() {}
public EscherClientDataRecord(EscherClientDataRecord other) {

View File

@ -41,7 +41,8 @@ import org.apache.poi.util.Removal;
public final class EscherMetafileBlip extends EscherBlipRecord {
private static final Logger LOGGER = LogManager.getLogger(EscherMetafileBlip.class);
//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;
/** @deprecated use EscherRecordTypes.BLIP_EMF.typeID */
@Deprecated
@ -77,6 +78,20 @@ public final class EscherMetafileBlip extends EscherBlipRecord {
private byte[] raw_pictureData;
private byte[] remainingData;
/**
* @param length the max length allowed for EscherMetafileBlip
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for EscherMetafileBlip
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
public EscherMetafileBlip() {}
public EscherMetafileBlip(EscherMetafileBlip other) {

View File

@ -34,15 +34,30 @@ import org.apache.poi.util.RecordFormatException;
public final class EscherTextboxRecord extends EscherRecord {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
private static int DEFAULT_MAX_RECORD_LENGTH = 100_000;
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
public static final short RECORD_ID = EscherRecordTypes.CLIENT_TEXTBOX.typeID;
private static final byte[] NO_BYTES = new byte[0];
/** The data for this record not including the the 8 byte header */
/** The data for this record not including the 8 byte header */
private byte[] thedata = NO_BYTES;
/**
* @param length the max length allowed for EscherTextboxRecord
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for EscherTextboxRecord
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
public EscherTextboxRecord() {}
public EscherTextboxRecord(EscherTextboxRecord other) {

View File

@ -24,10 +24,25 @@ import org.apache.poi.util.LittleEndianInput;
public class Blob {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 10_000_000;
private static final int DEFAULT_MAX_RECORD_LENGTH = 10_000_000;
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
private byte[] _value;
/**
* @param length the max length allowed for Blob
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for Blob
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
public void read( LittleEndianInput lei ) {
int size = lei.readInt();
_value = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);

View File

@ -29,13 +29,28 @@ import static org.apache.logging.log4j.util.Unbox.box;
@Internal
public class ClipboardData {
//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 static final Logger LOG = LogManager.getLogger(ClipboardData.class);
private int _format;
private byte[] _value;
/**
* @param length the max length allowed for ClipboardData
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for ClipboardData
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
public void read( LittleEndianByteArrayInputStream lei ) {
int offset = lei.getReadIndex();
long size = lei.readInt();

View File

@ -34,12 +34,26 @@ import static org.apache.logging.log4j.util.Unbox.box;
@Internal
public class CodePageString {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000;
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
private static final Logger LOG = LogManager.getLogger(CodePageString.class);
private byte[] _value;
/**
* @param length the max length allowed for CodePageString
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for CodePageString
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
public void read( LittleEndianByteArrayInputStream lei ) {
int offset = lei.getReadIndex();

View File

@ -32,7 +32,8 @@ import org.apache.poi.util.LittleEndianInputStream;
public abstract class ChunkedCipherInputStream extends LittleEndianInputStream {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000;
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
private final int chunkSize;
private final int chunkBits;
@ -45,6 +46,20 @@ public abstract class ChunkedCipherInputStream extends LittleEndianInputStream {
private long pos;
private boolean chunkIsValid;
/**
* @param length the max length allowed for ChunkedCipherInputStream
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for ChunkedCipherInputStream
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
public ChunkedCipherInputStream(InputStream stream, long size, int chunkSize)
throws GeneralSecurityException {
this(stream, size, chunkSize, 0);

View File

@ -44,7 +44,8 @@ import org.apache.poi.util.TempFile;
public abstract class ChunkedCipherOutputStream extends FilterOutputStream {
private static final Logger LOG = LogManager.getLogger(ChunkedCipherOutputStream.class);
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000;
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
private static final int STREAMING = -1;
@ -65,6 +66,20 @@ public abstract class ChunkedCipherOutputStream extends FilterOutputStream {
private Cipher cipher;
private boolean isClosed;
/**
* @param length the max length allowed for ChunkedCipherOutputStream
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for ChunkedCipherOutputStream
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
public ChunkedCipherOutputStream(DirectoryNode dir, int chunkSize) throws IOException, GeneralSecurityException {
super(null);
this.chunkSize = chunkSize;

View File

@ -36,7 +36,22 @@ import org.apache.poi.util.StringUtil;
public class DataSpaceMapUtils {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000;
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
/**
* @param length the max length allowed for EscherTextboxRecord
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for EscherTextboxRecord
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
public static void addDefaultDataSpace(DirectoryEntry dir) throws IOException {
DataSpaceMapEntry dsme = new DataSpaceMapEntry(

View File

@ -58,7 +58,8 @@ import org.apache.poi.util.LocaleUtil;
public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
private static final Logger LOG = LogManager.getLogger(EmbeddedExtractor.class);
//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;
// contentType
private static final String CONTENT_TYPE_BYTES = "binary/octet-stream";
@ -66,6 +67,20 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
private static final String CONTENT_TYPE_DOC = "application/msword";
private static final String CONTENT_TYPE_XLS = "application/vnd.ms-excel";
/**
* @param length the max length allowed for EmbeddedExtractor
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for EmbeddedExtractor
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
/**
* @return the list of known extractors, if you provide custom extractors, override this method
*/

View File

@ -36,7 +36,8 @@ import org.apache.poi.util.IOUtils;
final class FunctionMetadataReader {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_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 METADATA_FILE_NAME = "functionMetadata.txt";
private static final String METADATA_FILE_NAME_CETAB = "functionMetadataCetab.txt";
@ -55,6 +56,20 @@ final class FunctionMetadataReader {
};
private static final Set<String> DIGIT_ENDING_FUNCTION_NAMES_SET = new HashSet<>(Arrays.asList(DIGIT_ENDING_FUNCTION_NAMES));
/**
* @param length the max length allowed for FunctionMetadataReader
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for FunctionMetadataReader
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
public static FunctionMetadataRegistry createRegistry() {
FunctionDataBuilder fdb = new FunctionDataBuilder(800);
readResourceFile(fdb, METADATA_FILE_NAME);

View File

@ -40,7 +40,8 @@ public abstract class LZWDecompresser {
public static final int DICT_MASK = 0xFFF;
//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;
/**
* Does the mask bit mean it's compressed or uncompressed?
@ -59,6 +60,20 @@ public abstract class LZWDecompresser {
*/
private final boolean positionIsBigEndian;
/**
* @param length the max length allowed for LZWDecompresser
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for LZWDecompresser
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
protected LZWDecompresser(boolean maskMeansCompressed,
int codeLengthIncrease, boolean positionIsBigEndian) {
this.maskMeansCompressed = maskMeansCompressed;

View File

@ -29,12 +29,27 @@ import java.util.Locale;
@Internal
public final class StringUtil {
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 10000000;
private static final int DEFAULT_MAX_RECORD_LENGTH = 10000000;
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
public static final Charset UTF16LE = StandardCharsets.UTF_16LE;
public static final Charset UTF8 = StandardCharsets.UTF_8;
public static final Charset WIN_1252 = Charset.forName("cp1252");
/**
* @param length the max length allowed for StringUtil
*/
public static void setMaxRecordLength(int length) {
MAX_RECORD_LENGTH = length;
}
/**
* @return the max length allowed for StringUtil
*/
public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
private StringUtil() {
// no instances of this class
}