Replace Allocate+System.arraycopy with Array.copyOf/Range and IOUtils.safelyClone

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1876640 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2020-04-16 22:11:16 +00:00
parent cdefe69aab
commit 7daeb4278c
158 changed files with 1078 additions and 1357 deletions

View File

@ -171,9 +171,7 @@ public final class EscherArrayProperty extends EscherComplexProperty implements
public byte[] getElement(int index) {
int actualSize = getActualSizeOfElements(getSizeOfElements());
byte[] result = IOUtils.safelyAllocate(actualSize, MAX_RECORD_LENGTH);
System.arraycopy(getComplexData(), FIXED_SIZE + index * actualSize, result, 0, result.length );
return result;
return IOUtils.safelyClone(getComplexData(), FIXED_SIZE + index * actualSize, actualSize, MAX_RECORD_LENGTH);
}
public void setElement(int index, byte[] element) {

View File

@ -103,8 +103,8 @@ public final class EscherBSERecord extends EscherRecord {
pos += 36 + bytesRead;
bytesRemaining -= bytesRead;
_remainingData = IOUtils.safelyAllocate(bytesRemaining, MAX_RECORD_LENGTH);
System.arraycopy( data, pos, _remainingData, 0, bytesRemaining );
_remainingData = IOUtils.safelyClone(data, pos, bytesRemaining, MAX_RECORD_LENGTH);
return bytesRemaining + 8 + 36 + (field_12_blipRecord == null ? 0 : field_12_blipRecord.getRecordSize()) ;
}

View File

@ -49,9 +49,7 @@ public class EscherBlipRecord extends EscherRecord {
int bytesAfterHeader = readHeader( data, offset );
int pos = offset + HEADER_SIZE;
field_pictureData = IOUtils.safelyAllocate(bytesAfterHeader, MAX_RECORD_LENGTH);
System.arraycopy(data, pos, field_pictureData, 0, bytesAfterHeader);
field_pictureData = IOUtils.safelyClone(data, pos, bytesAfterHeader, MAX_RECORD_LENGTH);
return bytesAfterHeader + 8;
}
@ -108,8 +106,7 @@ public class EscherBlipRecord extends EscherRecord {
if (pictureData == null || offset < 0 || length < 0 || pictureData.length < offset+length) {
throw new IllegalArgumentException("picture data can't be null");
}
field_pictureData = IOUtils.safelyAllocate(length, MAX_RECORD_LENGTH);
System.arraycopy(pictureData, offset, field_pictureData, 0, length);
field_pictureData = IOUtils.safelyClone(pictureData, offset, length, MAX_RECORD_LENGTH);
}
@Override

View File

@ -106,8 +106,8 @@ public class EscherClientAnchorRecord extends EscherRecord {
}
}
bytesRemaining -= size;
remainingData = IOUtils.safelyAllocate(bytesRemaining, MAX_RECORD_LENGTH);
System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining );
remainingData = IOUtils.safelyClone(data, pos + size, bytesRemaining, MAX_RECORD_LENGTH);
return 8 + size + bytesRemaining;
}

View File

@ -50,8 +50,9 @@ public class EscherClientDataRecord extends EscherRecord {
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
int bytesRemaining = readHeader( data, offset );
int pos = offset + 8;
remainingData = (bytesRemaining == 0) ? EMPTY : IOUtils.safelyAllocate(bytesRemaining, MAX_RECORD_LENGTH);
System.arraycopy( data, pos, remainingData, 0, bytesRemaining );
remainingData = (bytesRemaining == 0) ? EMPTY : IOUtils.safelyClone(data, pos, bytesRemaining, MAX_RECORD_LENGTH);
return 8 + bytesRemaining;
}

View File

@ -45,14 +45,11 @@ public class EscherDgRecord extends EscherRecord {
@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
/*int bytesRemaining =*/ readHeader( data, offset );
readHeader( data, offset );
int pos = offset + 8;
int size = 0;
field_1_numShapes = LittleEndian.getInt( data, pos + size ); size += 4;
field_2_lastMSOSPID = LittleEndian.getInt( data, pos + size ); size += 4;
// bytesRemaining -= size;
// remainingData = new byte[bytesRemaining];
// System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining );
return getRecordSize();
}
@ -66,8 +63,6 @@ public class EscherDgRecord extends EscherRecord {
LittleEndian.putInt( data, offset + 4, 8 );
LittleEndian.putInt( data, offset + 8, field_1_numShapes );
LittleEndian.putInt( data, offset + 12, field_2_lastMSOSPID );
// System.arraycopy( remainingData, 0, data, offset + 26, remainingData.length );
// int pos = offset + 8 + 18 + remainingData.length;
listener.afterRecordSerialize( offset + 16, getRecordId(), getRecordSize(), this );
return getRecordSize();

View File

@ -106,8 +106,7 @@ public final class EscherMetafileBlip extends EscherBlipRecord {
field_6_fCompression = data[pos]; pos++;
field_7_fFilter = data[pos]; pos++;
raw_pictureData = IOUtils.safelyAllocate(field_5_cbSave, MAX_RECORD_LENGTH);
System.arraycopy( data, pos, raw_pictureData, 0, field_5_cbSave );
raw_pictureData = IOUtils.safelyClone(data, pos, field_5_cbSave, MAX_RECORD_LENGTH);
pos += field_5_cbSave;
// 0 means DEFLATE compression
@ -120,8 +119,7 @@ public final class EscherMetafileBlip extends EscherBlipRecord {
int remaining = bytesAfterHeader - pos + offset + HEADER_SIZE;
if(remaining > 0) {
remainingData = IOUtils.safelyAllocate(remaining, MAX_RECORD_LENGTH);
System.arraycopy( data, pos, remainingData, 0, remaining );
remainingData = IOUtils.safelyClone(data, pos, remaining, MAX_RECORD_LENGTH);
}
return bytesAfterHeader + HEADER_SIZE;
}

View File

@ -88,14 +88,11 @@ public class EscherSpRecord extends EscherRecord {
@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
/*int bytesRemaining =*/ readHeader( data, offset );
readHeader( data, offset );
int pos = offset + 8;
int size = 0;
field_1_shapeId = LittleEndian.getInt( data, pos + size ); size += 4;
field_2_flags = LittleEndian.getInt( data, pos + size ); size += 4;
// bytesRemaining -= size;
// remainingData = new byte[bytesRemaining];
// System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining );
return getRecordSize();
}
@ -119,8 +116,6 @@ public class EscherSpRecord extends EscherRecord {
LittleEndian.putInt( data, offset + 4, remainingBytes );
LittleEndian.putInt( data, offset + 8, field_1_shapeId );
LittleEndian.putInt( data, offset + 12, field_2_flags );
// System.arraycopy( remainingData, 0, data, offset + 26, remainingData.length );
// int pos = offset + 8 + 18 + remainingData.length;
listener.afterRecordSerialize( offset + getRecordSize(), getRecordId(), getRecordSize(), this );
return 8 + 8;
}

View File

@ -59,8 +59,6 @@ public class EscherSpgrRecord extends EscherRecord {
if (bytesRemaining != 0) {
throw new RecordFormatException("Expected no remaining bytes but got " + bytesRemaining);
}
// remainingData = new byte[bytesRemaining];
// System.arraycopy( data, pos + size, remainingData, 0, bytesRemaining );
return 8 + size + bytesRemaining;
}
@ -76,8 +74,6 @@ public class EscherSpgrRecord extends EscherRecord {
LittleEndian.putInt( data, offset + 12, field_2_rectY1 );
LittleEndian.putInt( data, offset + 16, field_3_rectX2 );
LittleEndian.putInt( data, offset + 20, field_4_rectY2 );
// System.arraycopy( remainingData, 0, data, offset + 26, remainingData.length );
// int pos = offset + 8 + 18 + remainingData.length;
listener.afterRecordSerialize( offset + getRecordSize(), getRecordId(), offset + getRecordSize(), this );
return 8 + 16;
}

View File

@ -54,10 +54,8 @@ public final class EscherTextboxRecord extends EscherRecord {
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
int bytesRemaining = readHeader( data, offset );
// Save the data, ready for the calling code to do something
// useful with it
thedata = IOUtils.safelyAllocate(bytesRemaining, MAX_RECORD_LENGTH);
System.arraycopy( data, offset + 8, thedata, 0, bytesRemaining );
// Save the data, ready for the calling code to do something useful with it
thedata = IOUtils.safelyClone(data, offset + 8, bytesRemaining, MAX_RECORD_LENGTH);
return bytesRemaining + 8;
}
@ -103,10 +101,8 @@ public final class EscherTextboxRecord extends EscherRecord {
* @param start the start position in the buffer
* @param length the length of the block
*/
public void setData(byte[] b, int start, int length)
{
thedata = IOUtils.safelyAllocate(length, MAX_RECORD_LENGTH);
System.arraycopy(b,start,thedata,0,length);
public void setData(byte[] b, int start, int length) {
thedata = IOUtils.safelyClone(b, start, length, MAX_RECORD_LENGTH);
}
/**

View File

@ -81,8 +81,8 @@ public final class UnknownEscherRecord extends EscherRecord {
bytesRemaining = 0;
}
thedata = IOUtils.safelyAllocate(bytesRemaining, MAX_RECORD_LENGTH);
System.arraycopy( data, offset + 8, thedata, 0, bytesRemaining );
thedata = IOUtils.safelyClone(data, offset + 8, bytesRemaining, MAX_RECORD_LENGTH);
return bytesRemaining + 8;
}

View File

@ -17,6 +17,7 @@
package org.apache.poi.hpsf;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LittleEndian;
/**
* <p>Class to manipulate data in the Clipboard Variant ({@link
@ -119,6 +120,9 @@ public final class Thumbnail {
*/
public static final int CF_BITMAP = 2;
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 1_000_000;
/**
* <p>A <code>byte[]</code> to hold a thumbnail image in ({@link
* Variant#VT_CF VT_CF}) format.</p>
@ -260,13 +264,6 @@ public final class Thumbnail {
"be CF_METAFILEPICT.");
}
byte[] thumbnail = getThumbnail();
int wmfImageLength = thumbnail.length - OFFSET_WMFDATA;
byte[] wmfImage = new byte[wmfImageLength];
System.arraycopy(thumbnail,
OFFSET_WMFDATA,
wmfImage,
0,
wmfImageLength);
return wmfImage;
return IOUtils.safelyClone(thumbnail, OFFSET_WMFDATA, thumbnail.length - OFFSET_WMFDATA, MAX_RECORD_LENGTH);
}
}

View File

@ -87,17 +87,17 @@ public abstract class AbstractEscherHolderRecord extends Record {
@Override
public int serialize(int offset, byte[] data)
{
LittleEndian.putShort( data, 0 + offset, getSid() );
LittleEndian.putShort(data, offset, getSid() );
LittleEndian.putShort( data, 2 + offset, (short) ( getRecordSize() - 4 ) );
byte[] rawData = getRawData();
if ( escherRecords.size() == 0 && rawData != null )
{
LittleEndian.putShort(data, 0 + offset, getSid());
LittleEndian.putShort(data, offset, getSid());
LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
System.arraycopy( rawData, 0, data, 4 + offset, rawData.length);
return rawData.length + 4;
}
LittleEndian.putShort(data, 0 + offset, getSid());
LittleEndian.putShort(data, offset, getSid());
LittleEndian.putShort(data, 2 + offset, (short)(getRecordSize() - 4));
int pos = offset + 4;

View File

@ -17,6 +17,7 @@
package org.apache.poi.hssf.record;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -151,8 +152,7 @@ public final class FormatRecord extends StandardRecord {
//there can be a remaining byte (without proper final '00')
//that should be read as a byte
if (ris.available() == 1) {
char[] tmp = new char[buf.length+1];
System.arraycopy(buf, 0, tmp, 0, buf.length);
char[] tmp = Arrays.copyOf(buf, buf.length+1);
tmp[buf.length] = (char)ris.readUByte();
buf = tmp;
}

View File

@ -78,9 +78,7 @@ public final class HeaderFooterRecord extends StandardRecord {
* @return the sheet view?s GUID
*/
public byte[] getGuid(){
byte[] guid = new byte[16];
System.arraycopy(_rawData, 12, guid, 0, guid.length);
return guid;
return Arrays.copyOfRange(_rawData, 12, 12+16);
}
/**

View File

@ -17,6 +17,7 @@
package org.apache.poi.hssf.record;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -74,9 +75,7 @@ public final class UserSViewBegin extends StandardRecord {
* @return Globally unique identifier for the custom view
*/
public byte[] getGuid(){
byte[] guid = new byte[16];
System.arraycopy(_rawData, 0, guid, 0, guid.length);
return guid;
return Arrays.copyOf(_rawData, 16);
}
@Override

View File

@ -19,8 +19,8 @@
package org.apache.poi.hssf.record.cont;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.record.ContinueRecord;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.util.LittleEndianInput;
/**
@ -44,7 +44,7 @@ import org.apache.poi.util.LittleEndianInput;
*
* <p>
* YK: For now (March 2011) this class is only used to read
* @see org.apache.poi.hssf.record.common.UnicodeString.ExtRst blocks of a UnicodeString.
* @see org.apache.poi.hssf.record.common.ExtRst blocks of a UnicodeString.
*
* </p>
*/
@ -78,7 +78,7 @@ public class ContinuableRecordInput implements LittleEndianInput {
public int readUShort(){
int ch1 = readUByte();
int ch2 = readUByte();
return (ch2 << 8) + (ch1 << 0);
return (ch2 << 8) + (ch1);
}
@Override
@ -87,7 +87,7 @@ public class ContinuableRecordInput implements LittleEndianInput {
int ch2 = _in.readUByte();
int ch3 = _in.readUByte();
int ch4 = _in.readUByte();
return (ch4 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1 << 0);
return (ch4 << 24) + (ch3 << 16) + (ch2 << 8) + (ch1);
}
@Override
@ -107,7 +107,7 @@ public class ContinuableRecordInput implements LittleEndianInput {
((long)b3 << 24) +
(b2 << 16) +
(b1 << 8) +
(b0 << 0));
(b0));
}
@Override

View File

@ -196,8 +196,9 @@ public final class HSSFSheetConditionalFormatting implements SheetConditionalFor
public int addConditionalFormatting(CellRangeAddress[] regions, ConditionalFormattingRule[] cfRules) {
HSSFConditionalFormattingRule[] hfRules;
if(cfRules instanceof HSSFConditionalFormattingRule[]) hfRules = (HSSFConditionalFormattingRule[])cfRules;
else {
if(cfRules instanceof HSSFConditionalFormattingRule[]) {
hfRules = (HSSFConditionalFormattingRule[])cfRules;
} else {
hfRules = new HSSFConditionalFormattingRule[cfRules.length];
System.arraycopy(cfRules, 0, hfRules, 0, hfRules.length);
}

View File

@ -23,7 +23,6 @@ import static org.apache.poi.hssf.model.InternalWorkbook.WORKBOOK_DIR_ENTRY_NAME
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@ -93,10 +92,11 @@ import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.DocumentNode;
import org.apache.poi.poifs.filesystem.EntryUtils;
import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.poifs.filesystem.FilteringDirectoryNode;
import org.apache.poi.poifs.filesystem.Ole10Native;
import org.apache.poi.poifs.filesystem.POIFSDocument;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.poifs.filesystem.Ole10Native;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.FormulaShifter;
import org.apache.poi.ss.formula.FormulaType;
@ -133,6 +133,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
//arbitrarily selected; may need to increase
private static final int MAX_RECORD_LENGTH = 100_000;
private static final int MAX_IMAGE_LENGTH = 50_000_000;
private static final Pattern COMMA_PATTERN = Pattern.compile(",");
@ -1873,12 +1874,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
short escherTag;
switch (format) {
case PICTURE_TYPE_WMF:
// remove first 22 bytes if file starts with magic bytes D7-CD-C6-9A
// see also http://de.wikipedia.org/wiki/Windows_Metafile#Hinweise_zur_WMF-Spezifikation
if (LittleEndian.getInt(pictureData) == 0x9AC6CDD7) {
byte[] picDataNoHeader = new byte[pictureData.length - 22];
System.arraycopy(pictureData, 22, picDataNoHeader, 0, pictureData.length-22);
pictureData = picDataNoHeader;
// remove first 22 bytes if file starts with the WMF placeable header
if (FileMagic.valueOf(pictureData) == FileMagic.WMF) {
pictureData = IOUtils.safelyClone(pictureData, 22, pictureData.length - 22, MAX_IMAGE_LENGTH);
}
// fall through
case PICTURE_TYPE_EMF:

View File

@ -135,8 +135,7 @@ public class BinaryRC4Decryptor extends Decryptor {
hashAlg.update(salt);
}
hash = new byte[5];
System.arraycopy(hashAlg.digest(), 0, hash, 0, 5);
hash = Arrays.copyOf(hashAlg.digest(), 5);
return new SecretKeySpec(hash, ver.getCipherAlgorithm().jceId);
}

View File

@ -206,9 +206,7 @@ public class Ole10Native {
if ((long)dataSize + (long)ofs > (long)data.length) { //cast to avoid overflow
throw new Ole10NativeException("Invalid Ole10Native: declared data length > available data");
}
dataBuffer = IOUtils.safelyAllocate(dataSize, MAX_RECORD_LENGTH);
System.arraycopy(data, ofs, dataBuffer, 0, dataSize);
ofs += dataSize;
dataBuffer = IOUtils.safelyClone(data, ofs, dataSize, MAX_RECORD_LENGTH);
}
/**

View File

@ -124,19 +124,13 @@ public abstract class Property implements Child, POIFSViewable {
*/
protected Property(int index, byte [] array, int offset)
{
_raw_data = new byte[ POIFSConstants.PROPERTY_SIZE ];
System.arraycopy(array, offset, _raw_data, 0,
POIFSConstants.PROPERTY_SIZE);
_raw_data = Arrays.copyOfRange(array, offset, offset + POIFSConstants.PROPERTY_SIZE);
_name_size = new ShortField(_name_size_offset, _raw_data);
_property_type =
new ByteField(PropertyConstants.PROPERTY_TYPE_OFFSET, _raw_data);
_property_type = new ByteField(PropertyConstants.PROPERTY_TYPE_OFFSET, _raw_data);
_node_color = new ByteField(_node_color_offset, _raw_data);
_previous_property = new IntegerField(_previous_property_offset,
_raw_data);
_next_property = new IntegerField(_next_property_offset,
_raw_data);
_child_property = new IntegerField(_child_property_offset,
_raw_data);
_previous_property = new IntegerField(_previous_property_offset, _raw_data);
_next_property = new IntegerField(_next_property_offset, _raw_data);
_child_property = new IntegerField(_child_property_offset, _raw_data);
_storage_clsid = new ClassID(_raw_data,_storage_clsid_offset);
_user_flags = new IntegerField(_user_flags_offset, 0, _raw_data);
_seconds_1 = new IntegerField(_seconds_1_offset, _raw_data);
@ -146,8 +140,7 @@ public abstract class Property implements Child, POIFSViewable {
_start_block = new IntegerField(_start_block_offset, _raw_data);
_size = new IntegerField(_size_offset, _raw_data);
_index = index;
int name_length = (_name_size.get() / LittleEndianConsts.SHORT_SIZE)
- 1;
int name_length = (_name_size.get() / LittleEndianConsts.SHORT_SIZE) - 1;
if (name_length < 1)
{

View File

@ -245,8 +245,7 @@ public class EmbeddedExtractor implements Iterable<EmbeddedExtractor> {
}
int pictureBytesLen = idxEnd-idxStart+6;
byte[] pdfBytes = IOUtils.safelyAllocate(pictureBytesLen, MAX_RECORD_LENGTH);
System.arraycopy(pictureBytes, idxStart, pdfBytes, 0, pictureBytesLen);
byte[] pdfBytes = IOUtils.safelyClone(pictureBytes, idxStart, pictureBytesLen, MAX_RECORD_LENGTH);
String filename = source.getShapeName().trim();
if (!endsWithIgnoreCase(filename, ".pdf")) {
filename += ".pdf";

View File

@ -18,6 +18,8 @@
package org.apache.poi.ss.formula.functions;
import java.util.Arrays;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
@ -60,8 +62,7 @@ public class Mirr extends MultiOperandNumericFunction {
double financeRate = values[values.length-1];
double reinvestRate = values[values.length-2];
double[] mirrValues = new double[values.length - 2];
System.arraycopy(values, 0, mirrValues, 0, mirrValues.length);
double[] mirrValues = Arrays.copyOf(values, values.length - 2);
boolean mirrValuesAreAllNegatives = true;
for (double mirrValue : mirrValues) {

View File

@ -17,6 +17,8 @@
package org.apache.poi.ss.formula.functions;
import java.util.Arrays;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.ThreeDEval;
import org.apache.poi.ss.formula.TwoDEval;
@ -67,20 +69,13 @@ public abstract class MultiOperandNumericFunction implements Function {
}
public double[] toArray() {
if (_count < 1) {
return EMPTY_DOUBLE_ARRAY;
}
double[] result = new double[_count];
System.arraycopy(_array, 0, result, 0, _count);
return result;
return _count < 1 ? EMPTY_DOUBLE_ARRAY : Arrays.copyOf(_array, _count);
}
private void ensureCapacity(int reqSize) {
if (reqSize > _array.length) {
int newSize = reqSize * 3 / 2; // grow with 50% extra
double[] newArr = new double[newSize];
System.arraycopy(_array, 0, newArr, 0, _count);
_array = newArr;
_array = Arrays.copyOf(_array, newSize);
}
}

View File

@ -17,6 +17,8 @@
package org.apache.poi.ss.formula.functions;
import java.util.Arrays;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.NumberEval;
@ -43,8 +45,7 @@ public final class Npv implements Function {
try {
double rate = NumericFunction.singleOperandEvaluate(args[0], srcRowIndex, srcColumnIndex);
// convert tail arguments into an array of doubles
ValueEval[] vargs = new ValueEval[args.length-1];
System.arraycopy(args, 1, vargs, 0, vargs.length);
ValueEval[] vargs = Arrays.copyOfRange(args, 1, args.length, ValueEval[].class);
double[] values = AggregateFunction.ValueCollector.collectValues(vargs);
double result = FinanceLib.npv(rate, values);

View File

@ -17,6 +17,8 @@
package org.apache.poi.ss.formula.functions;
import java.util.Arrays;
import org.apache.poi.ss.formula.TwoDEval;
import org.apache.poi.ss.formula.eval.AreaEval;
import org.apache.poi.ss.formula.eval.BlankEval;
@ -124,9 +126,9 @@ public final class Sumproduct implements Function {
private static ValueEval evaluateAreaSumProduct(ValueEval[] evalArgs) throws EvaluationException {
int maxN = evalArgs.length;
TwoDEval[] args = new TwoDEval[maxN];
TwoDEval[] args;
try {
System.arraycopy(evalArgs, 0, args, 0, maxN);
args = Arrays.copyOf(evalArgs, maxN, TwoDEval[].class);
} catch (ArrayStoreException e) {
// one of the other args was not an AreaRef
return ErrorEval.VALUE_INVALID;

View File

@ -18,6 +18,8 @@
package org.apache.poi.util;
import java.util.Arrays;
/**
* Utility classes for dealing with arrays.
*/
@ -54,8 +56,7 @@ public final class ArrayUtil {
}
// Grab the bit to move
Object[] toMove = new Object[numToMove];
System.arraycopy(array, moveFrom, toMove, 0, numToMove);
Object[] toMove = Arrays.copyOfRange(array, moveFrom, moveFrom+numToMove);
// Grab the bit to be shifted
Object[] toShift;
@ -63,14 +64,12 @@ public final class ArrayUtil {
if(moveFrom > moveTo) {
// Moving to an earlier point in the array
// Grab everything between the two points
toShift = new Object[(moveFrom-moveTo)];
System.arraycopy(array, moveTo, toShift, 0, toShift.length);
toShift = Arrays.copyOfRange(array, moveTo, moveFrom);
shiftTo = moveTo + numToMove;
} else {
// Moving to a later point in the array
// Grab everything from after the toMove block, to the new point
toShift = new Object[(moveTo-moveFrom)];
System.arraycopy(array, moveFrom+numToMove, toShift, 0, toShift.length);
toShift = Arrays.copyOfRange(array, moveFrom+numToMove, moveTo+numToMove);
shiftTo = moveFrom;
}

View File

@ -28,6 +28,7 @@ import java.io.OutputStream;
import java.io.PushbackInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.util.Arrays;
import java.util.zip.CRC32;
import java.util.zip.Checksum;
@ -35,6 +36,8 @@ import org.apache.poi.EmptyFileException;
import org.apache.poi.POIDocument;
import org.apache.poi.ss.usermodel.Workbook;
@Internal
public final class IOUtils {
private static final POILogger logger = POILogFactory.getLogger( IOUtils.class );
@ -610,6 +613,18 @@ public final class IOUtils {
checkLength(length, maxLength);
}
public static byte[] safelyClone(byte[] src, int offset, int length, int maxLength) {
if (src == null) {
return null;
}
assert(offset >= 0 && length >= 0 && maxLength >= 0);
safelyAllocateCheck(Math.min(src.length-offset,length), maxLength);
return Arrays.copyOfRange(src, offset, offset+length);
}
/**
* Simple utility function to check that you haven't hit EOF
* when reading a byte.

View File

@ -26,20 +26,16 @@ import java.io.Serializable;
* a utility class for handling little-endian numbers, which the 80x86 world is
* replete with. The methods are all static, and input/output is from/to byte
* arrays, or from InputStreams.
*
* @author Marc Johnson (mjohnson at apache dot org)
* @author Andrew Oliver (acoliver at apache dot org)
*/
public class LittleEndian implements LittleEndianConsts
{
@Internal
public final class LittleEndian implements LittleEndianConsts {
/**
* Exception to handle buffer underruns
*
* @author Marc Johnson (mjohnson at apache dot org)
*/
public static final class BufferUnderrunException extends IOException
{
public static final class BufferUnderrunException extends IOException {
/**
* Serial version UID
*
@ -47,61 +43,11 @@ public class LittleEndian implements LittleEndianConsts
*/
private static final long serialVersionUID = 8736973884877006145L;
BufferUnderrunException()
{
BufferUnderrunException() {
super( "buffer underrun" );
}
}
/**
* Copy a portion of a byte array
*
* @param data
* the original byte array
* @param offset
* Where to start copying from.
* @param size
* Number of bytes to copy.
* @return The byteArray value
*
* @see #getByteArray(byte[], int, int, int) if size is not a constant
*
* @throws IndexOutOfBoundsException
* - if copying would cause access of data outside array bounds.
*/
public static byte[] getByteArray( byte[] data, int offset, int size )
{
byte[] copy = new byte[size];
System.arraycopy( data, offset, copy, 0, size );
return copy;
}
/**
* Copy a portion of a byte array
*
* @param data
* the original byte array
* @param offset
* Where to start copying from.
* @param size
* Number of bytes to copy.
* @param maxSize
* Size must be <= maxSize or an exception is thrown.
* Use this to avoid potential OOMs on corrupt data.
* @return The byteArray value
* @throws IndexOutOfBoundsException
* - if copying would cause access of data outside array bounds.
*/
public static byte[] getByteArray( byte[] data, int offset, int size, int maxSize)
{
byte[] copy = IOUtils.safelyAllocate(size, maxSize);
System.arraycopy( data, offset, copy, 0, size );
return copy;
}
/**
* get a double value from a byte array, reads it in little endian format
* then converts the resulting revolting IEEE 754 (curse them) floating
@ -111,8 +57,7 @@ public class LittleEndian implements LittleEndianConsts
* the byte array
* @return the double (64-bit) value
*/
public static double getDouble( byte[] data )
{
public static double getDouble( byte[] data ) {
return Double.longBitsToDouble( getLong( data, 0 ) );
}
@ -127,8 +72,7 @@ public class LittleEndian implements LittleEndianConsts
* a starting offset into the byte array
* @return the double (64-bit) value
*/
public static double getDouble( byte[] data, int offset )
{
public static double getDouble( byte[] data, int offset ) {
return Double.longBitsToDouble( getLong( data, offset ) );
}
@ -141,8 +85,7 @@ public class LittleEndian implements LittleEndianConsts
* the byte array
* @return the double (64-bit) value
*/
public static float getFloat( byte[] data )
{
public static float getFloat( byte[] data ) {
return getFloat( data, 0 );
}
@ -157,8 +100,7 @@ public class LittleEndian implements LittleEndianConsts
* a starting offset into the byte array
* @return the double (64-bit) value
*/
public static float getFloat( byte[] data, int offset )
{
public static float getFloat( byte[] data, int offset ) {
return Float.intBitsToFloat( getInt( data, offset ) );
}
@ -169,8 +111,7 @@ public class LittleEndian implements LittleEndianConsts
* the byte array
* @return the int (32-bit) value
*/
public static int getInt( byte[] data )
{
public static int getInt( byte[] data ) {
return getInt( data, 0 );
}
@ -183,14 +124,13 @@ public class LittleEndian implements LittleEndianConsts
* a starting offset into the byte array
* @return the int (32-bit) value
*/
public static int getInt( byte[] data, int offset )
{
public static int getInt( byte[] data, int offset ) {
int i = offset;
int b0 = data[i++] & 0xFF;
int b1 = data[i++] & 0xFF;
int b2 = data[i++] & 0xFF;
int b3 = data[i++] & 0xFF;
return ( b3 << 24 ) + ( b2 << 16 ) + ( b1 << 8 ) + ( b0 << 0 );
int b3 = data[i ] & 0xFF;
return ( b3 << 24 ) + ( b2 << 16 ) + ( b1 << 8 ) + (b0);
}
/**
@ -200,8 +140,7 @@ public class LittleEndian implements LittleEndianConsts
* the byte array
* @return the long (64-bit) value
*/
public static long getLong( byte[] data )
{
public static long getLong( byte[] data ) {
return getLong( data, 0 );
}
@ -214,8 +153,7 @@ public class LittleEndian implements LittleEndianConsts
* a starting offset into the byte array
* @return the long (64-bit) value
*/
public static long getLong( byte[] data, int offset )
{
public static long getLong( byte[] data, int offset ) {
long result = 0xff & data[offset + 7];
for ( int j = offset + LONG_SIZE - 1; j >= offset; j-- )
@ -233,8 +171,7 @@ public class LittleEndian implements LittleEndianConsts
* the byte array
* @return the short (16-bit) value
*/
public static short getShort( byte[] data )
{
public static short getShort( byte[] data ) {
return getShort( data, 0 );
}
@ -247,11 +184,10 @@ public class LittleEndian implements LittleEndianConsts
* a starting offset into the byte array
* @return the short (16-bit) value
*/
public static short getShort( byte[] data, int offset )
{
public static short getShort( byte[] data, int offset ) {
int b0 = data[offset] & 0xFF;
int b1 = data[offset + 1] & 0xFF;
return (short) ( ( b1 << 8 ) + ( b0 << 0 ) );
return (short) ( ( b1 << 8 ) + (b0) );
}
/**
@ -266,8 +202,7 @@ public class LittleEndian implements LittleEndianConsts
* @throws IndexOutOfBoundsException
* - if read would cause access of data outside array bounds.
*/
public static short[] getShortArray( byte[] data, int offset, int size )
{
public static short[] getShortArray( byte[] data, int offset, int size ) {
short[] result = new short[size / SHORT_SIZE];
for ( int i = 0; i < result.length; i++ )
{
@ -283,8 +218,7 @@ public class LittleEndian implements LittleEndianConsts
* the byte array.
* @return the unsigned value of the byte as a 16 bit short
*/
public static short getUByte( byte[] data )
{
public static short getUByte( byte[] data ) {
return (short) ( data[0] & 0xFF );
}
@ -297,8 +231,7 @@ public class LittleEndian implements LittleEndianConsts
* a starting offset into the byte array.
* @return the unsigned value of the byte as a 16 bit short
*/
public static short getUByte( byte[] data, int offset )
{
public static short getUByte( byte[] data, int offset ) {
return (short) ( data[offset] & 0xFF );
}
@ -309,8 +242,7 @@ public class LittleEndian implements LittleEndianConsts
* the byte array
* @return the unsigned int (32-bit) value in a long
*/
public static long getUInt( byte[] data )
{
public static long getUInt( byte[] data ) {
return getUInt( data, 0 );
}
@ -323,10 +255,9 @@ public class LittleEndian implements LittleEndianConsts
* a starting offset into the byte array
* @return the unsigned int (32-bit) value in a long
*/
public static long getUInt( byte[] data, int offset )
{
public static long getUInt( byte[] data, int offset ) {
long retNum = getInt( data, offset );
return retNum & 0x00FFFFFFFFl;
return retNum & 0x00FFFFFFFFL;
}
/**
@ -336,8 +267,7 @@ public class LittleEndian implements LittleEndianConsts
* the byte array
* @return the unsigned short (16-bit) value in an int
*/
public static int getUShort( byte[] data )
{
public static int getUShort( byte[] data ) {
return getUShort( data, 0 );
}
@ -350,11 +280,10 @@ public class LittleEndian implements LittleEndianConsts
* a starting offset into the byte array
* @return the unsigned short (16-bit) value in an integer
*/
public static int getUShort( byte[] data, int offset )
{
public static int getUShort( byte[] data, int offset ) {
int b0 = data[offset] & 0xFF;
int b1 = data[offset + 1] & 0xFF;
return ( b1 << 8 ) + ( b0 << 0 );
return ( b1 << 8 ) + (b0);
}
/**
@ -366,8 +295,7 @@ public class LittleEndian implements LittleEndianConsts
* </p>
* Added for consistency with other put~() methods
*/
public static void putByte( byte[] data, int offset, int value )
{
public static void putByte( byte[] data, int offset, int value ) {
data[offset] = (byte) value;
}
@ -381,8 +309,7 @@ public class LittleEndian implements LittleEndianConsts
* @param value
* the double (64-bit) value
*/
public static void putDouble( byte[] data, int offset, double value )
{
public static void putDouble( byte[] data, int offset, double value ) {
putLong( data, offset, Double.doubleToLongBits( value ) );
}
@ -396,9 +323,7 @@ public class LittleEndian implements LittleEndianConsts
* @throws IOException
* if an I/O error occurs
*/
public static void putDouble( double value, OutputStream outputStream )
throws IOException
{
public static void putDouble( double value, OutputStream outputStream ) throws IOException {
putLong( Double.doubleToLongBits( value ), outputStream );
}
@ -412,8 +337,7 @@ public class LittleEndian implements LittleEndianConsts
* @param value
* the float (32-bit) value
*/
public static void putFloat( byte[] data, int offset, float value )
{
public static void putFloat( byte[] data, int offset, float value ) {
putInt( data, offset, Float.floatToIntBits( value ) );
}
@ -427,9 +351,8 @@ public class LittleEndian implements LittleEndianConsts
* @throws IOException
* if an I/O error occurs
*/
public static void putFloat( float value, OutputStream outputStream )
throws IOException
{
@SuppressWarnings("unused")
public static void putFloat(float value, OutputStream outputStream ) throws IOException {
putInt( Float.floatToIntBits( value ), outputStream );
}
@ -443,13 +366,12 @@ public class LittleEndian implements LittleEndianConsts
* @param value
* the int (32-bit) value
*/
public static void putInt( byte[] data, int offset, int value )
{
public static void putInt( byte[] data, int offset, int value ) {
int i = offset;
data[i++] = (byte) ( ( value >>> 0 ) & 0xFF );
data[i++] = (byte) ( ( value ) & 0xFF );
data[i++] = (byte) ( ( value >>> 8 ) & 0xFF );
data[i++] = (byte) ( ( value >>> 16 ) & 0xFF );
data[i++] = (byte) ( ( value >>> 24 ) & 0xFF );
data[i] = (byte) ( ( value >>> 24 ) & 0xFF );
}
/**
@ -462,10 +384,8 @@ public class LittleEndian implements LittleEndianConsts
* @throws IOException
* if an I/O error occurs
*/
public static void putInt( int value, OutputStream outputStream )
throws IOException
{
outputStream.write( (byte) ( ( value >>> 0 ) & 0xFF ) );
public static void putInt( int value, OutputStream outputStream ) throws IOException {
outputStream.write( (byte) ( ( value ) & 0xFF ) );
outputStream.write( (byte) ( ( value >>> 8 ) & 0xFF ) );
outputStream.write( (byte) ( ( value >>> 16 ) & 0xFF ) );
outputStream.write( (byte) ( ( value >>> 24 ) & 0xFF ) );
@ -481,9 +401,8 @@ public class LittleEndian implements LittleEndianConsts
* @param value
* the long (64-bit) value
*/
public static void putLong( byte[] data, int offset, long value )
{
data[offset + 0] = (byte) ( ( value >>> 0 ) & 0xFF );
public static void putLong( byte[] data, int offset, long value ) {
data[offset ] = (byte) ( ( value ) & 0xFF );
data[offset + 1] = (byte) ( ( value >>> 8 ) & 0xFF );
data[offset + 2] = (byte) ( ( value >>> 16 ) & 0xFF );
data[offset + 3] = (byte) ( ( value >>> 24 ) & 0xFF );
@ -503,10 +422,8 @@ public class LittleEndian implements LittleEndianConsts
* @throws IOException
* if an I/O error occurs
*/
public static void putLong( long value, OutputStream outputStream )
throws IOException
{
outputStream.write( (byte) ( ( value >>> 0 ) & 0xFF ) );
public static void putLong( long value, OutputStream outputStream ) throws IOException {
outputStream.write( (byte) ( ( value ) & 0xFF ) );
outputStream.write( (byte) ( ( value >>> 8 ) & 0xFF ) );
outputStream.write( (byte) ( ( value >>> 16 ) & 0xFF ) );
outputStream.write( (byte) ( ( value >>> 24 ) & 0xFF ) );
@ -526,11 +443,10 @@ public class LittleEndian implements LittleEndianConsts
* @param value
* the short (16-bit) value
*/
public static void putShort( byte[] data, int offset, short value )
{
public static void putShort( byte[] data, int offset, short value ) {
int i = offset;
data[i++] = (byte) ( ( value >>> 0 ) & 0xFF );
data[i++] = (byte) ( ( value >>> 8 ) & 0xFF );
data[i++] = (byte) ( ( value ) & 0xFF );
data[i ] = (byte) ( ( value >>> 8 ) & 0xFF );
}
/**
@ -543,10 +459,8 @@ public class LittleEndian implements LittleEndianConsts
* @throws IOException
* if an I/O error occurs
*/
public static void putShort( OutputStream outputStream, short value )
throws IOException
{
outputStream.write( (byte) ( ( value >>> 0 ) & 0xFF ) );
public static void putShort( OutputStream outputStream, short value ) throws IOException {
outputStream.write( (byte) ( ( value ) & 0xFF ) );
outputStream.write( (byte) ( ( value >>> 8 ) & 0xFF ) );
}
@ -560,9 +474,7 @@ public class LittleEndian implements LittleEndianConsts
* @param value
* the short (16-bit) values
*/
public static void putShortArray( byte[] data, int startOffset,
short[] value )
{
public static void putShortArray( byte[] data, int startOffset, short[] value ) {
int offset = startOffset;
for ( short s : value )
{
@ -584,8 +496,7 @@ public class LittleEndian implements LittleEndianConsts
* @exception ArrayIndexOutOfBoundsException
* may be thrown
*/
public static void putUByte( byte[] data, int offset, short value )
{
public static void putUByte( byte[] data, int offset, short value ) {
data[offset] = (byte) ( value & 0xFF );
}
@ -602,13 +513,12 @@ public class LittleEndian implements LittleEndianConsts
* @exception ArrayIndexOutOfBoundsException
* may be thrown
*/
public static void putUInt( byte[] data, int offset, long value )
{
public static void putUInt( byte[] data, int offset, long value ) {
int i = offset;
data[i++] = (byte) ( ( value >>> 0 ) & 0xFF );
data[i++] = (byte) ( ( value ) & 0xFF );
data[i++] = (byte) ( ( value >>> 8 ) & 0xFF );
data[i++] = (byte) ( ( value >>> 16 ) & 0xFF );
data[i++] = (byte) ( ( value >>> 24 ) & 0xFF );
data[i ] = (byte) ( ( value >>> 24 ) & 0xFF );
}
/**
@ -621,10 +531,8 @@ public class LittleEndian implements LittleEndianConsts
* @throws IOException
* if an I/O error occurs
*/
public static void putUInt( long value, OutputStream outputStream )
throws IOException
{
outputStream.write( (byte) ( ( value >>> 0 ) & 0xFF ) );
public static void putUInt( long value, OutputStream outputStream ) throws IOException {
outputStream.write( (byte) ( ( value ) & 0xFF ) );
outputStream.write( (byte) ( ( value >>> 8 ) & 0xFF ) );
outputStream.write( (byte) ( ( value >>> 16 ) & 0xFF ) );
outputStream.write( (byte) ( ( value >>> 24 ) & 0xFF ) );
@ -643,11 +551,10 @@ public class LittleEndian implements LittleEndianConsts
* @exception ArrayIndexOutOfBoundsException
* may be thrown
*/
public static void putUShort( byte[] data, int offset, int value )
{
public static void putUShort( byte[] data, int offset, int value ) {
int i = offset;
data[i++] = (byte) ( ( value >>> 0 ) & 0xFF );
data[i++] = (byte) ( ( value >>> 8 ) & 0xFF );
data[i++] = (byte) ( ( value ) & 0xFF );
data[i ] = (byte) ( ( value >>> 8 ) & 0xFF );
}
/**
@ -660,10 +567,8 @@ public class LittleEndian implements LittleEndianConsts
* @throws IOException
* if an I/O error occurs
*/
public static void putUShort( int value, OutputStream outputStream )
throws IOException
{
outputStream.write( (byte) ( ( value >>> 0 ) & 0xFF ) );
public static void putUShort( int value, OutputStream outputStream ) throws IOException {
outputStream.write( (byte) ( ( value ) & 0xFF ) );
outputStream.write( (byte) ( ( value >>> 8 ) & 0xFF ) );
}
@ -678,9 +583,7 @@ public class LittleEndian implements LittleEndianConsts
* @exception BufferUnderrunException
* if the stream cannot provide enough bytes
*/
public static int readInt( InputStream stream ) throws IOException,
BufferUnderrunException
{
public static int readInt( InputStream stream ) throws IOException {
int ch1 = stream.read();
int ch2 = stream.read();
int ch3 = stream.read();
@ -689,7 +592,7 @@ public class LittleEndian implements LittleEndianConsts
{
throw new BufferUnderrunException();
}
return ( ch4 << 24 ) + ( ch3 << 16 ) + ( ch2 << 8 ) + ( ch1 << 0 );
return ( ch4 << 24 ) + ( ch3 << 16 ) + ( ch2 << 8 ) + ( ch1 );
}
/**
@ -703,11 +606,9 @@ public class LittleEndian implements LittleEndianConsts
* @exception BufferUnderrunException
* if the stream cannot provide enough bytes
*/
public static long readUInt( InputStream stream ) throws IOException,
BufferUnderrunException
{
public static long readUInt( InputStream stream ) throws IOException {
long retNum = readInt(stream);
return retNum & 0x00FFFFFFFFl;
return retNum & 0x00FFFFFFFFL;
}
/**
@ -721,9 +622,7 @@ public class LittleEndian implements LittleEndianConsts
* @exception BufferUnderrunException
* if the stream cannot provide enough bytes
*/
public static long readLong( InputStream stream ) throws IOException,
BufferUnderrunException
{
public static long readLong( InputStream stream ) throws IOException {
int ch1 = stream.read();
int ch2 = stream.read();
int ch3 = stream.read();
@ -732,8 +631,7 @@ public class LittleEndian implements LittleEndianConsts
int ch6 = stream.read();
int ch7 = stream.read();
int ch8 = stream.read();
if ( ( ch1 | ch2 | ch3 | ch4 | ch5 | ch6 | ch7 | ch8 ) < 0 )
{
if ( ( ch1 | ch2 | ch3 | ch4 | ch5 | ch6 | ch7 | ch8 ) < 0 ) {
throw new BufferUnderrunException();
}
@ -741,7 +639,7 @@ public class LittleEndian implements LittleEndianConsts
+ ( (long) ch6 << 40 ) + ( (long) ch5 << 32 )
+ ( (long) ch4 << 24 ) + // cast to long to preserve bit 31
// (sign bit for ints)
( ch3 << 16 ) + ( ch2 << 8 ) + ( ch1 << 0 );
( ch3 << 16 ) + ( ch2 << 8 ) + ( ch1 );
}
/**
@ -755,22 +653,17 @@ public class LittleEndian implements LittleEndianConsts
* @exception BufferUnderrunException
* if the stream cannot provide enough bytes
*/
public static short readShort( InputStream stream ) throws IOException,
BufferUnderrunException
{
public static short readShort( InputStream stream ) throws IOException {
return (short) readUShort( stream );
}
public static int readUShort( InputStream stream ) throws IOException,
BufferUnderrunException
{
public static int readUShort( InputStream stream ) throws IOException {
int ch1 = stream.read();
int ch2 = stream.read();
if ( ( ch1 | ch2 ) < 0 )
{
if ( ( ch1 | ch2 ) < 0 ) {
throw new BufferUnderrunException();
}
return ( ch2 << 8 ) + ( ch1 << 0 );
return ( ch2 << 8 ) + ( ch1 );
}
/**
@ -781,13 +674,11 @@ public class LittleEndian implements LittleEndianConsts
* Description of the Parameter
* @return Description of the Return Value
*/
public static int ubyteToInt( byte b )
{
public static int ubyteToInt( byte b ) {
return b & 0xFF;
}
private LittleEndian()
{
private LittleEndian() {
// no instances of this class
}
}

View File

@ -65,6 +65,9 @@ public final class StringUtil {
final int offset,
final int len)
throws ArrayIndexOutOfBoundsException, IllegalArgumentException {
if (len == 0) {
return "";
}
if ((offset < 0) || (offset >= string.length)) {
throw new ArrayIndexOutOfBoundsException("Illegal offset " + offset + " (String data is of length " + string.length + ")");
}

View File

@ -215,14 +215,8 @@ public class XSSFColor extends ExtendedColor {
return null;
}
if(rgb.length == 4) {
// Need to trim off the alpha
byte[] tmp = new byte[3];
System.arraycopy(rgb, 1, tmp, 0, 3);
return tmp;
} else {
return rgb;
}
return rgb.length == 4 ? Arrays.copyOfRange(rgb, 1, 4) : rgb;
}
/**

View File

@ -188,8 +188,7 @@ public final class ChunkFactory {
}
// Now, create the chunk
byte[] contents = IOUtils.safelyAllocate(header.getLength(), MAX_RECORD_LENGTH);
System.arraycopy(data, offset+header.getSizeInBytes(), contents, 0, contents.length);
byte[] contents = IOUtils.safelyClone(data, offset+header.getSizeInBytes(), header.getLength(), MAX_RECORD_LENGTH);
Chunk chunk = new Chunk(header, trailer, separator, contents);
// Feed in the stuff from chunks_parse_cmds.tbl

View File

@ -17,16 +17,17 @@
package org.apache.poi.hdgf.chunks;
import java.util.Arrays;
/**
* A separator between the trailer of one chunk, and the
* header of the next one
*/
public final class ChunkSeparator {
protected byte[] separatorData;
final byte[] separatorData;
public ChunkSeparator(byte[] data, int offset) {
separatorData = new byte[4];
System.arraycopy(data, offset, separatorData, 0, 4);
separatorData = Arrays.copyOfRange(data, offset, offset+4);
}
public String toString() {

View File

@ -17,15 +17,16 @@
package org.apache.poi.hdgf.chunks;
import java.util.Arrays;
/**
* A trailer that follows a chunk
*/
public final class ChunkTrailer {
private byte[] trailerData;
private final byte[] trailerData;
public ChunkTrailer(byte[] data, int offset) {
trailerData = new byte[8];
System.arraycopy(data, offset, trailerData, 0, 8);
trailerData = Arrays.copyOfRange(data, offset, offset+8);
}
public String toString() {

View File

@ -38,21 +38,19 @@ public final class CompressedStreamStore extends StreamStore {
* We're not sure what this is, but it comes before the
* real contents in the de-compressed data
*/
private byte[] blockHeader = new byte[4];
private final byte[] blockHeader;
private boolean blockHeaderInContents;
protected byte[] _getCompressedContents() { return compressedContents; }
protected byte[] _getBlockHeader() { return blockHeader; }
byte[] _getCompressedContents() { return compressedContents; }
byte[] _getBlockHeader() { return blockHeader; }
/**
* Creates a new compressed StreamStore, which will handle
* the decompression.
*/
protected CompressedStreamStore(byte[] data, int offset, int length) throws IOException {
CompressedStreamStore(byte[] data, int offset, int length) throws IOException {
this(decompress(data,offset,length));
compressedContents = IOUtils.safelyAllocate(length, MAX_RECORD_LENGTH);
System.arraycopy(data, offset, compressedContents, 0, length);
compressedContents = IOUtils.safelyClone(data, offset, length, MAX_RECORD_LENGTH);
}
/**
* Handles passing the de-compressed data onto our superclass.

View File

@ -34,8 +34,7 @@ public class StreamStore { // TODO - instantiable superclass
* Creates a new, non compressed Stream Store
*/
protected StreamStore(byte[] data, int offset, int length) {
contents = IOUtils.safelyAllocate(length, MAX_RECORD_LENGTH);
System.arraycopy(data, offset, contents, 0, length);
contents = IOUtils.safelyClone(data, offset, length, MAX_RECORD_LENGTH);
}
protected void prependContentsWith(byte[] b) {

View File

@ -20,7 +20,7 @@ package org.apache.poi.hmef;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LZWDecompresser;
@ -120,7 +120,7 @@ public final class CompressedRTF extends LZWDecompresser {
@Override
protected int populateDictionary(byte[] dict) {
// Copy in the RTF constants
byte[] preload = LZW_RTF_PRELOAD.getBytes(Charset.forName("US-ASCII"));
byte[] preload = LZW_RTF_PRELOAD.getBytes(StandardCharsets.US_ASCII);
System.arraycopy(preload, 0, dict, 0, preload.length);
// Start adding new codes after the constants

View File

@ -21,6 +21,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.poi.hmef.Attachment;
@ -73,8 +74,7 @@ public class MAPIAttribute {
if(data.length <= 16) {
hex = HexDump.toHex(data);
} else {
byte[] d = new byte[16];
System.arraycopy(data, 0, d, 0, 16);
byte[] d = Arrays.copyOf(data, 16);
hex = HexDump.toHex(d);
hex = hex.substring(0, hex.length()-1) + ", ....]";
}

View File

@ -46,8 +46,7 @@ public final class MAPIRtfAttribute extends MAPIAttribute {
CompressedRTF rtf = new CompressedRTF();
byte[] tmp = rtf.decompress(new ByteArrayInputStream(data));
if(tmp.length > rtf.getDeCompressedSize()) {
this.decompressed = IOUtils.safelyAllocate(rtf.getDeCompressedSize(), MAX_RECORD_LENGTH);
System.arraycopy(tmp, 0, decompressed, 0, decompressed.length);
this.decompressed = IOUtils.safelyClone(tmp, 0, rtf.getDeCompressedSize(), MAX_RECORD_LENGTH);
} else {
this.decompressed = tmp;
}

View File

@ -140,8 +140,7 @@ public final class HMEFDumper {
thisLen = len - offset;
}
byte[] data = IOUtils.safelyAllocate(thisLen, MAX_RECORD_LENGTH);
System.arraycopy(attr.getData(), offset, data, 0, thisLen);
byte[] data = IOUtils.safelyClone(attr.getData(), offset, thisLen, MAX_RECORD_LENGTH);
System.out.print(
indent + HexDump.dump(data, 0, 0)

View File

@ -69,8 +69,7 @@ public final class QuillContents extends HPBFPart {
int from = (int)LittleEndian.getUInt(data, offset+16);
int len = (int)LittleEndian.getUInt(data, offset+20);
byte[] bitData = IOUtils.safelyAllocate(len, MAX_RECORD_LENGTH);
System.arraycopy(data, from, bitData, 0, len);
byte[] bitData = IOUtils.safelyClone(data, from, len, MAX_RECORD_LENGTH);
// Create
if(bitType.equals("TEXT")) {

View File

@ -39,9 +39,7 @@ public abstract class Bitmap extends HSLFPictureData {
public byte[] getData(){
byte[] rawdata = getRawData();
int prefixLen = 16*getUIDInstanceCount()+1;
byte[] imgdata = IOUtils.safelyAllocate(rawdata.length-prefixLen, rawdata.length);
System.arraycopy(rawdata, prefixLen, imgdata, 0, imgdata.length);
return imgdata;
return IOUtils.safelyClone(rawdata, prefixLen, rawdata.length-prefixLen, rawdata.length);
}
@Override

View File

@ -102,8 +102,7 @@ public final class DIB extends Bitmap {
@Override
public void setData(byte[] data) throws IOException {
//cut off the bitmap file-header
byte[] dib = IOUtils.safelyAllocate(data.length-HEADER_SIZE, data.length);
System.arraycopy(data, HEADER_SIZE, dib, 0, dib.length);
byte[] dib = IOUtils.safelyClone(data, HEADER_SIZE, data.length-HEADER_SIZE, data.length);
super.setData(dib);
}
}

View File

@ -161,7 +161,7 @@ public final class PICT extends Metafile {
}
for (int i = 1; i < len; i += i) {
System.arraycopy(array, 0, array, i, ((len - i) < i) ? (len - i) : i);
System.arraycopy(array, 0, array, i, Math.min(len - i, i));
}
}
}

View File

@ -26,6 +26,7 @@ import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import org.apache.poi.hslf.record.RecordTypes;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
@ -161,20 +162,18 @@ public final class PPTXMLDump {
public void dumpPictures(byte[] data, int padding) throws IOException {
int pos = 0;
while (pos < data.length) {
byte[] header = new byte[PICT_HEADER_SIZE];
if(data.length - pos < header.length) {
if(data.length - pos < PICT_HEADER_SIZE) {
// corrupt file, cannot read header
return;
}
System.arraycopy(data, pos, header, 0, header.length);
byte[] header = Arrays.copyOfRange(data, pos, pos + PICT_HEADER_SIZE);
int size = LittleEndian.getInt(header, 4) - 17;
if(size < 0) {
// corrupt file, negative image size
return;
}
byte[] pictdata = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH);
System.arraycopy(data, pos + PICT_HEADER_SIZE, pictdata, 0, pictdata.length);
byte[] pictdata = IOUtils.safelyClone(data, pos + PICT_HEADER_SIZE, size, MAX_RECORD_LENGTH);
pos += PICT_HEADER_SIZE + size;
padding++;

View File

@ -213,8 +213,7 @@ public void walkTree(int depth, int startPos, int maxLen) throws IOException {
final String ind = (indent == 0) ? "%1$s" : "%1$"+indent+"s";
byte[] contents = IOUtils.safelyAllocate(len, MAX_RECORD_LENGTH);
System.arraycopy(docstream,pos,contents,0,len);
byte[] contents = IOUtils.safelyClone(docstream, pos, len, MAX_RECORD_LENGTH);
DefaultEscherRecordFactory erf = new HSLFEscherRecordFactory();
EscherRecord record = erf.createRecord(contents,0);

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
@ -39,8 +40,7 @@ public final class AnimationInfo extends RecordContainer {
*/
protected AnimationInfo(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);

View File

@ -21,6 +21,7 @@ import static org.apache.poi.util.GenericRecordUtil.getBitsAsString;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -101,7 +102,7 @@ public final class AnimationInfoAtom extends RecordAtom {
/**
* record data
*/
private byte[] _recdata;
private final byte[] _recdata;
/**
* Constructs a brand new link related atom record.
@ -125,12 +126,10 @@ public final class AnimationInfoAtom extends RecordAtom {
*/
protected AnimationInfoAtom(byte[] source, int start, int len) {
// Get the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Grab the record data
_recdata = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
System.arraycopy(source,start+8,_recdata,0,len-8);
_recdata = IOUtils.safelyClone(source,start+8, len-8, MAX_RECORD_LENGTH);
}
/**

View File

@ -17,9 +17,11 @@
package org.apache.poi.hslf.record;
import org.apache.poi.util.LittleEndian;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import org.apache.poi.util.LittleEndian;
/**
* If we come across a record we know has children of (potential)
@ -44,8 +46,7 @@ public final class BinaryTagDataBlob extends PositionDependentRecordContainer
*/
protected BinaryTagDataBlob(byte[] source, int start, int len) {
// Just grab the header, not the whole contents
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
_type = LittleEndian.getUShort(_header,2);
// Find our children

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -86,12 +87,10 @@ public final class CString extends RecordAtom {
if(len < 8) { len = 8; }
// Get the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Grab the text
_text = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
System.arraycopy(source,start+8,_text,0,len-8);
_text = IOUtils.safelyClone(source,start+8, len-8, MAX_RECORD_LENGTH);
}
/**
* Create an empty CString

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.record;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
@ -108,11 +109,10 @@ public final class ColorSchemeAtom extends RecordAtom {
}
// Get the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Grab the rgb values
backgroundColourRGB = LittleEndian.getInt(source,start+8+0);
backgroundColourRGB = LittleEndian.getInt(source, start+8);
textAndLinesColourRGB = LittleEndian.getInt(source,start+8+4);
shadowsColourRGB = LittleEndian.getInt(source,start+8+8);
titleTextColourRGB = LittleEndian.getInt(source,start+8+12);

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
@ -101,8 +102,7 @@ public final class Comment2000 extends RecordContainer {
*/
protected Comment2000(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Find our children
_children = org.apache.poi.hslf.record.Record.findChildRecords(source,start+8,len-8);

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;
import java.util.function.Supplier;
@ -72,12 +73,10 @@ public final class Comment2000Atom extends RecordAtom
*/
protected Comment2000Atom(byte[] source, int start, int len) {
// Get the header.
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Get the record data.
_data = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
System.arraycopy(source,start+8,_data,0,len-8);
_data = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH);
}
/**

View File

@ -192,17 +192,12 @@ public class CurrentUserAtom
// Grab the unicode username, if stored
int start = 28+(int)usernameLen+4;
int len = 2*(int)usernameLen;
if(_contents.length >= start+len) {
byte[] textBytes = IOUtils.safelyAllocate(len, MAX_RECORD_LENGTH);
System.arraycopy(_contents,start,textBytes,0,len);
lastEditUser = StringUtil.getFromUnicodeLE(textBytes);
if(_contents.length >= start+2*usernameLen) {
lastEditUser = StringUtil.getFromUnicodeLE(_contents, start, (int)usernameLen);
} else {
// Fake from the 8 bit version
byte[] textBytes = IOUtils.safelyAllocate(usernameLen, MAX_RECORD_LENGTH);
System.arraycopy(_contents,28,textBytes,0,(int)usernameLen);
lastEditUser = StringUtil.getFromCompressedUnicode(textBytes,0,(int)usernameLen);
lastEditUser = StringUtil.getFromCompressedUnicode(_contents, 28, (int)usernameLen);
}
}

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -38,8 +39,7 @@ public final class DocInfoListContainer extends RecordContainer {
*/
protected DocInfoListContainer(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source,start,start+8);
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);

View File

@ -17,11 +17,12 @@
package org.apache.poi.hslf.record;
import org.apache.poi.util.POILogger;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import org.apache.poi.util.POILogger;
/**
* Master container for Document. There is one of these for every
@ -126,8 +127,7 @@ public final class Document extends PositionDependentRecordContainer
*/
/* package */ Document(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.record;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -51,8 +52,7 @@ public final class DocumentEncryptionAtom extends PositionDependentRecordAtom {
*/
protected DocumentEncryptionAtom(byte[] source, int start, int len) {
// Get the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source,start,start+8);
ByteArrayInputStream bis = new ByteArrayInputStream(source, start+8, len-8);
try (LittleEndianInputStream leis = new LittleEndianInputStream(bis)) {

View File

@ -17,9 +17,11 @@
package org.apache.poi.hslf.record;
import org.apache.poi.util.LittleEndian;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import org.apache.poi.util.LittleEndian;
/**
* If we come across a record we know has children of (potential)
@ -44,8 +46,7 @@ public final class DummyPositionSensitiveRecordWithChildren extends PositionDepe
*/
protected DummyPositionSensitiveRecordWithChildren(byte[] source, int start, int len) {
// Just grab the header, not the whole contents
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source,start,start+8);
_type = LittleEndian.getUShort(_header,2);
// Find our children

View File

@ -17,9 +17,11 @@
package org.apache.poi.hslf.record;
import org.apache.poi.util.LittleEndian;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import org.apache.poi.util.LittleEndian;
/**
* If we come across a record we know has children of (potential)
@ -39,8 +41,7 @@ public final class DummyRecordWithChildren extends RecordContainer
*/
protected DummyRecordWithChildren(byte[] source, int start, int len) {
// Just grab the header, not the whole contents
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
_type = LittleEndian.getUShort(_header,2);
// Find our children

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
/**
* Environment, which contains lots of settings for the document.
@ -47,8 +48,7 @@ public final class Environment extends PositionDependentRecordContainer
*/
protected Environment(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -63,8 +64,7 @@ public final class ExControlAtom extends RecordAtom {
*/
protected ExControlAtom(byte[] source, int start, int len) {
// Get the header.
_header = new byte[8];
System.arraycopy(source, start, _header, 0, 8);
_header = Arrays.copyOfRange(source, start, start+8);
_id = LittleEndian.getInt(source, start + 8);
}

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
@ -49,8 +50,7 @@ public class ExEmbed extends RecordContainer {
*/
protected ExEmbed(final byte[] source, final int start, final int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -94,12 +95,10 @@ public class ExEmbedAtom extends RecordAtom {
*/
protected ExEmbedAtom(byte[] source, int start, int len) {
// Get the header.
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Get the record data.
_data = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
System.arraycopy(source,start+8,_data,0,len-8);
_data = IOUtils.safelyClone(source,start+8,len-8, MAX_RECORD_LENGTH);
// Must be at least 8 bytes long
if(_data.length < 8) {

View File

@ -18,6 +18,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
@ -99,8 +100,7 @@ public class ExHyperlink extends RecordContainer {
*/
protected ExHyperlink(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -70,12 +71,10 @@ public final class ExHyperlinkAtom extends RecordAtom {
*/
protected ExHyperlinkAtom(byte[] source, int start, int len) {
// Get the header.
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Get the record data.
_data = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
System.arraycopy(source,start+8,_data,0,len-8);
_data = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH);
// Must be at least 4 bytes long
if(_data.length < 4) {

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
@ -39,8 +40,7 @@ public class ExMCIMovie extends RecordContainer { // TODO - instantiable supercl
*/
protected ExMCIMovie(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source, start, _header, 0, 8);
_header = Arrays.copyOfRange(source, start, start+8);
// Find our children
_children = Record.findChildRecords(source, start + 8, len - 8);

View File

@ -21,6 +21,7 @@ import static org.apache.poi.util.GenericRecordUtil.getBitsAsString;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -89,12 +90,10 @@ public final class ExMediaAtom extends RecordAtom
*/
protected ExMediaAtom(byte[] source, int start, int len) {
// Get the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Grab the record data
_recdata = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
System.arraycopy(source,start+8,_recdata,0,len-8);
_recdata = IOUtils.safelyClone(source,start+8, len-8, MAX_RECORD_LENGTH);
}
/**

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import org.apache.poi.util.LittleEndian;
@ -58,8 +59,7 @@ public class ExObjList extends RecordContainer {
*/
protected ExObjList(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -72,12 +73,10 @@ public class ExObjListAtom extends RecordAtom
*/
protected ExObjListAtom(byte[] source, int start, int len) {
// Get the header.
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Get the record data.
_data = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
System.arraycopy(source,start+8,_data,0,len-8);
_data = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH);
// Must be at least 4 bytes long
if(_data.length < 4) {

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -61,11 +62,8 @@ public final class ExObjRefAtom extends RecordAtom {
* @param len the length of the slice in the byte array.
*/
protected ExObjRefAtom(byte[] source, int start, int len) {
_header = new byte[8];
int offset = start;
System.arraycopy(source,start,_header,0,8);
offset += _header.length;
exObjIdRef = (int)LittleEndian.getUInt(source, offset);
_header = Arrays.copyOfRange(source, start, start+8);
exObjIdRef = (int)LittleEndian.getUInt(source, start+8);
}
/**

View File

@ -22,6 +22,7 @@ import static org.apache.poi.util.GenericRecordUtil.safeEnum;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -187,12 +188,10 @@ public class ExOleObjAtom extends RecordAtom {
*/
protected ExOleObjAtom(byte[] source, int start, int len) {
// Get the header.
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Get the record data.
_data = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
System.arraycopy(source,start+8,_data,0,len-8);
_data = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH);
// Must be at least 24 bytes long
if(_data.length < 24) {

View File

@ -22,6 +22,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
import java.util.zip.DeflaterOutputStream;
@ -74,12 +75,10 @@ public class ExOleObjStg extends PositionDependentRecordAtom implements PersistR
*/
protected ExOleObjStg(byte[] source, int start, int len) {
// Get the header.
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Get the record data.
_data = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
System.arraycopy(source,start+8,_data,0,len-8);
_data = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH);
}
public boolean isCompressed() {

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
@ -41,8 +42,7 @@ public final class ExVideoContainer extends RecordContainer {
*/
protected ExVideoContainer(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);

View File

@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -47,8 +48,7 @@ public final class FontCollection extends RecordContainer {
private byte[] _header;
/* package */ FontCollection(byte[] source, int start, int len) {
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
_children = Record.findChildRecords(source,start+8,len-8);

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -63,12 +64,10 @@ public class FontEmbeddedData extends RecordAtom implements FontFacet {
*/
/* package */ FontEmbeddedData(byte[] source, int start, int len) {
// Get the header.
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Get the record data.
_data = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
System.arraycopy(source,start+8,_data,0,len-8);
_data = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH);
// Must be at least 4 bytes long
if(_data.length < 4) {

View File

@ -62,7 +62,7 @@ public final class FontEntityAtom extends RecordAtom {
/**
* record header
*/
private final byte[] _header = new byte[8];
private final byte[] _header;
/**
* record data
@ -74,11 +74,10 @@ public final class FontEntityAtom extends RecordAtom {
*/
/* package */ FontEntityAtom(byte[] source, int start, int len) {
// Get the header
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Grab the record data
_recdata = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
System.arraycopy(source,start+8,_recdata,0,len-8);
_recdata = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH);
}
/**
@ -86,6 +85,7 @@ public final class FontEntityAtom extends RecordAtom {
*/
public FontEntityAtom() {
_recdata = new byte[68];
_header = new byte[8];
LittleEndian.putShort(_header, 2, (short)getRecordType());
LittleEndian.putInt(_header, 4, _recdata.length);

View File

@ -68,8 +68,7 @@ public class HSLFEscherClientDataRecord extends EscherClientDataRecord {
@Override
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
int bytesRemaining = readHeader( data, offset );
byte[] remainingData = IOUtils.safelyAllocate(bytesRemaining, MAX_RECORD_LENGTH);
System.arraycopy(data, offset+8, remainingData, 0, bytesRemaining);
byte[] remainingData = IOUtils.safelyClone(data, offset+8, bytesRemaining, MAX_RECORD_LENGTH);
setRemainingData(remainingData);
return bytesRemaining + 8;
}

View File

@ -22,6 +22,7 @@ import static org.apache.poi.util.GenericRecordUtil.safeEnum;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -142,12 +143,10 @@ public final class HeadersFootersAtom extends RecordAtom {
*/
protected HeadersFootersAtom(byte[] source, int start, int len) {
// Get the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Grab the record data
_recdata = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
System.arraycopy(source,start+8,_recdata,0,len-8);
_recdata = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH);
}
/**

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
@ -59,8 +60,7 @@ public final class HeadersFootersContainer extends RecordContainer {
protected HeadersFootersContainer(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
_children = Record.findChildRecords(source,start+8,len-8);
findInterestingChildren();

View File

@ -18,6 +18,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.POILogger;
@ -45,8 +46,7 @@ public class InteractiveInfo extends RecordContainer {
*/
protected InteractiveInfo(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);

View File

@ -22,6 +22,7 @@ import static org.apache.poi.util.GenericRecordUtil.safeEnum;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -153,12 +154,10 @@ public class InteractiveInfoAtom extends RecordAtom {
*/
protected InteractiveInfoAtom(byte[] source, int start, int len) {
// Get the header.
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Get the record data.
_data = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
System.arraycopy(source,start+8,_data,0,len-8);
_data = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH);
// Must be at least 16 bytes long
if(_data.length < 16) {

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
/**
* Master slide
@ -57,8 +58,7 @@ public final class MainMaster extends SheetContainer {
*/
protected MainMaster(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);
@ -66,19 +66,19 @@ public final class MainMaster extends SheetContainer {
ArrayList<TxMasterStyleAtom> tx = new ArrayList<>();
ArrayList<ColorSchemeAtom> clr = new ArrayList<>();
// Find the interesting ones in there
for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof SlideAtom) {
slideAtom = (SlideAtom)_children[i];
} else if(_children[i] instanceof PPDrawing) {
ppDrawing = (PPDrawing)_children[i];
} else if(_children[i] instanceof TxMasterStyleAtom) {
tx.add( (TxMasterStyleAtom)_children[i] );
} else if(_children[i] instanceof ColorSchemeAtom) {
clr.add( (ColorSchemeAtom)_children[i] );
for (Record child : _children) {
if (child instanceof SlideAtom) {
slideAtom = (SlideAtom) child;
} else if (child instanceof PPDrawing) {
ppDrawing = (PPDrawing) child;
} else if (child instanceof TxMasterStyleAtom) {
tx.add((TxMasterStyleAtom) child);
} else if (child instanceof ColorSchemeAtom) {
clr.add((ColorSchemeAtom) child);
}
if(ppDrawing != null && _children[i] instanceof ColorSchemeAtom) {
_colorScheme = (ColorSchemeAtom)_children[i];
if (ppDrawing != null && child instanceof ColorSchemeAtom) {
_colorScheme = (ColorSchemeAtom) child;
}
}

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@ -76,12 +77,10 @@ public final class MasterTextPropAtom extends RecordAtom {
*/
protected MasterTextPropAtom(byte[] source, int start, int len) {
// Get the header.
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Get the record data.
_data = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
System.arraycopy(source,start+8,_data,0,len-8);
_data = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH);
try {
read();

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
/**
* Master container for Notes. There is one of these for every page of
@ -53,22 +54,21 @@ public final class Notes extends SheetContainer
*/
protected Notes(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);
// Find the interesting ones in there
for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof NotesAtom) {
notesAtom = (NotesAtom)_children[i];
for (Record child : _children) {
if (child instanceof NotesAtom) {
notesAtom = (NotesAtom) child;
}
if(_children[i] instanceof PPDrawing) {
ppDrawing = (PPDrawing)_children[i];
if (child instanceof PPDrawing) {
ppDrawing = (PPDrawing) child;
}
if(ppDrawing != null && _children[i] instanceof ColorSchemeAtom) {
_colorScheme = (ColorSchemeAtom)_children[i];
if (ppDrawing != null && child instanceof ColorSchemeAtom) {
_colorScheme = (ColorSchemeAtom) child;
}
}
}

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -70,33 +71,19 @@ public final class NotesAtom extends RecordAtom
if(len < 8) { len = 8; }
// Get the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Get the slide ID
slideID = LittleEndian.getInt(source,start+8);
// Grok the flags, stored as bits
int flags = LittleEndian.getUShort(source,start+12);
if((flags&4) == 4) {
followMasterBackground = true;
} else {
followMasterBackground = false;
}
if((flags&2) == 2) {
followMasterScheme = true;
} else {
followMasterScheme = false;
}
if((flags&1) == 1) {
followMasterObjects = true;
} else {
followMasterObjects = false;
}
followMasterBackground = (flags & 4) == 4;
followMasterScheme = (flags & 2) == 2;
followMasterObjects = (flags & 1) == 1;
// There might be 2 more bytes, which are a reserved field
reserved = IOUtils.safelyAllocate(len-14, MAX_RECORD_LENGTH);
System.arraycopy(source,start+14,reserved,0,reserved.length);
reserved = IOUtils.safelyClone(source, start+14, len-14, MAX_RECORD_LENGTH);
}
/**

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -77,10 +78,8 @@ public final class OEPlaceholderAtom extends RecordAtom{
* Build an instance of {@code OEPlaceholderAtom} from on-disk data
*/
protected OEPlaceholderAtom(byte[] source, int start, int len) {
_header = new byte[8];
int offset = start;
System.arraycopy(source,start,_header,0,8);
offset += _header.length;
_header = Arrays.copyOfRange(source, start, start+8);
int offset = start+8;
placementId = LittleEndian.getInt(source, offset); offset += 4;
placeholderId = LittleEndian.getUByte(source, offset); offset++;

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -55,8 +56,7 @@ public final class OutlineTextRefAtom extends RecordAtom {
*/
protected OutlineTextRefAtom(byte[] source, int start, int len) {
// Get the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Grab the record data
_index = LittleEndian.getInt(source, start+8);

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -114,15 +115,13 @@ public final class PPDrawing extends RecordAtom implements Iterable<EscherRecord
*/
PPDrawing(byte[] source, int start, int len) {
// Get the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Get the type
_type = LittleEndian.getUShort(_header,2);
// Get the contents for now
final byte[] contents = IOUtils.safelyAllocate(len, MAX_RECORD_LENGTH);
System.arraycopy(source,start,contents,0,len);
final byte[] contents = IOUtils.safelyClone(source, start, len, MAX_RECORD_LENGTH);
// Build up a tree of Escher records contained within
final DefaultEscherRecordFactory erf = new HSLFEscherRecordFactory();

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.record;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -50,12 +51,10 @@ public final class PPDrawingGroup extends RecordAtom {
protected PPDrawingGroup(byte[] source, int start, int len) {
// Get the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Get the contents for now
byte[] contents = IOUtils.safelyAllocate(len, MAX_RECORD_LENGTH);
System.arraycopy(source,start,contents,0,len);
byte[] contents = IOUtils.safelyClone(source, start, len, MAX_RECORD_LENGTH);
DefaultEscherRecordFactory erf = new HSLFEscherRecordFactory();
EscherRecord child = erf.createRecord(contents, 0);

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.record;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ -103,8 +104,7 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom
if(len < 8) { len = 8; }
// Treat as an atom, grab and hold everything
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
_type = LittleEndian.getUShort(_header,2);
// Try to make sense of the data part:
@ -115,8 +115,7 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom
// count * 32 bit offsets
// Repeat as many times as you have data
_slideLocations = new HashMap<>();
_ptrData = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH);
System.arraycopy(source,start+8,_ptrData,0,_ptrData.length);
_ptrData = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH);
int pos = 0;
while(pos < _ptrData.length) {

View File

@ -21,6 +21,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -76,8 +77,7 @@ public abstract class RecordContainer extends Record
*/
private int appendChild(Record newChild) {
// Copy over, and pop the child in at the end
Record[] nc = new org.apache.poi.hslf.record.Record[(_children.length + 1)];
System.arraycopy(_children, 0, nc, 0, _children.length);
Record[] nc = Arrays.copyOf(_children, _children.length+1, org.apache.poi.hslf.record.Record[].class);
// Switch the arrays
nc[_children.length] = newChild;
_children = nc;

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -65,8 +66,7 @@ public final class RoundTripHFPlaceholder12 extends RecordAtom {
*/
protected RoundTripHFPlaceholder12(byte[] source, int start, int len) {
// Get the header.
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Get the record data.
_placeholderId = source[start+8];

View File

@ -21,6 +21,7 @@ import static org.apache.poi.util.GenericRecordUtil.getBitsAsString;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -193,7 +194,7 @@ public class SSSlideInfoAtom extends RecordAtom {
assert(source.length >= offset+len);
// Get the header
_header = LittleEndian.getByteArray(source,ofs,8);
_header = Arrays.copyOfRange(source, ofs, ofs+8);
ofs += _header.length;
assert(LittleEndian.getShort(_header, 0) == 0);
@ -214,7 +215,7 @@ public class SSSlideInfoAtom extends RecordAtom {
ofs += LittleEndianConsts.SHORT_SIZE;
_speed = LittleEndian.getUByte(source, ofs);
ofs += LittleEndianConsts.BYTE_SIZE;
_unused = LittleEndian.getByteArray(source,ofs,3);
_unused = Arrays.copyOfRange(source,ofs,ofs+3);
}
/**

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import org.apache.poi.util.LittleEndian;
@ -56,23 +57,21 @@ public final class Slide extends SheetContainer
*/
protected Slide(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);
// Find the interesting ones in there
for(int i=0; i<_children.length; i++) {
if(_children[i] instanceof SlideAtom) {
slideAtom = (SlideAtom)_children[i];
}
else if(_children[i] instanceof PPDrawing) {
ppDrawing = (PPDrawing)_children[i];
for (Record child : _children) {
if (child instanceof SlideAtom) {
slideAtom = (SlideAtom) child;
} else if (child instanceof PPDrawing) {
ppDrawing = (PPDrawing) child;
}
if(ppDrawing != null && _children[i] instanceof ColorSchemeAtom) {
_colorScheme = (ColorSchemeAtom)_children[i];
if (ppDrawing != null && child instanceof ColorSchemeAtom) {
_colorScheme = (ColorSchemeAtom) child;
}
}
}

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -83,12 +84,10 @@ public final class SlideAtom extends RecordAtom {
if(len < 30) { len = 30; }
// Get the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Grab the 12 bytes that is "SSlideLayoutAtom"
byte[] SSlideLayoutAtomData = new byte[12];
System.arraycopy(source,start+8,SSlideLayoutAtomData,0,12);
byte[] SSlideLayoutAtomData = Arrays.copyOfRange(source,start+8, start+12+8);
// Use them to build up the SSlideLayoutAtom
layoutAtom = new SlideAtomLayout(SSlideLayoutAtomData);
@ -98,26 +97,13 @@ public final class SlideAtom extends RecordAtom {
// Grok the flags, stored as bits
int flags = LittleEndian.getUShort(source,start+20+8);
if((flags&4) == 4) {
followMasterBackground = true;
} else {
followMasterBackground = false;
}
if((flags&2) == 2) {
followMasterScheme = true;
} else {
followMasterScheme = false;
}
if((flags&1) == 1) {
followMasterObjects = true;
} else {
followMasterObjects = false;
}
followMasterBackground = (flags & 4) == 4;
followMasterScheme = (flags & 2) == 2;
followMasterObjects = (flags & 1) == 1;
// 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.safelyAllocate(len-30, MAX_RECORD_LENGTH);
System.arraycopy(source,start+30,reserved,0,reserved.length);
reserved = IOUtils.safelyClone(source,start+30, len-30, MAX_RECORD_LENGTH);
}
/**

View File

@ -19,6 +19,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -117,8 +118,7 @@ public class SlideAtomLayout implements GenericRecord {
// Grab out our data
geometry = SlideLayoutType.forNativeID(LittleEndian.getInt(data,0));
placeholderIDs = new byte[8];
System.arraycopy(data,4,placeholderIDs,0,8);
placeholderIDs = Arrays.copyOfRange(data,4, 4+8);
}
/**

View File

@ -20,6 +20,7 @@ package org.apache.poi.hslf.record;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.poi.util.LittleEndian;
@ -74,8 +75,7 @@ public final class SlideListWithText extends RecordContainer {
*/
protected SlideListWithText(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);
@ -96,8 +96,7 @@ public final class SlideListWithText extends RecordContainer {
// Create a SlideAtomsSets, not caring if they're empty
//if(emptySet) { continue; }
org.apache.poi.hslf.record.Record[] spaChildren = new org.apache.poi.hslf.record.Record[clen];
System.arraycopy(_children,i+1,spaChildren,0,clen);
org.apache.poi.hslf.record.Record[] spaChildren = Arrays.copyOfRange(_children,i+1, i+1+clen, org.apache.poi.hslf.record.Record[].class);
SlideAtomsSet set = new SlideAtomsSet((SlidePersistAtom)_children[i],spaChildren);
sets.add(set);

View File

@ -21,6 +21,7 @@ import static org.apache.poi.util.GenericRecordUtil.getBitsAsString;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Supplier;
@ -44,7 +45,7 @@ public final class SlidePersistAtom extends RecordAtom {
private static final String[] FLAGS_NAMES = { "HAS_SHAPES_OTHER_THAN_PLACEHOLDERS" };
private final byte[] _header = new byte[8];
private final byte[] _header;
/** Slide reference ID. Should correspond to the PersistPtr "sheet ID" of the matching slide/notes record */
private int refID;
@ -91,7 +92,7 @@ public final class SlidePersistAtom extends RecordAtom {
if(len < 8) { len = 8; }
// Get the header
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Grab the reference ID
refID = LittleEndian.getInt(source,start+8);
@ -107,14 +108,14 @@ public final class SlidePersistAtom extends RecordAtom {
// Finally you have typically 4 or 8 bytes of reserved fields,
// all zero running from 24 bytes in to the end
reservedFields = IOUtils.safelyAllocate(len-24, MAX_RECORD_LENGTH);
System.arraycopy(source,start+24,reservedFields,0,reservedFields.length);
reservedFields = IOUtils.safelyClone(source,start+24, len-24, MAX_RECORD_LENGTH);
}
/**
* Create a new SlidePersistAtom, for use with a new Slide
*/
public SlidePersistAtom() {
_header = new byte[8];
LittleEndian.putUShort(_header, 0, 0);
LittleEndian.putUShort(_header, 2, (int)_type);
LittleEndian.putInt(_header, 4, 20);

View File

@ -17,10 +17,11 @@
package org.apache.poi.hslf.record;
import org.apache.poi.util.POILogger;
import java.io.OutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import org.apache.poi.util.POILogger;
/**
* A container holding information about a sound. It contains:
@ -55,8 +56,7 @@ public final class Sound extends RecordContainer {
*/
protected Sound(byte[] source, int start, int len) {
// Grab the header
_header = new byte[8];
System.arraycopy(source,start,_header,0,8);
_header = Arrays.copyOfRange(source, start, start+8);
// Find our children
_children = Record.findChildRecords(source,start+8,len-8);

Some files were not shown because too many files have changed in this diff Show More