mirror of https://github.com/apache/poi.git
configurable max record len
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894516 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c1ae6ef0e9
commit
8644c69b4c
|
@ -45,8 +45,6 @@ import org.apache.poi.util.LittleEndianOutputStream;
|
|||
* Represents a section in a {@link PropertySet}.
|
||||
*/
|
||||
public class Section {
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(Section.class);
|
||||
|
||||
|
@ -830,7 +828,7 @@ public class Section {
|
|||
}
|
||||
|
||||
try {
|
||||
byte[] buf = IOUtils.safelyAllocate(nrBytes, MAX_RECORD_LENGTH);
|
||||
byte[] buf = IOUtils.safelyAllocate(nrBytes, CodePageString.getMaxRecordLength());
|
||||
leis.readFully(buf, 0, nrBytes);
|
||||
final String str = CodePageUtil.getStringFromCodePage(buf, 0, nrBytes, cp);
|
||||
|
||||
|
|
|
@ -33,15 +33,13 @@ import org.apache.poi.util.StringUtil;
|
|||
@Internal
|
||||
public class UnicodeString {
|
||||
private static final Logger LOG = LogManager.getLogger(UnicodeString.class);
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
private byte[] _value;
|
||||
|
||||
public void read(LittleEndianByteArrayInputStream lei) {
|
||||
final int length = lei.readInt();
|
||||
final int unicodeBytes = length*2;
|
||||
_value = IOUtils.safelyAllocate(unicodeBytes, MAX_RECORD_LENGTH);
|
||||
_value = IOUtils.safelyAllocate(unicodeBytes, CodePageString.getMaxRecordLength());
|
||||
|
||||
// If Length is zero, this field MUST be zero bytes in length. If Length is
|
||||
// nonzero, this field MUST be a null-terminated array of 16-bit Unicode characters, followed by
|
||||
|
|
|
@ -59,8 +59,6 @@ public class VariantSupport extends Variant {
|
|||
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(VariantSupport.class);
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
private static boolean logUnsupportedTypes;
|
||||
|
||||
|
@ -176,7 +174,7 @@ public class VariantSupport extends Variant {
|
|||
typedPropertyValue.readValue(lei);
|
||||
} catch ( UnsupportedOperationException exc ) {
|
||||
try {
|
||||
final byte[] v = IOUtils.toByteArray(lei, length, MAX_RECORD_LENGTH);
|
||||
final byte[] v = IOUtils.toByteArray(lei, length, CodePageString.getMaxRecordLength());
|
||||
throw new ReadingNotSupportedException( type, v );
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
@ -254,7 +252,7 @@ public class VariantSupport extends Variant {
|
|||
default:
|
||||
final int unpadded = lei.getReadIndex()-offset;
|
||||
lei.setReadIndex(offset);
|
||||
final byte[] v = IOUtils.safelyAllocate(unpadded, MAX_RECORD_LENGTH);
|
||||
final byte[] v = IOUtils.safelyAllocate(unpadded, CodePageString.getMaxRecordLength());
|
||||
lei.readFully( v, 0, unpadded );
|
||||
throw new ReadingNotSupportedException( type, v );
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.apache.poi.hssf.record.OldSheetRecord;
|
|||
import org.apache.poi.hssf.record.OldStringRecord;
|
||||
import org.apache.poi.hssf.record.RKRecord;
|
||||
import org.apache.poi.hssf.record.RecordInputStream;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||
import org.apache.poi.poifs.filesystem.DocumentNode;
|
||||
import org.apache.poi.poifs.filesystem.FileMagic;
|
||||
|
@ -62,9 +63,6 @@ import org.apache.poi.util.IOUtils;
|
|||
public class OldExcelExtractor implements POITextExtractor {
|
||||
|
||||
private static final int FILE_PASS_RECORD_SID = 0x2f;
|
||||
//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 RecordInputStream ris;
|
||||
|
||||
|
@ -74,20 +72,6 @@ public class OldExcelExtractor implements POITextExtractor {
|
|||
private int biffVersion;
|
||||
private int fileType;
|
||||
|
||||
/**
|
||||
* @param length the max record length allowed for OldExcelExtractor
|
||||
*/
|
||||
public static void setMaxRecordLength(int length) {
|
||||
MAX_RECORD_LENGTH = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the max record length allowed for OldExcelExtractor
|
||||
*/
|
||||
public static int getMaxRecordLength() {
|
||||
return MAX_RECORD_LENGTH;
|
||||
}
|
||||
|
||||
public OldExcelExtractor(InputStream input) throws IOException {
|
||||
open(input);
|
||||
}
|
||||
|
@ -316,7 +300,7 @@ public class OldExcelExtractor implements POITextExtractor {
|
|||
break;
|
||||
|
||||
default:
|
||||
ris.readFully(IOUtils.safelyAllocate(ris.remaining(), MAX_RECORD_LENGTH));
|
||||
ris.readFully(IOUtils.safelyAllocate(ris.remaining(), HSSFWorkbook.getMaxRecordLength()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.apache.poi.util.IOUtils;
|
|||
import org.apache.poi.util.LittleEndianOutput;
|
||||
|
||||
import static org.apache.logging.log4j.util.Unbox.box;
|
||||
import static org.apache.poi.hssf.usermodel.HSSFWorkbook.getMaxRecordLength;
|
||||
|
||||
/**
|
||||
* Conditional Formatting v12 Rule Record (0x087A).
|
||||
|
@ -55,9 +56,6 @@ import static org.apache.logging.log4j.util.Unbox.box;
|
|||
*/
|
||||
public final class CFRule12Record extends CFRuleBase implements FutureRecord {
|
||||
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
public static final short sid = 0x087A;
|
||||
|
||||
private FtrHeader futureHeader;
|
||||
|
@ -123,7 +121,7 @@ public final class CFRule12Record extends CFRuleBase implements FutureRecord {
|
|||
priority = 0;
|
||||
template_type = getConditionType();
|
||||
template_param_length = 16;
|
||||
template_params = IOUtils.safelyAllocate(template_param_length, MAX_RECORD_LENGTH);
|
||||
template_params = IOUtils.safelyAllocate(template_param_length, getMaxRecordLength());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -267,7 +265,7 @@ public final class CFRule12Record extends CFRuleBase implements FutureRecord {
|
|||
} else {
|
||||
long len = readFormatOptions(in);
|
||||
if (len < ext_formatting_length) {
|
||||
ext_formatting_data = IOUtils.safelyAllocate(ext_formatting_length-len, MAX_RECORD_LENGTH);
|
||||
ext_formatting_data = IOUtils.safelyAllocate(ext_formatting_length-len, getMaxRecordLength());
|
||||
in.readFully(ext_formatting_data);
|
||||
}
|
||||
}
|
||||
|
@ -283,7 +281,7 @@ public final class CFRule12Record extends CFRuleBase implements FutureRecord {
|
|||
template_type = in.readUShort();
|
||||
template_param_length = in.readByte();
|
||||
if (template_param_length == 0 || template_param_length == 16) {
|
||||
template_params = IOUtils.safelyAllocate(template_param_length, MAX_RECORD_LENGTH);
|
||||
template_params = IOUtils.safelyAllocate(template_param_length, getMaxRecordLength());
|
||||
in.readFully(template_params);
|
||||
} else {
|
||||
LOG.atWarn().log("CF Rule v12 template params length should be 0 or 16, found {}", box(template_param_length));
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Map;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.util.GenericRecordUtil;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.util.LittleEndianOutput;
|
||||
|
@ -72,9 +73,6 @@ import org.apache.poi.util.StringUtil;
|
|||
*/
|
||||
public class DConRefRecord extends StandardRecord {
|
||||
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
/**
|
||||
* The id of the record type,
|
||||
* <code>sid = {@value}</code>
|
||||
|
@ -158,7 +156,7 @@ public class DConRefRecord extends StandardRecord {
|
|||
// single-byte, 1 if double-byte.
|
||||
final int byteLength = charCount * (charType + 1);
|
||||
|
||||
path = IOUtils.safelyAllocate(byteLength, MAX_RECORD_LENGTH);
|
||||
path = IOUtils.safelyAllocate(byteLength, HSSFWorkbook.getMaxRecordLength());
|
||||
inStream.readFully(path);
|
||||
|
||||
// If it's a self reference, the last one or two bytes (depending on char type) are the
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.function.Supplier;
|
|||
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.formula.ptg.Area3DPtg;
|
||||
import org.apache.poi.ss.formula.ptg.AreaPtg;
|
||||
import org.apache.poi.ss.formula.ptg.Ptg;
|
||||
|
@ -47,8 +48,6 @@ import static org.apache.logging.log4j.util.Unbox.box;
|
|||
*/
|
||||
public final class EmbeddedObjectRefSubRecord extends SubRecord {
|
||||
private static final Logger LOG = LogManager.getLogger(EmbeddedObjectRefSubRecord.class);
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
public static final short sid = 0x0009;
|
||||
|
||||
|
@ -202,7 +201,7 @@ public final class EmbeddedObjectRefSubRecord extends SubRecord {
|
|||
if (size == 0) {
|
||||
return EMPTY_BYTE_ARRAY;
|
||||
}
|
||||
byte[] result = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
|
||||
byte[] result = IOUtils.safelyAllocate(size, HSSFWorkbook.getMaxRecordLength());
|
||||
in.readFully(result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.poi.hssf.record;
|
|||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.util.GenericRecordUtil;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.util.LittleEndianInput;
|
||||
|
@ -31,9 +32,6 @@ import org.apache.poi.util.LittleEndianOutput;
|
|||
*/
|
||||
public final class GroupMarkerSubRecord extends SubRecord {
|
||||
public static final short sid = 0x0006;
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
|
||||
private static final byte[] EMPTY_BYTE_ARRAY = { };
|
||||
|
||||
|
@ -54,7 +52,7 @@ public final class GroupMarkerSubRecord extends SubRecord {
|
|||
}
|
||||
|
||||
GroupMarkerSubRecord(LittleEndianInput in, int size, int cmoOt) {
|
||||
byte[] buf = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
|
||||
byte[] buf = IOUtils.safelyAllocate(size, HSSFWorkbook.getMaxRecordLength());
|
||||
in.readFully(buf);
|
||||
reserved = buf;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.apache.logging.log4j.LogManager;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.poi.hpsf.ClassID;
|
||||
import org.apache.poi.hpsf.ClassIDPredefined;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.util.GenericRecordUtil;
|
||||
import org.apache.poi.util.HexRead;
|
||||
|
@ -48,9 +49,6 @@ import org.apache.poi.util.StringUtil;
|
|||
public final class HyperlinkRecord extends StandardRecord {
|
||||
public static final short sid = 0x01B8;
|
||||
private static final Logger LOG = LogManager.getLogger(HyperlinkRecord.class);
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
|
||||
/*
|
||||
* Link flags
|
||||
|
@ -391,7 +389,7 @@ public final class HyperlinkRecord extends StandardRecord {
|
|||
|
||||
int len = in.readInt();
|
||||
|
||||
byte[] path_bytes = IOUtils.safelyAllocate(len, MAX_RECORD_LENGTH);
|
||||
byte[] path_bytes = IOUtils.safelyAllocate(len, HSSFWorkbook.getMaxRecordLength());
|
||||
in.readFully(path_bytes);
|
||||
|
||||
_address = new String(path_bytes, StringUtil.UTF8);
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.function.Supplier;
|
|||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.util.GenericRecordUtil;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.util.RecordFormatException;
|
||||
|
@ -36,8 +37,6 @@ import static org.apache.poi.util.HexDump.toHex;
|
|||
*/
|
||||
public final class OldLabelRecord extends OldCellRecord {
|
||||
private static final Logger LOG = LogManager.getLogger(OldLabelRecord.class);
|
||||
//arbitrarily set, may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
public static final short biff2_sid = 0x0004;
|
||||
public static final short biff345_sid = 0x0204;
|
||||
|
@ -60,7 +59,7 @@ public final class OldLabelRecord extends OldCellRecord {
|
|||
}
|
||||
|
||||
// Can only decode properly later when you know the codepage
|
||||
field_5_bytes = IOUtils.safelyAllocate(field_4_string_len, MAX_RECORD_LENGTH);
|
||||
field_5_bytes = IOUtils.safelyAllocate(field_4_string_len, HSSFWorkbook.getMaxRecordLength());
|
||||
in.read(field_5_bytes, 0, field_4_string_len);
|
||||
|
||||
if (in.remaining() > 0) {
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.Map;
|
|||
import java.util.function.Supplier;
|
||||
|
||||
import org.apache.poi.common.usermodel.GenericRecord;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.util.GenericRecordJsonWriter;
|
||||
import org.apache.poi.util.GenericRecordUtil;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
|
@ -35,9 +36,6 @@ import org.apache.poi.util.RecordFormatException;
|
|||
*/
|
||||
public final class OldSheetRecord implements GenericRecord {
|
||||
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
public static final short sid = 0x0085;
|
||||
|
||||
private final int field_1_position_of_BOF;
|
||||
|
@ -64,7 +62,7 @@ public final class OldSheetRecord implements GenericRecord {
|
|||
}
|
||||
}
|
||||
}
|
||||
field_5_sheetname = IOUtils.safelyAllocate(field_4_sheetname_length, MAX_RECORD_LENGTH);
|
||||
field_5_sheetname = IOUtils.safelyAllocate(field_4_sheetname_length, HSSFWorkbook.getMaxRecordLength());
|
||||
in.read(field_5_sheetname, 0, field_4_sheetname_length);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.function.Supplier;
|
|||
|
||||
import org.apache.poi.common.usermodel.GenericRecord;
|
||||
import org.apache.poi.hpsf.Property;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.util.CodePageUtil;
|
||||
import org.apache.poi.util.GenericRecordJsonWriter;
|
||||
import org.apache.poi.util.GenericRecordUtil;
|
||||
|
@ -35,9 +36,6 @@ import org.apache.poi.util.IOUtils;
|
|||
*/
|
||||
public final class OldStringRecord implements GenericRecord {
|
||||
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
public static final short biff2_sid = 0x0007;
|
||||
public static final short biff345_sid = 0x0207;
|
||||
|
||||
|
@ -59,7 +57,7 @@ public final class OldStringRecord implements GenericRecord {
|
|||
}
|
||||
|
||||
// Can only decode properly later when you know the codepage
|
||||
field_2_bytes = IOUtils.safelyAllocate(field_1_string_len, MAX_RECORD_LENGTH);
|
||||
field_2_bytes = IOUtils.safelyAllocate(field_1_string_len, HSSFWorkbook.getMaxRecordLength());
|
||||
in.read(field_2_bytes, 0, field_1_string_len);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.Locale;
|
|||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||
import org.apache.poi.hssf.dev.BiffViewer;
|
||||
import org.apache.poi.hssf.record.crypto.Biff8DecryptingStream;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.poifs.crypt.EncryptionInfo;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.util.Internal;
|
||||
|
@ -39,12 +40,10 @@ import org.apache.poi.util.RecordFormatException;
|
|||
*/
|
||||
public final class RecordInputStream implements LittleEndianInput {
|
||||
|
||||
|
||||
/** Maximum size of a single record (minus the 4 byte header) without a continue*/
|
||||
public static final short MAX_RECORD_DATA_SIZE = 8224;
|
||||
private static final int INVALID_SID_VALUE = -1;
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
/**
|
||||
* When {@link #_currentDataLength} has this value, it means that the previous BIFF record is
|
||||
* finished, the next sid has been properly read, but the data size field has not been read yet.
|
||||
|
@ -442,7 +441,7 @@ public final class RecordInputStream implements LittleEndianInput {
|
|||
if (size ==0) {
|
||||
return EMPTY_BYTE_ARRAY;
|
||||
}
|
||||
byte[] result = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
|
||||
byte[] result = IOUtils.safelyAllocate(size, HSSFWorkbook.getMaxRecordLength());
|
||||
readFully(result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.logging.log4j.LogManager;
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.poi.common.usermodel.GenericRecord;
|
||||
import org.apache.poi.hssf.record.cont.ContinuableRecordOutput;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.util.GenericRecordUtil;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.util.Internal;
|
||||
|
@ -37,8 +38,6 @@ import static org.apache.logging.log4j.util.Unbox.box;
|
|||
@Internal
|
||||
public class ExtRst implements Comparable<ExtRst>, GenericRecord {
|
||||
private static final Logger LOG = LogManager.getLogger(ExtRst.class);
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
private short reserved;
|
||||
|
||||
|
@ -126,7 +125,7 @@ public class ExtRst implements Comparable<ExtRst>, GenericRecord {
|
|||
LOG.atWarn().log("ExtRst overran by {} bytes", box(-extraDataLength));
|
||||
extraDataLength = 0;
|
||||
}
|
||||
extraData = IOUtils.safelyAllocate(extraDataLength, MAX_RECORD_LENGTH);
|
||||
extraData = IOUtils.safelyAllocate(extraDataLength, HSSFWorkbook.getMaxRecordLength());
|
||||
for(int i=0; i<extraData.length; i++) {
|
||||
extraData[i] = in.readByte();
|
||||
}
|
||||
|
|
|
@ -20,10 +20,8 @@ package org.apache.poi.hssf.record.crypto;
|
|||
import java.io.InputStream;
|
||||
import java.io.PushbackInputStream;
|
||||
|
||||
import org.apache.poi.hssf.record.BOFRecord;
|
||||
import org.apache.poi.hssf.record.BiffHeaderInput;
|
||||
import org.apache.poi.hssf.record.FilePassRecord;
|
||||
import org.apache.poi.hssf.record.InterfaceHdrRecord;
|
||||
import org.apache.poi.hssf.record.*;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.poifs.crypt.ChunkedCipherInputStream;
|
||||
import org.apache.poi.poifs.crypt.Decryptor;
|
||||
import org.apache.poi.poifs.crypt.EncryptionInfo;
|
||||
|
@ -37,31 +35,15 @@ import org.apache.poi.util.SuppressForbidden;
|
|||
public final class Biff8DecryptingStream implements BiffHeaderInput, LittleEndianInput {
|
||||
|
||||
public static final int RC4_REKEYING_INTERVAL = 1024;
|
||||
//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 final ChunkedCipherInputStream ccis;
|
||||
private final byte[] buffer = new byte[LittleEndianConsts.LONG_SIZE];
|
||||
private boolean shouldSkipEncryptionOnCurrentRecord;
|
||||
|
||||
/**
|
||||
* @param length the max record length allowed for Biff8DecryptingStream
|
||||
*/
|
||||
public static void setMaxRecordLength(int length) {
|
||||
MAX_RECORD_LENGTH = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the max record length allowed for Biff8DecryptingStream
|
||||
*/
|
||||
public static int getMaxRecordLength() {
|
||||
return MAX_RECORD_LENGTH;
|
||||
}
|
||||
|
||||
public Biff8DecryptingStream(InputStream in, int initialOffset, EncryptionInfo info) throws RecordFormatException {
|
||||
try {
|
||||
byte[] initialBuf = IOUtils.safelyAllocate(initialOffset, MAX_RECORD_LENGTH);
|
||||
byte[] initialBuf = IOUtils.safelyAllocate(initialOffset, HSSFWorkbook.getMaxRecordLength());
|
||||
InputStream stream;
|
||||
if (initialOffset == 0) {
|
||||
stream = in;
|
||||
|
|
|
@ -39,8 +39,6 @@ import org.apache.poi.util.IOUtils;
|
|||
* Dump internal structure of a OLE2 file into file system
|
||||
*/
|
||||
public final class POIFSDump {
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
private POIFSDump() {}
|
||||
|
||||
|
@ -125,7 +123,7 @@ public final class POIFSDump {
|
|||
try (FileOutputStream out = new FileOutputStream(file)) {
|
||||
POIFSStream stream = new POIFSStream(fs, startBlock);
|
||||
|
||||
byte[] b = IOUtils.safelyAllocate(fs.getBigBlockSize(), MAX_RECORD_LENGTH);
|
||||
byte[] b = IOUtils.safelyAllocate(fs.getBigBlockSize(), POIFSFileSystem.getMaxRecordLength());
|
||||
for (ByteBuffer bb : stream) {
|
||||
int len = bb.remaining();
|
||||
bb.get(b);
|
||||
|
|
|
@ -143,7 +143,7 @@ public final class POIFSDocument implements POIFSViewable, Iterable<ByteBuffer>
|
|||
int usedInBlock = (int) (length % _block_size);
|
||||
if (usedInBlock != 0 && usedInBlock != _block_size) {
|
||||
int toBlockEnd = _block_size - usedInBlock;
|
||||
byte[] padding = IOUtils.safelyAllocate(toBlockEnd, POIFSFileSystem.MAX_RECORD_LENGTH);
|
||||
byte[] padding = IOUtils.safelyAllocate(toBlockEnd, POIFSFileSystem.getMaxRecordLength());
|
||||
Arrays.fill(padding, (byte) 0xFF);
|
||||
os.write(padding);
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ public final class POIFSDocument implements POIFSViewable, Iterable<ByteBuffer>
|
|||
|
||||
if (getSize() > 0) {
|
||||
// Get all the data into a single array
|
||||
byte[] data = IOUtils.safelyAllocate(getSize(), POIFSFileSystem.MAX_RECORD_LENGTH);
|
||||
byte[] data = IOUtils.safelyAllocate(getSize(), POIFSFileSystem.getMaxRecordLength());
|
||||
int offset = 0;
|
||||
for (ByteBuffer buffer : _stream) {
|
||||
int length = Math.min(_block_size, data.length - offset);
|
||||
|
|
|
@ -62,7 +62,7 @@ public class POIFSFileSystem extends BlockStore
|
|||
implements POIFSViewable, Closeable {
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000;
|
||||
static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
|
||||
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(POIFSFileSystem.class);
|
||||
|
||||
|
|
|
@ -45,9 +45,6 @@ import static org.apache.logging.log4j.util.Unbox.box;
|
|||
public final class PropertyTable implements BATManaged {
|
||||
private static final Logger LOG = LogManager.getLogger(PropertyTable.class);
|
||||
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
private final HeaderBlock _header_block;
|
||||
private final List<Property> _properties = new ArrayList<>();
|
||||
private final POIFSBigBlockSize _bigBigBlockSize;
|
||||
|
@ -91,7 +88,7 @@ public final class PropertyTable implements BATManaged {
|
|||
bb.array().length == _bigBigBlockSize.getBigBlockSize()) {
|
||||
data = bb.array();
|
||||
} else {
|
||||
data = IOUtils.safelyAllocate(_bigBigBlockSize.getBigBlockSize(), MAX_RECORD_LENGTH);
|
||||
data = IOUtils.safelyAllocate(_bigBigBlockSize.getBigBlockSize(), POIFSFileSystem.getMaxRecordLength());
|
||||
|
||||
int toRead = data.length;
|
||||
if (bb.remaining() < _bigBigBlockSize.getBigBlockSize()) {
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.poi.poifs.common.POIFSConstants;
|
|||
import org.apache.poi.poifs.filesystem.FileMagic;
|
||||
import org.apache.poi.poifs.filesystem.NotOLE2FileException;
|
||||
import org.apache.poi.poifs.filesystem.OfficeXmlFileException;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
import org.apache.poi.util.HexDump;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.util.IntegerField;
|
||||
|
@ -42,9 +43,6 @@ import org.apache.poi.util.ShortField;
|
|||
*/
|
||||
public final class HeaderBlock implements HeaderBlockConstants {
|
||||
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000;
|
||||
|
||||
private static final byte _default_value = ( byte ) 0xFF;
|
||||
|
||||
/**
|
||||
|
@ -108,7 +106,7 @@ public final class HeaderBlock implements HeaderBlockConstants {
|
|||
// Fetch the rest of the block if needed
|
||||
if(bigBlockSize.getBigBlockSize() != 512) {
|
||||
int rest = bigBlockSize.getBigBlockSize() - 512;
|
||||
byte[] tmp = IOUtils.safelyAllocate(rest, MAX_RECORD_LENGTH);
|
||||
byte[] tmp = IOUtils.safelyAllocate(rest, POIFSFileSystem.getMaxRecordLength());
|
||||
IOUtils.readFully(stream, tmp);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue