public static int getMaxRecordLength() {
return MAX_RECORD_LENGTH;
}
-
+
/**
* Creates a new compressed StreamStore, which will handle
* the decompression.
HDGFLZW lzw = new HDGFLZW();
byte[] decompressed = lzw.decompress(bais);
+ if (decompressed.length < 4) {
+ throw new IllegalArgumentException("Could not read enough data to decompress: " + decompressed.length);
+ }
+
// Split into header and contents
byte[][] ret = new byte[2][];
ret[0] = new byte[4];
// First four bytes are the number
numberOfPLCs = (int)LittleEndian.getUInt(data, 0);
+ if (numberOfPLCs < 0) {
+ throw new IllegalArgumentException("Invalid number of PLCs: " + numberOfPLCs);
+ }
// Next four bytes are the type
typeOfPLCS = (int)LittleEndian.getUInt(data, 4);
this.plcValB = plcValB.clone();
}
-
+
public static QCPLCBit createQCPLCBit(String thingType, String bitType, byte[] data) {
// Grab the type
super(thingType, bitType, data);
int cntPlcs = getNumberOfPLCs();
-
+
// How many hyperlinks do we really have?
// (zero hyperlinks gets numberOfPLCs=1)
hyperlinks = new String[data.length == 0x34 ? 0 : cntPlcs];
offsetTmp = offset - offsetTmp;
_xszFfnLength = (this.getSize() - offsetTmp) / 2;
+
+ if (_xszFfnLength < 0) {
+ throw new IllegalArgumentException("Had invalid computed size: " + _xszFfnLength + " with size " + getSize() + " and offsetTmp: " + offsetTmp);
+ }
+
_xszFfn = new char[_xszFfnLength];
for (int i = 0; i < _xszFfnLength; i++) {
_rgLfoLvl = new ListFormatOverrideLevel[0];
}
- LFOData( byte[] buf, int startOffset, int cLfolvl )
- {
+ LFOData( byte[] buf, int startOffset, int cLfolvl ) {
+ if (cLfolvl < 0) {
+ throw new IllegalArgumentException("Cannot create LFOData with negative count");
+ }
+
int offset = startOffset;
_cp = LittleEndian.getInt( buf, offset );
_stshif = new Stshif(tableStream, offset);
+ if (_stshif.getCstd() < 0) {
+ throw new IllegalArgumentException("Cannot create StyleSheet, invalid Cstd: " + _stshif.getCstd());
+ }
+
// shall we discard cbLSD and mpstilsd?
offset = startOffset + LittleEndianConsts.SHORT_SIZE + _cbStshi;
import java.util.Arrays;
import java.util.List;
+import org.apache.poi.util.RecordFormatException;
+
/**
* Title: Record Factory<p>
* Description: Takes a stream and outputs an array of Record objects.
* @return the equivalent array of {@link NumberRecord NumberRecords}
*/
public static NumberRecord[] convertRKRecords(MulRKRecord mrk) {
+ if (mrk.getNumColumns() < 0) {
+ throw new RecordFormatException("Cannot create RKRecords with negative number of columns: " + mrk.getNumColumns());
+ }
+
NumberRecord[] mulRecs = new NumberRecord[mrk.getNumColumns()];
for (int k = 0; k < mrk.getNumColumns(); k++) {
NumberRecord nr = new NumberRecord();
*
* @exception org.apache.poi.util.RecordFormatException on error processing the InputStream
*/
- public static List<org.apache.poi.hssf.record.Record> createRecords(InputStream in) throws org.apache.poi.util.RecordFormatException {
+ public static List<org.apache.poi.hssf.record.Record> createRecords(InputStream in) throws RecordFormatException {
List<org.apache.poi.hssf.record.Record> records = new ArrayList<>(NUM_RECORDS);
} else {
nextRecord();
nextChunk = Math.min(available(),len);
- assert(nextChunk > 0);
+ if (nextChunk <= 0) {
+ throw new RecordFormatException("Need to have a valid next chunk, but had: " + nextChunk +
+ " with len: " + len + " and available: " + available());
+ }
}
}
checkRecordPosition(nextChunk);
verOriginator = in.readByte();
verWriter = in.readByte();
int cCFRTID = in.readShort();
+ if (cCFRTID < 0) {
+ throw new IllegalArgumentException("Had negative CFRTID: " + cCFRTID);
+ }
rgCFRTID = new CFRTID[cCFRTID];
for (int i = 0; i < cCFRTID; i++) {
row = record;
setRowNum(record.getRowNumber());
+ if (record.getLastCol() < 0 || INITIAL_CAPACITY < 0) {
+ throw new IllegalArgumentException("Had invalid column counts: " + record.getLastCol() + " and " + INITIAL_CAPACITY);
+ }
+
// Size the initial cell list such that a read only case won't waste
// lots of memory, and a create/read followed by adding new cells can
// add a bit without needing a resize
protected class ChainLoopDetector {
private final boolean[] used_blocks;
protected ChainLoopDetector(long rawSize) {
+ if (rawSize < 0) {
+ throw new IllegalArgumentException("Cannot create a ChainLoopDetector with negative size, but had: " + rawSize);
+ }
+
int blkSize = getBlockStoreBlockSize();
int numBlocks = (int)(rawSize / blkSize);
if ((rawSize % blkSize) != 0) {
}
public static Object[] parse(LittleEndianInput in, int nValues) {
+ if (nValues < 0) {
+ throw new IllegalArgumentException("Invalid number of values to parse: " + nValues);
+ }
+
Object[] result = new Object[nValues];
for (int i = 0; i < result.length; i++) {
result[i] = readAConstantValue(in);