diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2020-04-16 22:11:16 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2020-04-16 22:11:16 +0000 |
commit | 7daeb4278c5ace8d263db087f8014e779140423d (patch) | |
tree | 2f8a086e508c1842c2e2b641f7d89a1eab850e30 /src/scratchpad | |
parent | cdefe69aab015c8ca06e8212969f81a4150273a2 (diff) | |
download | poi-7daeb4278c5ace8d263db087f8014e779140423d.tar.gz poi-7daeb4278c5ace8d263db087f8014e779140423d.zip |
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
Diffstat (limited to 'src/scratchpad')
110 files changed, 724 insertions, 839 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java index ca78a48edd..5ebda3841d 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkSeparator.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkSeparator.java index bf49ceac48..ee009db15e 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkSeparator.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkSeparator.java @@ -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() { diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java index a4c9e178c2..92160abb8e 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkTrailer.java @@ -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() { diff --git a/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java b/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java index 0ed5540b5e..a8bea5ccd8 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/streams/CompressedStreamStore.java @@ -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. diff --git a/src/scratchpad/src/org/apache/poi/hdgf/streams/StreamStore.java b/src/scratchpad/src/org/apache/poi/hdgf/streams/StreamStore.java index 30dead90a3..ad8e13cd56 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/streams/StreamStore.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/streams/StreamStore.java @@ -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) { diff --git a/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java b/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java index b9f4cc4ee6..c3e2ab0c38 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java +++ b/src/scratchpad/src/org/apache/poi/hmef/CompressedRTF.java @@ -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; @@ -43,18 +43,18 @@ public final class CompressedRTF extends LZWDecompresser { LittleEndian.getInt(COMPRESSED_SIGNATURE); public static final int UNCOMPRESSED_SIGNATURE_INT = LittleEndian.getInt(UNCOMPRESSED_SIGNATURE); - + // The 4096 byte LZW dictionary is pre-loaded with some common // RTF fragments. These come from RTFLIB32.LIB, which ships // with older versions of Visual Studio or the EDK - public static final String LZW_RTF_PRELOAD = + public static final String LZW_RTF_PRELOAD = "{\\rtf1\\ansi\\mac\\deff0\\deftab720{\\fonttbl;}{\\f0\\fnil \\froman \\fswiss " + "\\fmodern \\fscript \\fdecor MS Sans SerifSymbolArialTimes New RomanCourier" + "{\\colortbl\\red0\\green0\\blue0\n\r\\par \\pard\\plain\\f0\\fs20\\b\\i\\u\\tab\\tx"; private int compressedSize; private int decompressedSize; - + public CompressedRTF() { // Out flag has the normal meaning // Length wise, we're 2 longer than we say, so the max len is 18 @@ -76,9 +76,9 @@ public final class CompressedRTF extends LZWDecompresser { decompressedSize = LittleEndian.readInt(src); int compressionType = LittleEndian.readInt(src); /* int dataCRC = */ LittleEndian.readInt(src); - + // TODO - Handle CRC checking on the output side - + // Do we need to do anything? if(compressionType == UNCOMPRESSED_SIGNATURE_INT) { // Nope, nothing fancy to do @@ -92,7 +92,7 @@ public final class CompressedRTF extends LZWDecompresser { // Have it processed super.decompress(src, res); } - + /** * Returns how big the compressed version was. */ @@ -100,7 +100,7 @@ public final class CompressedRTF extends LZWDecompresser { // Return the size less the header return compressedSize - 12; } - + /** * Returns how big the decompressed version was. */ @@ -119,10 +119,10 @@ 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")); + // Copy in the RTF constants + byte[] preload = LZW_RTF_PRELOAD.getBytes(StandardCharsets.US_ASCII); System.arraycopy(preload, 0, dict, 0, preload.length); - + // Start adding new codes after the constants return preload.length; } diff --git a/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIAttribute.java b/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIAttribute.java index 159328fe70..695822909a 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIAttribute.java +++ b/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIAttribute.java @@ -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; @@ -45,7 +46,7 @@ public class MAPIAttribute { private final MAPIProperty property; private final int type; private final byte[] data; - + /** * Constructs a single new attribute from * the contents of the stream @@ -67,21 +68,20 @@ public class MAPIAttribute { public byte[] getData() { return data; } - + public String toString() { String hex; 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) + ", ....]"; } - + return property + " " + hex; } - + /** * Parses a MAPI Properties TNEF Attribute, and returns * the list of MAPI Attributes contained within it @@ -101,16 +101,16 @@ public class MAPIAttribute { ); } ByteArrayInputStream inp = new ByteArrayInputStream(parent.getData()); - + // First up, get the number of attributes int count = LittleEndian.readInt(inp); List<MAPIAttribute> attrs = new ArrayList<>(); - + // Now, read each one in in turn for(int i=0; i<count; i++) { int typeAndMV = LittleEndian.readUShort(inp); int id = LittleEndian.readUShort(inp); - + // Is it either Multi-Valued or Variable-Length? boolean isMV = false; boolean isVL = false; @@ -123,13 +123,13 @@ public class MAPIAttribute { typeId == Types.BINARY.getId() || typeId == Types.DIRECTORY.getId()) { isVL = true; } - + // Turn the type ID into a strongly typed thing MAPIType type = Types.getById(typeId); if (type == null) { type = Types.createCustom(typeId); } - + // If it's a named property, rather than a standard // MAPI property, grab the details of it MAPIProperty prop = MAPIProperty.get(id); @@ -137,7 +137,7 @@ public class MAPIAttribute { byte[] guid = new byte[16]; IOUtils.readFully(inp, guid); int mptype = LittleEndian.readInt(inp); - + // Get the name of it String name; if(mptype == 0) { @@ -153,14 +153,14 @@ public class MAPIAttribute { name = StringUtil.getFromUnicodeLE(mpdata, 0, (mplen/2)-1); skipToBoundary(mplen, inp); } - + // Now create prop = MAPIProperty.createCustom(id, type, name); } if(prop == MAPIProperty.UNKNOWN) { prop = MAPIProperty.createCustom(id, type, "(unknown " + Integer.toHexString(id) + ")"); } - + // Now read in the value(s) int values = 1; if(isMV || isVL) { @@ -171,7 +171,7 @@ public class MAPIAttribute { byte[] data = IOUtils.safelyAllocate(len, MAX_RECORD_LENGTH); IOUtils.readFully(inp, data); skipToBoundary(len, inp); - + // Create MAPIAttribute attr; if(type == Types.UNICODE_STRING || type == Types.ASCII_STRING) { @@ -186,7 +186,7 @@ public class MAPIAttribute { attrs.add(attr); } } - + // All done return attrs; } diff --git a/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIRtfAttribute.java b/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIRtfAttribute.java index 744fc2b7df..c5d1cec826 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIRtfAttribute.java +++ b/src/scratchpad/src/org/apache/poi/hmef/attribute/MAPIRtfAttribute.java @@ -28,7 +28,7 @@ import org.apache.poi.util.IOUtils; import org.apache.poi.util.StringUtil; /** - * A pure-MAPI attribute holding RTF (compressed or not), which applies + * A pure-MAPI attribute holding RTF (compressed or not), which applies * to a {@link HMEFMessage} or one of its {@link Attachment}s. */ public final class MAPIRtfAttribute extends MAPIAttribute { @@ -38,45 +38,44 @@ public final class MAPIRtfAttribute extends MAPIAttribute { private final byte[] decompressed; private final String data; - + public MAPIRtfAttribute(MAPIProperty property, int type, byte[] data) throws IOException { super(property, type, data); - + // Decompress it, removing any trailing padding as needed 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; } - + // Turn the RTF data into a more useful string this.data = StringUtil.getFromCompressedUnicode(decompressed, 0, decompressed.length); } - + /** * Returns the original, compressed RTF */ public byte[] getRawData() { return super.getData(); } - + /** * Returns the raw uncompressed RTF data */ public byte[] getData() { return decompressed; } - + /** * Returns the uncompressed RTF as a string */ public String getDataString() { return data; } - + public String toString() { return getProperty() + " " + data; } diff --git a/src/scratchpad/src/org/apache/poi/hmef/dev/HMEFDumper.java b/src/scratchpad/src/org/apache/poi/hmef/dev/HMEFDumper.java index e969952648..d0019cebf4 100644 --- a/src/scratchpad/src/org/apache/poi/hmef/dev/HMEFDumper.java +++ b/src/scratchpad/src/org/apache/poi/hmef/dev/HMEFDumper.java @@ -44,7 +44,7 @@ public final class HMEFDumper { if(args.length < 1) { throw new IllegalArgumentException("Filename must be given"); } - + boolean truncatePropData = true; for (String arg : args) { if (arg.equalsIgnoreCase("--full")) { @@ -62,77 +62,77 @@ public final class HMEFDumper { private InputStream inp; private boolean truncatePropertyData; - + public HMEFDumper(InputStream inp) throws IOException { this.inp = inp; - + // Check the signature matches int sig = LittleEndian.readInt(inp); if(sig != HMEFMessage.HEADER_SIGNATURE) { throw new IllegalArgumentException( "TNEF signature not detected in file, " + - "expected " + HMEFMessage.HEADER_SIGNATURE + + "expected " + HMEFMessage.HEADER_SIGNATURE + " but got " + sig ); } - + // Skip over the File ID LittleEndian.readUShort(inp); } - + public void setTruncatePropertyData(boolean truncate) { truncatePropertyData = truncate; } - + private void dump() throws IOException { int level; int attachments = 0; - + while(true) { // Fetch the level level = inp.read(); if(level == TNEFProperty.LEVEL_END_OF_FILE) { break; } - + // Build the attribute TNEFAttribute attr = TNEFAttribute.create(inp); - + // Is it a new attachment? - if(level == TNEFProperty.LEVEL_ATTACHMENT && + if(level == TNEFProperty.LEVEL_ATTACHMENT && attr.getProperty() == TNEFProperty.ID_ATTACHRENDERDATA) { attachments++; System.out.println(); System.out.println("Attachment # " + attachments); System.out.println(); } - + // Print the attribute into System.out.println( "Level " + level + " : Type " + attr.getType() + " : ID " + attr.getProperty() ); - + // Print the contents String indent = " "; - + if(attr instanceof TNEFStringAttribute) { System.out.println(indent + indent + indent + ((TNEFStringAttribute)attr).getString()); } if(attr instanceof TNEFDateAttribute) { System.out.println(indent + indent + indent + ((TNEFDateAttribute)attr).getDate()); } - + System.out.println(indent + "Data of length " + attr.getData().length); if(attr.getData().length > 0) { int len = attr.getData().length; if(truncatePropertyData) { len = Math.min( attr.getData().length, 48 ); } - + int loops = len/16; if(loops == 0) loops = 1; - + for(int i=0; i<loops; i++) { int thisLen = 16; int offset = i*16; @@ -140,16 +140,15 @@ 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) ); } } System.out.println(); - + if(attr.getProperty() == TNEFProperty.ID_MAPIPROPERTIES || attr.getProperty() == TNEFProperty.ID_ATTACHMENT) { List<MAPIAttribute> attrs = MAPIAttribute.create(attr); diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java b/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java index 8db0e5b7d2..ab5b5d09e9 100644 --- a/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java +++ b/src/scratchpad/src/org/apache/poi/hpbf/model/QuillContents.java @@ -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")) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java b/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java index 1e944d48ed..afc8cd5481 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java +++ b/src/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java b/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java index 5699bbfeff..1c2d3dc07f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java +++ b/src/scratchpad/src/org/apache/poi/hslf/blip/DIB.java @@ -62,9 +62,9 @@ public final class DIB extends Bitmap { break; default: throw new IllegalArgumentException(signature+" is not a valid instance/signature value for DIB"); - } - } - + } + } + @Override public byte[] getData(){ return addBMPHeader ( super.getData() ); @@ -83,14 +83,14 @@ public final class DIB extends Bitmap { int imageSize = LittleEndian.getInt(data, 0x22 - HEADER_SIZE); int fileSize = data.length + HEADER_SIZE; int offset = fileSize - imageSize; - + // specifies the size, in bytes, of the bitmap file - must add the length of the header - LittleEndian.putInt(header, 2, fileSize); + LittleEndian.putInt(header, 2, fileSize); // Reserved; set to zero LittleEndian.putInt(header, 6, 0); // the offset, i.e. starting address, of the byte where the bitmap data can be found LittleEndian.putInt(header, 10, offset); - + //DIB data is the header + dib bytes byte[] dib = IOUtils.safelyAllocate(header.length + data.length, MAX_RECORD_LENGTH); System.arraycopy(header, 0, dib, 0, header.length); @@ -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); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java b/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java index e4fedb4d98..201f98e603 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java +++ b/src/scratchpad/src/org/apache/poi/hslf/blip/PICT.java @@ -36,8 +36,8 @@ import org.apache.poi.util.Units; */ public final class PICT extends Metafile { private static final POILogger LOG = POILogFactory.getLogger(PICT.class); - - + + @Override public byte[] getData(){ byte[] rawdata = getRawData(); @@ -95,7 +95,7 @@ public final class PICT extends Metafile { // skip the first 512 bytes - they are MAC specific crap final int nOffset = ImageHeaderPICT.PICT_HEADER_OFFSET; ImageHeaderPICT nHeader = new ImageHeaderPICT(data, nOffset); - + Header header = new Header(); int wmfSize = data.length - nOffset; header.setWmfSize(wmfSize); @@ -144,12 +144,12 @@ public final class PICT extends Metafile { break; default: throw new IllegalArgumentException(signature+" is not a valid instance/signature value for PICT"); - } + } } - - + + /* - * initialize a smaller piece of the array and use the System.arraycopy + * initialize a smaller piece of the array and use the System.arraycopy * call to fill in the rest of the array in an expanding binary fashion */ private static void bytefill(byte[] array, byte value) { @@ -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)); } } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java b/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java index fc0afe7ece..6b13a07920 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java +++ b/src/scratchpad/src/org/apache/poi/hslf/dev/PPTXMLDump.java @@ -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++; diff --git a/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java b/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java index 7fbed19e0e..230892e61f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java +++ b/src/scratchpad/src/org/apache/poi/hslf/dev/SlideShowDumper.java @@ -58,7 +58,7 @@ public final class SlideShowDumper { private boolean ddfEscher; /** Do we use our own built-in basic escher groker to understand the escher objects? */ private boolean basicEscher; - + private PrintStream out; /** @@ -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); @@ -229,8 +228,8 @@ public void walkTree(int depth, int startPos, int maxLen) throws IOException { String fmt = ind+"At position %2$d (%2$04x): type is %3$d (%3$04x), len is %4$d (%4$04x) (%5$d) - record claims %6$d"; out.println(String.format(Locale.ROOT, fmt, "", pos, atomType, atomLen, atomLen+8, recordLen)); - - + + // Check for corrupt / lying ones if(recordLen != 8 && (recordLen != (atomLen+8))) { out.println(String.format(Locale.ROOT, ind+"** Atom length of $2d ($3d) doesn't match record length of %4d", "", atomLen, atomLen+8, recordLen)); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java b/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java index 01f641d303..baa17a08ea 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfo.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java index 2f1306a3f8..f89e188f14 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/AnimationInfoAtom.java @@ -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); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/BinaryTagDataBlob.java b/src/scratchpad/src/org/apache/poi/hslf/record/BinaryTagDataBlob.java index 160e2bdbdf..79d8d9da7d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/BinaryTagDataBlob.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/BinaryTagDataBlob.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/CString.java b/src/scratchpad/src/org/apache/poi/hslf/record/CString.java index 5f98cc8a8c..329915f93e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/CString.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/CString.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java index 9bd51ed8ad..8625245844 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ColorSchemeAtom.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java b/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java index ed8237b38f..fbf0d3086a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000Atom.java b/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000Atom.java index de01e4f9aa..00c3cdef01 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000Atom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Comment2000Atom.java @@ -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); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java index 99b991fa11..680d97c242 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/CurrentUserAtom.java @@ -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); } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/DocInfoListContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/DocInfoListContainer.java index e10e864724..a43e475034 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/DocInfoListContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/DocInfoListContainer.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Document.java b/src/scratchpad/src/org/apache/poi/hslf/record/Document.java index 4fd37a9b35..114f5b3bb6 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Document.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Document.java @@ -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 @@ -46,24 +47,24 @@ public final class Document extends PositionDependentRecordContainer * Returns the DocumentAtom of this Document */ public DocumentAtom getDocumentAtom() { return documentAtom; } - + /** * Returns the Environment of this Notes, which lots of * settings for the document in it */ public Environment getEnvironment() { return environment; } - + /** * Returns the PPDrawingGroup, which holds an Escher Structure * that contains information on pictures in the slides. */ public PPDrawingGroup getPPDrawingGroup() { return ppDrawing; } - + /** * Returns the ExObjList, which holds the references to * external objects used in the slides. This may be null, if * there are no external references. - * + * * @param create if true, create an ExObjList if it doesn't exist */ public ExObjList getExObjList(boolean create) { @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/DocumentEncryptionAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/DocumentEncryptionAtom.java index abcf03628e..bb498f2088 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/DocumentEncryptionAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/DocumentEncryptionAtom.java @@ -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)) { @@ -67,10 +67,10 @@ public final class DocumentEncryptionAtom extends PositionDependentRecordAtom { LittleEndian.putShort(_header, 0, (short)0x000F); LittleEndian.putShort(_header, 2, (short)_type); // record length not yet known ... - + ei = new EncryptionInfo(EncryptionMode.cryptoAPI); } - + /** * Initializes the encryption settings * @@ -79,7 +79,7 @@ public final class DocumentEncryptionAtom extends PositionDependentRecordAtom { public void initializeEncryptionInfo(int keyBits) { ei = new EncryptionInfo(EncryptionMode.cryptoAPI, CipherAlgorithm.rc4, HashAlgorithm.sha1, keyBits, -1, null); } - + /** * Return the length of the encryption key, in bits */ @@ -100,8 +100,8 @@ public final class DocumentEncryptionAtom extends PositionDependentRecordAtom { public EncryptionInfo getEncryptionInfo() { return ei; } - - + + /** * We are of type 12052 */ @@ -119,10 +119,10 @@ public final class DocumentEncryptionAtom extends PositionDependentRecordAtom { bos.writeShort(ei.getVersionMajor()); bos.writeShort(ei.getVersionMinor()); bos.writeInt(ei.getEncryptionFlags()); - + ((CryptoAPIEncryptionHeader)ei.getHeader()).write(bos); ((CryptoAPIEncryptionVerifier)ei.getVerifier()).write(bos); - + // Header LittleEndian.putInt(_header, 4, bos.getWriteIndex()); out.write(_header); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java b/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java index 285f824b43..db7a0cb943 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/DummyPositionSensitiveRecordWithChildren.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java b/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java index 18dea58923..cc99aa2f98 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/DummyRecordWithChildren.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Environment.java b/src/scratchpad/src/org/apache/poi/hslf/record/Environment.java index eb66f2a288..a8bebeaeaa 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Environment.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Environment.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExControlAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExControlAtom.java index 93942674af..58d27ef340 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExControlAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExControlAtom.java @@ -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); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java index 099aeb854b..486a9bf235 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbed.java @@ -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); @@ -66,9 +66,9 @@ public class ExEmbed extends RecordContainer { this(); _children[0] = this.embedAtom = embedAtom; } - - - + + + /** * Create a new ExEmbed, with blank fields */ @@ -163,7 +163,7 @@ public class ExEmbed extends RecordContainer { /** * Gets the OLE Programmatic Identifier. - * + * * @return the OLE Programmatic Identifier. */ public String getProgId() { @@ -175,8 +175,8 @@ public class ExEmbed extends RecordContainer { this.progId.setText(progId); } - - + + /** * Gets the name that appears in the paste special dialog. * @@ -190,7 +190,7 @@ public class ExEmbed extends RecordContainer { this.clipboardName = safeCString(this.clipboardName, 0x3); this.clipboardName.setText(clipboardName); } - + /** * Returns the type (held as a little endian in bytes 3 and 4) * that this class handles. @@ -213,7 +213,7 @@ public class ExEmbed extends RecordContainer { public void writeOut(final OutputStream out) throws IOException { writeOut(_header[0],_header[1],getRecordType(),_children,out); } - + private CString safeCString(CString oldStr, int optionsId) { CString newStr = oldStr; if (newStr == null) { @@ -233,7 +233,7 @@ public class ExEmbed extends RecordContainer { if (!found) { appendChildRecord(newStr); } - + return newStr; } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbedAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbedAtom.java index e72f052347..f3c3a48f43 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbedAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExEmbedAtom.java @@ -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) { @@ -130,7 +129,7 @@ public class ExEmbedAtom extends RecordAtom { public void setCantLockServerB(boolean cantBeLocked) { _data[4] = (byte)(cantBeLocked ? 1 : 0); } - + /** * Gets whether it is not required to send the dimensions to the embedded object. * diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java index 37c47824e4..4dabe4cc82 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlink.java @@ -18,12 +18,13 @@ 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; /** - * This class represents the data of a link in the document. + * This class represents the data of a link in the document. * @author Nick Burch */ public class ExHyperlink extends RecordContainer { @@ -35,12 +36,12 @@ public class ExHyperlink extends RecordContainer { private ExHyperlinkAtom linkAtom; private CString linkDetailsA; private CString linkDetailsB; - - /** + + /** * Returns the ExHyperlinkAtom of this link - */ + */ public ExHyperlinkAtom getExHyperlinkAtom() { return linkAtom; } - + /** * Returns the URL of the link. * @@ -68,7 +69,7 @@ public class ExHyperlink extends RecordContainer { linkDetailsB.setText(url); } } - + public void setLinkOptions(int options) { if(linkDetailsB != null) { linkDetailsB.setOptions(options); @@ -80,7 +81,7 @@ public class ExHyperlink extends RecordContainer { linkDetailsA.setText(title); } } - + /** * Get the link details (field A) */ @@ -94,13 +95,12 @@ public class ExHyperlink extends RecordContainer { return linkDetailsB == null ? null : linkDetailsB.getText(); } - /** + /** * Set things up, and find our more interesting children */ 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); @@ -111,7 +111,7 @@ public class ExHyperlink extends RecordContainer { * Go through our child records, picking out the ones that are * interesting, and saving those for use by the easy helper * methods. - */ + */ private void findInterestingChildren() { // First child should be the ExHyperlinkAtom @@ -138,11 +138,11 @@ public class ExHyperlink extends RecordContainer { public ExHyperlink() { _header = new byte[8]; _children = new org.apache.poi.hslf.record.Record[3]; - + // Setup our header block _header[0] = 0x0f; // We are a container record LittleEndian.putShort(_header, 2, (short)_type); - + // Setup our child records CString csa = new CString(); CString csb = new CString(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlinkAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlinkAtom.java index bc99430998..ba63ac5da6 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlinkAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExHyperlinkAtom.java @@ -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) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExMCIMovie.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExMCIMovie.java index b83e0f8184..37b60ca9e2 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExMCIMovie.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExMCIMovie.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExMediaAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExMediaAtom.java index b8db11ad78..486b976f66 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExMediaAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExMediaAtom.java @@ -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); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java index f57461cf18..bee803a21b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java @@ -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; @@ -30,15 +31,15 @@ import org.apache.poi.util.LittleEndian; public class ExObjList extends RecordContainer { private byte[] _header; private static final long _type = RecordTypes.ExObjList.typeID; - + // Links to our more interesting children - private ExObjListAtom exObjListAtom; - - /** + private ExObjListAtom exObjListAtom; + + /** * Returns the ExObjListAtom of this list - */ + */ public ExObjListAtom getExObjListAtom() { return exObjListAtom; } - + /** * Returns all the ExHyperlinks */ @@ -53,13 +54,12 @@ public class ExObjList extends RecordContainer { return links.toArray(new ExHyperlink[0]); } - /** + /** * Set things up, and find our more interesting children */ 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); @@ -70,7 +70,7 @@ public class ExObjList extends RecordContainer { * Go through our child records, picking out the ones that are * interesting, and saving those for use by the easy helper * methods. - */ + */ private void findInterestingChildren() { // First child should be the atom if(_children[0] instanceof ExObjListAtom) { @@ -79,18 +79,18 @@ public class ExObjList extends RecordContainer { throw new IllegalStateException("First child record wasn't a ExObjListAtom, was of type " + _children[0].getRecordType()); } } - + /** * Create a new ExObjList, with blank fields */ public ExObjList() { _header = new byte[8]; _children = new org.apache.poi.hslf.record.Record[1]; - + // Setup our header block _header[0] = 0x0f; // We are a container record LittleEndian.putShort(_header, 2, (short)_type); - + // Setup our child records _children[0] = new ExObjListAtom(); findInterestingChildren(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExObjListAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExObjListAtom.java index 0c345a286b..5fab662c42 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExObjListAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExObjListAtom.java @@ -14,12 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + 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; @@ -58,7 +59,7 @@ public class ExObjListAtom extends RecordAtom LittleEndian.putShort(_header, 2, (short)getRecordType()); LittleEndian.putInt(_header, 4, _data.length); - + // It is fine for the other values to be zero } @@ -72,13 +73,11 @@ 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) { throw new IllegalArgumentException("The length of the data for a ExObjListAtom must be at least 4 bytes, but was only " + _data.length); @@ -101,7 +100,7 @@ public class ExObjListAtom extends RecordAtom public void setObjectIDSeed(int seed) { LittleEndian.putInt(_data,0,seed); } - + /** * Gets the record type. * @return the record type. diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExObjRefAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExObjRefAtom.java index 930f54c380..a1e3d168c8 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExObjRefAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExObjRefAtom.java @@ -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,17 +56,14 @@ public final class ExObjRefAtom extends RecordAtom { /** * Build an instance of <code>ExObjRefAtom</code> from on-disk data - * + * * @param source the source data as a byte array. * @param start the start offset into the byte array. * @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); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjAtom.java index b8c77a747c..321f09cb41 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjAtom.java @@ -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) { @@ -258,7 +257,7 @@ public class ExOleObjAtom extends RecordAtom { /** * Gets the type of OLE object. - * + * * @return the sub-type, one of the {@code SUBTYPE_*} constants. */ public int getSubType() { @@ -303,7 +302,7 @@ public class ExOleObjAtom extends RecordAtom { // Even though this is a mere boolean, KOffice's code says it's an int. return LittleEndian.getInt(_data, 20) != 0; } - + /** * Gets misc options (the last four bytes in the atom). * diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java index 3fdfa04ecd..4fc8a838e0 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExOleObjStg.java @@ -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; @@ -51,7 +52,7 @@ public class ExOleObjStg extends PositionDependentRecordAtom implements PersistR * Record data. */ private byte[] _data; - + /** * Constructs a new empty storage container. */ @@ -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() { @@ -155,7 +154,7 @@ public class ExOleObjStg extends PositionDependentRecordAtom implements PersistR public int getRecordInstance() { return (LittleEndian.getUShort(_header, 0) >>> 4); } - + /** * Write the contents of the record back, so it can be written * to disk. diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExVideoContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExVideoContainer.java index 1e9031cba2..bebb2aecfe 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExVideoContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExVideoContainer.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java b/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java index 4bd0b0547c..aef98a81c1 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/FontCollection.java @@ -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); @@ -86,10 +86,10 @@ public final class FontCollection extends RecordContainer { /** * Add font with the given FontInfo configuration to the font collection. - * The returned FontInfo contains the HSLF specific details and the collection + * The returned FontInfo contains the HSLF specific details and the collection * uniquely contains fonts based on their typeface, i.e. calling the method with FontInfo * objects having the same name results in the same HSLFFontInfo reference. - * + * * @param fontInfo the FontInfo configuration, can be a instance of {@link HSLFFontInfo}, * {@link HSLFFontInfoPredefined} or a custom implementation * @return the register HSLFFontInfo object @@ -168,9 +168,9 @@ public final class FontCollection extends RecordContainer { /** * Lookup a FontInfo object by its typeface - * + * * @param typeface the full font name - * + * * @return the HSLFFontInfo for the given name or {@code null} if not found */ public HSLFFontInfo getFontInfo(String typeface) { @@ -195,9 +195,9 @@ public final class FontCollection extends RecordContainer { /** * Lookup a FontInfo object by its internal font index - * + * * @param index the internal font index - * + * * @return the HSLFFontInfo for the given index or {@code null} if not found */ public HSLFFontInfo getFontInfo(int index) { @@ -208,7 +208,7 @@ public final class FontCollection extends RecordContainer { } return null; } - + /** * @return the number of registered fonts */ diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/FontEmbeddedData.java b/src/scratchpad/src/org/apache/poi/hslf/record/FontEmbeddedData.java index f28bb3f990..b9acb2e3bf 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/FontEmbeddedData.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/FontEmbeddedData.java @@ -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) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java index 0e9f732833..0d576f6a6a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/FontEntityAtom.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java b/src/scratchpad/src/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java index 3f1b0fbe3d..af0e0a5ec5 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/HSLFEscherClientDataRecord.java @@ -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; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersAtom.java index f175848ff1..42f8d017ca 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersAtom.java @@ -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); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersContainer.java index b974bb35bb..492933be48 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/HeadersFootersContainer.java @@ -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(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfo.java b/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfo.java index 440005b479..76b84c554a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfo.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfo.java @@ -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; @@ -31,22 +32,21 @@ import org.apache.poi.util.POILogger; public class InteractiveInfo extends RecordContainer { private byte[] _header; private static final long _type = RecordTypes.InteractiveInfo.typeID; - + // Links to our more interesting children private InteractiveInfoAtom infoAtom; - - /** + + /** * Returns the InteractiveInfoAtom of this InteractiveInfo - */ + */ public InteractiveInfoAtom getInteractiveInfoAtom() { return infoAtom; } - - /** + + /** * Set things up, and find our more interesting children */ 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); @@ -57,7 +57,7 @@ public class InteractiveInfo extends RecordContainer { * Go through our child records, picking out the ones that are * interesting, and saving those for use by the easy helper * methods. - */ + */ private void findInterestingChildren() { // First child should be the InteractiveInfoAtom if (_children == null || _children.length == 0 || !(_children[0] instanceof InteractiveInfoAtom)) { @@ -67,18 +67,18 @@ public class InteractiveInfo extends RecordContainer { infoAtom = (InteractiveInfoAtom)_children[0]; } - + /** * Create a new InteractiveInfo, with blank fields */ public InteractiveInfo() { _header = new byte[8]; _children = new org.apache.poi.hslf.record.Record[1]; - + // Setup our header block _header[0] = 0x0f; // We are a container record LittleEndian.putShort(_header, 2, (short)_type); - + // Setup our child records infoAtom = new InteractiveInfoAtom(); _children[0] = infoAtom; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfoAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfoAtom.java index 71a5adc123..3543010612 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfoAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/InteractiveInfoAtom.java @@ -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) { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java b/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java index 8451193c33..e771fcf57d 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java @@ -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; } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/MasterTextPropAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/MasterTextPropAtom.java index 0e1b4dcab1..8da3d439b6 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/MasterTextPropAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/MasterTextPropAtom.java @@ -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(); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java b/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java index 8695b25f0b..4854426283 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Notes.java @@ -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,23 +54,22 @@ 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 && child instanceof ColorSchemeAtom) { + _colorScheme = (ColorSchemeAtom) child; } - if(ppDrawing != null && _children[i] instanceof ColorSchemeAtom) { - _colorScheme = (ColorSchemeAtom)_children[i]; - } } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/NotesAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/NotesAtom.java index 40b4554955..655898adb8 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/NotesAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/NotesAtom.java @@ -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); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/OEPlaceholderAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/OEPlaceholderAtom.java index f25164d2a2..af3595fecb 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/OEPlaceholderAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/OEPlaceholderAtom.java @@ -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; @@ -28,7 +29,7 @@ import org.apache.poi.util.LittleEndian; /** * OEPlaceholderAtom (3011).<p> - * + * * An atom record that specifies whether a shape is a placeholder shape. * * @see Placeholder @@ -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++; @@ -96,7 +95,7 @@ public final class OEPlaceholderAtom extends RecordAtom{ /** * Returns the placement Id.<p> - * + * * The placement Id is a number assigned to the placeholder. It goes from -1 to the number of placeholders. * It SHOULD be unique among all PlacholderAtom records contained in the corresponding slide. * The value 0xFFFFFFFF specifies that the corresponding shape is not a placeholder shape. diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/OutlineTextRefAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/OutlineTextRefAtom.java index e0c368825b..e521c74383 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/OutlineTextRefAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/OutlineTextRefAtom.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java b/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java index 2bb40a812a..77af5d467f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawing.java @@ -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(); @@ -342,7 +341,7 @@ public final class PPDrawing extends RecordAtom implements Iterable<EscherRecord spContainer.addChildRecord(opt); dgContainer.addChildRecord(spContainer); - + childRecords.add(dgContainer); } @@ -364,7 +363,7 @@ public final class PPDrawing extends RecordAtom implements Iterable<EscherRecord public EscherContainerRecord getDgContainer() { return (EscherContainerRecord)firstEscherRecord(this, EscherRecordTypes.DG_CONTAINER).orElse(null); } - + /** * Return EscherDgRecord which keeps track of the number of shapes and shapeId in this drawing group * diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawingGroup.java b/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawingGroup.java index 672be6c0cf..6ff8b4577f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawingGroup.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PPDrawingGroup.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java b/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java index 841d49d9e1..0084d9020b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/PersistPtrHolder.java @@ -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; @@ -65,7 +66,7 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom private static final BitField persistIdFld = BitFieldFactory.getInstance(0X000FFFFF); private static final BitField cntPersistFld = BitFieldFactory.getInstance(0XFFF00000); - + /** * Return the value we were given at creation, be it 6001 or 6002 */ @@ -93,7 +94,7 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom public Map<Integer,Integer> getSlideLocationsLookup() { return Collections.unmodifiableMap(_slideLocations); } - + /** * Create a new holder for a PersistPtr record */ @@ -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) { @@ -127,7 +126,7 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom // Remaining 12 bits = offset count int offset_no = persistIdFld.getValue(info); int offset_count = cntPersistFld.getValue(info); - + // Wind on by the 4 byte info header pos += 4; @@ -145,13 +144,13 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom /** * remove all slide references - * + * * Convenience method provided, for easier reviewing of invocations */ public void clear() { _slideLocations.clear(); } - + /** * Adds a new slide, notes or similar, to be looked up by this. */ @@ -187,7 +186,7 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom private void normalizePersistDirectory() { TreeMap<Integer,Integer> orderedSlideLocations = new TreeMap<>(_slideLocations); - + @SuppressWarnings("resource") BufAccessBAOS bos = new BufAccessBAOS(); // NOSONAR byte[] intbuf = new byte[4]; @@ -200,7 +199,7 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom // Building the info block // First 20 bits = offset number = slide ID (persistIdFld, i.e. first slide ID of a continuous group) // Remaining 12 bits = offset count = 1 (cntPersistFld, i.e. continuous entries in a group) - + if (lastSlideId+1 == nextSlideId) { // use existing PersistDirectoryEntry, need to increase entry count assert(lastPersistEntry != -1); @@ -225,14 +224,14 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom throw new HSLFException(e); } } - + // Save the new ptr data _ptrData = bos.toByteArray(); // Update the atom header LittleEndian.putInt(_header,4,bos.size()); } - + /** * Write the contents of the record back, so it can be written * to disk @@ -243,7 +242,7 @@ public final class PersistPtrHolder extends PositionDependentRecordAtom out.write(_header); out.write(_ptrData); } - + private static class BufAccessBAOS extends ByteArrayOutputStream { public byte[] getBuf() { return buf; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java index dafc3972fe..4e738a7601 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java @@ -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; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/RoundTripHFPlaceholder12.java b/src/scratchpad/src/org/apache/poi/hslf/record/RoundTripHFPlaceholder12.java index f2c8f03b82..283c65ba43 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/RoundTripHFPlaceholder12.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/RoundTripHFPlaceholder12.java @@ -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,7 +56,7 @@ public final class RoundTripHFPlaceholder12 extends RecordAtom { LittleEndian.putInt(_header, 4, 8); _placeholderId = 0; } - + /** * Constructs the comment atom record from its source data. * @@ -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]; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SSSlideInfoAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/SSSlideInfoAtom.java index e0d28e5dfa..7bd098f92b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SSSlideInfoAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SSSlideInfoAtom.java @@ -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; @@ -31,7 +32,7 @@ import org.apache.poi.util.LittleEndianConsts; /** * A SlideShowSlideInfo Atom (type 1017).<br> * <br> - * + * * An atom record that specifies which transition effects to perform * during a slide show, and how to advance to the next presentation slide.<br> * <br> @@ -70,30 +71,30 @@ public class SSSlideInfoAtom extends RecordAtom { * manually advanced by the user during the slide show. */ public static final int MANUAL_ADVANCE_BIT = 1 << 0; - + /** - * A bit that specifies whether the corresponding slide is + * A bit that specifies whether the corresponding slide is * hidden and is not displayed during the slide show. */ public static final int HIDDEN_BIT = 1 << 2; - + /** * A bit that specifies whether to play the sound specified by soundIfRef. */ public static final int SOUND_BIT = 1 << 4; - + /** * A bit that specifies whether the sound specified by soundIdRef is * looped continuously when playing until the next sound plays. */ public static final int LOOP_SOUND_BIT = 1 << 6; - + /** - * A bit that specifies whether to stop any currently playing + * A bit that specifies whether to stop any currently playing * sound when the transition starts. */ public static final int STOP_SOUND_BIT = 1 << 8; - + /** * A bit that specifies whether the slide will automatically * advance after slideTime milliseconds during the slide show. @@ -102,10 +103,10 @@ public class SSSlideInfoAtom extends RecordAtom { /** * A bit that specifies whether to display the cursor during - * the slide show. + * the slide show. */ public static final int CURSOR_VISIBLE_BIT = 1 << 12; - + // public static int RESERVED1_BIT = 1 << 1; // public static int RESERVED2_BIT = 1 << 3; // public static int RESERVED3_BIT = 1 << 5; @@ -144,9 +145,9 @@ public class SSSlideInfoAtom extends RecordAtom { * less than or equal to 86399000. It MUST be ignored unless AUTO_ADVANCE_BIT is TRUE. */ private int _slideTime; - + /** - * A SoundIdRef that specifies which sound to play when the transition starts. + * A SoundIdRef that specifies which sound to play when the transition starts. */ private int _soundIdRef; @@ -155,23 +156,23 @@ public class SSSlideInfoAtom extends RecordAtom { * there are further restriction and specification of this field. */ private short _effectDirection; // byte - + /** * A byte that specifies which transition is used when transitioning to the - * next presentation slide during a slide show. Exact rendering of any transition is + * next presentation slide during a slide show. Exact rendering of any transition is * determined by the rendering application. As such, the same transition can have * many variations depending on the implementation. */ private short _effectType; // byte - + /** * Various flags - see bitmask for more details */ private short _effectTransitionFlags; - + /** * A byte value that specifies how long the transition takes to run. - * (0x00 = 0.75 seconds, 0x01 = 0.5 seconds, 0x02 = 0.25 seconds) + * (0x00 = 0.75 seconds, 0x01 = 0.5 seconds, 0x02 = 0.25 seconds) */ private short _speed; // byte private byte[] _unused; // 3-byte @@ -184,18 +185,18 @@ public class SSSlideInfoAtom extends RecordAtom { LittleEndian.putShort(_header, 6, (short)0); _unused = new byte[3]; } - + public SSSlideInfoAtom(byte[] source, int offset, int len) { int ofs = offset; // Sanity Checking if(len != 24) len = 24; 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); assert(LittleEndian.getShort(_header, 2) == RecordTypes.SSSlideInfoAtom.typeID); assert(LittleEndian.getShort(_header, 4) == 0x10); @@ -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); } /** @@ -232,7 +233,7 @@ public class SSSlideInfoAtom extends RecordAtom { out.write(byteBuf); LittleEndian.putUByte(byteBuf, 0, _effectType); out.write(byteBuf); - + writeLittleEndian(_effectTransitionFlags, out); LittleEndian.putUByte(byteBuf, 0, _speed); out.write(byteBuf); @@ -240,7 +241,7 @@ public class SSSlideInfoAtom extends RecordAtom { assert(_unused.length == 3); out.write(_unused); } - + /** * We are of type 1017 */ @@ -303,7 +304,7 @@ public class SSSlideInfoAtom extends RecordAtom { public boolean getEffectTransitionFlagByBit(int bitmask) { return ((_effectTransitionFlags & bitmask) != 0); } - + public short getSpeed() { return _speed; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java b/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java index 4534de034a..cf8d2466c0 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Slide.java @@ -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,24 +57,22 @@ 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; + } } } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java index e5b85a7e00..5728bacf4c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtom.java @@ -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); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtomLayout.java b/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtomLayout.java index 9b27fe2282..e91bc7ddb4 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtomLayout.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SlideAtomLayout.java @@ -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; @@ -32,7 +33,7 @@ import org.apache.poi.util.LittleEndian; * Holds the geometry of the Slide, and the ID of the placeholders on the slide. * Embedded inside a SlideAtom is a SlideAtomLayout, without the usual record header. * Since it's a fixed size and tied to the SlideAtom, we'll hold it here.<p> - * + * * This might eventually merged with the XSLF counterpart */ @Internal @@ -82,7 +83,7 @@ public class SlideAtomLayout implements GenericRecord { SlideLayoutType(int nativeId) { this.nativeId = nativeId; } - + public int getNativeId() { return nativeId; } @@ -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); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java b/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java index 516bbda7b0..d0298a5be2 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java index 34a5560253..d52552ab7b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SlidePersistAtom.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Sound.java b/src/scratchpad/src/org/apache/poi/hslf/record/Sound.java index f454e4d208..27a2c1b8cf 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Sound.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Sound.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SoundCollection.java b/src/scratchpad/src/org/apache/poi/hslf/record/SoundCollection.java index abea3887f0..3fda587c6e 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SoundCollection.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SoundCollection.java @@ -17,8 +17,9 @@ package org.apache.poi.hslf.record; -import java.io.OutputStream; import java.io.IOException; +import java.io.OutputStream; +import java.util.Arrays; /** * Is a container for all sound related atoms and containers. It contains: @@ -42,8 +43,7 @@ public final class SoundCollection extends RecordContainer { */ protected SoundCollection(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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SoundData.java b/src/scratchpad/src/org/apache/poi/hslf/record/SoundData.java index 09f9d5c1a7..0989052c56 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SoundData.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SoundData.java @@ -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; @@ -68,12 +69,10 @@ public final class SoundData extends RecordAtom { */ protected SoundData(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); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextProp9Atom.java b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextProp9Atom.java index cedea7f646..20317e3074 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextProp9Atom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextProp9Atom.java @@ -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.LinkedList; import java.util.List; import java.util.Map; @@ -45,7 +46,7 @@ public final class StyleTextProp9Atom extends RecordAtom { private short version; private short recordId; private int length; - + /** * Constructs the link related atom record from its * source data. @@ -57,35 +58,33 @@ public final class StyleTextProp9Atom extends RecordAtom { protected StyleTextProp9Atom(byte[] source, int start, int len) { // Get the header. final List<TextPFException9> schemes = new LinkedList<>(); - header = new byte[8]; - System.arraycopy(source,start, header,0,8); + header = Arrays.copyOfRange(source, start, start+8); this.version = LittleEndian.getShort(header, 0); this.recordId = LittleEndian.getShort(header, 2); this.length = LittleEndian.getInt(header, 4); - + // 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); for (int i = 0; i < data.length; ) { final TextPFException9 item = new TextPFException9(data, i); schemes.add(item); i += item.getRecordLength(); - + if (i+4 >= data.length) { break; } int textCfException9 = LittleEndian.getInt(data, i ); i += 4; //TODO analyze textCfException when have some test data - + if (i+4 >= data.length) { break; } int textSiException = LittleEndian.getInt(data, i ); i += 4;//TextCFException9 + SIException - - if (0 != (textSiException & 0x40)) { - i += 2; //skip fBidi + + if (0 != (textSiException & 0x40)) { + i += 2; //skip fBidi } if (i+4 >= data.length) { break; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java index 0d2a23ba60..2e0084e323 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextPropAtom.java @@ -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.List; import java.util.Map; import java.util.function.Supplier; @@ -130,13 +131,11 @@ public final class StyleTextPropAtom extends RecordAtom { } // Get the header - _header = new byte[8]; - System.arraycopy(source,start,_header,0,8); + _header = Arrays.copyOfRange(source, start, start+8); // Save the contents of the atom, until we're asked to go and // decode them (via a call to setParentTextSize(int) - rawContents = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH); - System.arraycopy(source,start+8,rawContents,0,rawContents.length); + rawContents = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH); reserved = new byte[0]; // Set empty lists, ready for when they call setParentTextSize @@ -289,8 +288,7 @@ public final class StyleTextPropAtom extends RecordAtom { // Handle anything left over if(pos < rawContents.length) { - reserved = IOUtils.safelyAllocate(rawContents.length-pos, rawContents.length); - System.arraycopy(rawContents,pos,reserved,0,reserved.length); + reserved = IOUtils.safelyClone(rawContents, pos, rawContents.length-pos, rawContents.length); } initialised = true; diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java index cd84b7b8da..81a503b95c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextBytesAtom.java @@ -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; @@ -69,12 +70,10 @@ public final class TextBytesAtom 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); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java index 078f1d9ef7..768aaba6ef 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextCharsAtom.java @@ -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; @@ -68,12 +69,10 @@ public final class TextCharsAtom 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 TextCharsAtom diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java index 3a2d01adfb..99ac049994 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextHeaderAtom.java @@ -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; @@ -84,8 +85,7 @@ public final class TextHeaderAtom extends RecordAtom implements ParentAwareRecor } // Get the header - _header = new byte[8]; - System.arraycopy(source,start,_header,0,8); + _header = Arrays.copyOfRange(source, start, start+8); // Grab the type textType = LittleEndian.getInt(source,start+8); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java index d572290657..b26e9cb04b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java @@ -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.List; import java.util.Map; import java.util.function.Supplier; @@ -43,7 +44,7 @@ public final class TextSpecInfoAtom extends RecordAtom { private static final int MAX_RECORD_LENGTH = 100_000; private static final long _type = RecordTypes.TextSpecInfoAtom.typeID; - + /** * Record header. */ @@ -55,14 +56,14 @@ public final class TextSpecInfoAtom extends RecordAtom { private byte[] _data; /** - * Constructs an empty atom, with a default run of size 1 + * Constructs an empty atom, with a default run of size 1 */ public TextSpecInfoAtom() { _header = new byte[8]; LittleEndian.putUInt(_header, 4, _type); reset(1); } - + /** * Constructs the link related atom record from its * source data. @@ -73,13 +74,10 @@ public final class TextSpecInfoAtom extends RecordAtom { */ public TextSpecInfoAtom(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); } /** * Gets the record type. @@ -157,7 +155,7 @@ public final class TextSpecInfoAtom extends RecordAtom { // Update the size (header bytes 5-8) LittleEndian.putInt(_header, 4, _data.length); } - + /** * Get the number of characters covered by this records * diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TxInteractiveInfoAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TxInteractiveInfoAtom.java index 469de32a56..f5896aa817 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TxInteractiveInfoAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TxInteractiveInfoAtom.java @@ -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; @@ -67,13 +68,10 @@ public final class TxInteractiveInfoAtom extends RecordAtom { */ protected TxInteractiveInfoAtom(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); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java index 2597ccbe67..40a85fab1c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TxMasterStyleAtom.java @@ -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.List; import java.util.Map; import java.util.function.Supplier; @@ -70,11 +71,9 @@ public final class TxMasterStyleAtom extends RecordAtom { private List<TextPropCollection> charStyles; protected TxMasterStyleAtom(byte[] source, int start, int len) { - _header = new byte[8]; - System.arraycopy(source,start,_header,0,8); + _header = Arrays.copyOfRange(source, start, start+8); - _data = IOUtils.safelyAllocate(len-8, MAX_RECORD_LENGTH); - System.arraycopy(source,start+8,_data,0,_data.length); + _data = IOUtils.safelyClone(source, start+8, len-8, MAX_RECORD_LENGTH); //read available styles try { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/UnknownRecordPlaceholder.java b/src/scratchpad/src/org/apache/poi/hslf/record/UnknownRecordPlaceholder.java index e483ce7424..886a0dd20f 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/UnknownRecordPlaceholder.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/UnknownRecordPlaceholder.java @@ -53,8 +53,7 @@ public final class UnknownRecordPlaceholder extends RecordAtom if(len < 0) { len = 0; } // Treat as an atom, grab and hold everything - _contents = IOUtils.safelyAllocate(len, MAX_RECORD_LENGTH); - System.arraycopy(source,start,_contents,0,len); + _contents = IOUtils.safelyClone(source, start, len, MAX_RECORD_LENGTH); _type = LittleEndian.getUShort(_contents,2); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java index 287da27798..b89da4a98c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/UserEditAtom.java @@ -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.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -89,8 +90,7 @@ public final class UserEditAtom extends PositionDependentRecordAtom int offset = start; // Get the header - _header = new byte[8]; - System.arraycopy(source,offset,_header,0,8); + _header = Arrays.copyOfRange(source, start, start+8); offset += 8; // Get the last viewed slide ID @@ -125,7 +125,7 @@ public final class UserEditAtom extends PositionDependentRecordAtom // Last view type lastViewType = LittleEndian.getShort(source,offset); offset += LittleEndianConsts.SHORT_SIZE; - + // unused unused = LittleEndian.getShort(source,offset); offset += LittleEndianConsts.SHORT_SIZE; @@ -135,7 +135,7 @@ public final class UserEditAtom extends PositionDependentRecordAtom encryptSessionPersistIdRef = LittleEndian.getInt(source,offset); offset += LittleEndianConsts.INT_SIZE; } - + assert(offset-start == len); } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/VBAInfoAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/VBAInfoAtom.java index eb4d337383..4607bb6141 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/VBAInfoAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/VBAInfoAtom.java @@ -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; @@ -30,7 +31,7 @@ import org.apache.poi.util.LittleEndian; */ public final class VBAInfoAtom extends RecordAtom { private static final long _type = RecordTypes.VBAInfoAtom.typeID; - + /** * Record header. */ @@ -44,7 +45,7 @@ public final class VBAInfoAtom extends RecordAtom { private long version; /** - * Constructs an empty atom - not yet supported + * Constructs an empty atom - not yet supported */ private VBAInfoAtom() { _header = new byte[8]; @@ -54,7 +55,7 @@ public final class VBAInfoAtom extends RecordAtom { hasMacros = true; version = 2; } - + /** * Constructs the vba atom record from its source data. * @@ -64,8 +65,7 @@ public final class VBAInfoAtom extends RecordAtom { */ public VBAInfoAtom(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. persistIdRef = LittleEndian.getUInt(source, start+8); diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/VBAInfoContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/VBAInfoContainer.java index cf9f6159cc..043cea2286 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/VBAInfoContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/VBAInfoContainer.java @@ -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; @@ -36,8 +37,7 @@ public final class VBAInfoContainer extends RecordContainer { */ protected VBAInfoContainer(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); diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureData.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureData.java index e7f92a4a9f..f5b2eaa1ce 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureData.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFPictureData.java @@ -21,6 +21,7 @@ import java.awt.Dimension; import java.io.IOException; import java.io.OutputStream; import java.security.MessageDigest; +import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; @@ -129,9 +130,7 @@ public abstract class HSLFPictureData implements PictureData, GenericRecord { * Returns 16-byte checksum of this picture */ public byte[] getUID(){ - byte[] uid = new byte[16]; - System.arraycopy(rawdata, 0, uid, 0, uid.length); - return uid; + return Arrays.copyOf(rawdata, 16); } @Override diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java index 9ad2c7ccde..6f1c633ea3 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowImpl.java @@ -301,7 +301,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { // check for corrupted user edit atom and try to repair it // if the next user edit atom offset is already known, we would go into an endless loop if (usrOffset > 0 && recordMap.containsKey(usrOffset)) { - // a user edit atom is usually located 36 byte before the smallest known record offset + // a user edit atom is usually located 36 byte before the smallest known record offset usrOffset = recordMap.firstKey() - 36; // check that we really are located on a user edit atom int ver_inst = LittleEndian.getUShort(docstream, usrOffset); @@ -415,8 +415,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { pict.setSignature(signature); // Copy the data, ready to pass to PictureData - byte[] imgdata = IOUtils.safelyAllocate(imgsize, MAX_RECORD_LENGTH); - System.arraycopy(pictstream, pos, imgdata, 0, imgdata.length); + byte[] imgdata = IOUtils.safelyClone(pictstream, pos, imgsize, MAX_RECORD_LENGTH); pict.setRawData(imgdata); pict.setOffset(offset); @@ -563,7 +562,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { validateInPlaceWritePossible(); // Write the PowerPoint streams to the current FileSystem - // No need to do anything to other streams, already there! + // No need to do anything to other streams, already there! write(getDirectory().getFileSystem(), false); // Sync with the File on disk @@ -649,7 +648,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { } private void write(POIFSFileSystem outFS, boolean copyAllOtherNodes) throws IOException { - // read properties and pictures, with old encryption settings where appropriate + // read properties and pictures, with old encryption settings where appropriate if (_pictures == null) { readPictures(); } @@ -673,8 +672,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { updateAndWriteDependantRecords(baos, null); // Update our cached copy of the bytes that make up the PPT stream - _docstream = new byte[baos.size()]; - System.arraycopy(baos.getBuf(), 0, _docstream, 0, baos.size()); + _docstream = baos.toByteArray(); baos.close(); // Write the PPT stream into the POIFS layer @@ -701,7 +699,7 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { } } - + // If requested, copy over any other streams we spot, eg Macros if (copyAllOtherNodes) { EntryUtils.copyNodes(getDirectory().getFileSystem(), outFS, writtenEntries); @@ -715,9 +713,9 @@ public final class HSLFSlideShowImpl extends POIDocument implements Closeable { return (dea != null) ? dea.getEncryptionInfo() : null; } - - - + + + /* ******************* adding methods follow ********************* */ /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java index ba9d1495bc..6e1b7611d1 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFTextParagraph.java @@ -22,6 +22,7 @@ import static org.apache.poi.hslf.record.RecordTypes.OutlineTextRefAtom; import java.awt.Color; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.function.Consumer; @@ -333,8 +334,7 @@ public final class HSLFTextParagraph implements TextParagraph<HSLFShape,HSLFText } } - org.apache.poi.hslf.record.Record[] result = new org.apache.poi.hslf.record.Record[length]; - System.arraycopy(records, startIdx[0], result, 0, length); + org.apache.poi.hslf.record.Record[] result = Arrays.copyOfRange(records, startIdx[0], startIdx[0]+length, org.apache.poi.hslf.record.Record[].class); startIdx[0] += length; return result; diff --git a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlUtils.java b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlUtils.java index 651d1f0dda..63e71d9b98 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlUtils.java +++ b/src/scratchpad/src/org/apache/poi/hssf/converter/ExcelToHtmlUtils.java @@ -39,7 +39,7 @@ public class ExcelToHtmlUtils extends AbstractExcelUtils { * Creates a map (i.e. two-dimensional array) filled with ranges. Allow fast * retrieving {@link CellRangeAddress} of any cell, if cell is contained in * range. - * + * * @see #getMergedRange(CellRangeAddress[][], int, int) */ public static CellRangeAddress[][] buildMergedRangesMap( Sheet sheet ) { @@ -47,10 +47,7 @@ public class ExcelToHtmlUtils extends AbstractExcelUtils { for ( final CellRangeAddress cellRangeAddress : sheet.getMergedRegions() ) { final int requiredHeight = cellRangeAddress.getLastRow() + 1; if ( mergedRanges.length < requiredHeight ) { - CellRangeAddress[][] newArray = new CellRangeAddress[requiredHeight][]; - System.arraycopy( mergedRanges, 0, newArray, 0, - mergedRanges.length ); - mergedRanges = newArray; + mergedRanges = Arrays.copyOf(mergedRanges, requiredHeight, CellRangeAddress[][].class); } for ( int r = cellRangeAddress.getFirstRow(); r <= cellRangeAddress @@ -63,14 +60,9 @@ public class ExcelToHtmlUtils extends AbstractExcelUtils { mergedRanges[r] = rowMerged; } else { final int rowMergedLength = rowMerged.length; - if ( rowMergedLength < requiredWidth ) - { - final CellRangeAddress[] newRow = new CellRangeAddress[requiredWidth]; - System.arraycopy( rowMerged, 0, newRow, 0, - rowMergedLength ); - - mergedRanges[r] = newRow; - rowMerged = newRow; + if ( rowMergedLength < requiredWidth ) { + rowMerged = mergedRanges[r] = + Arrays.copyOf(rowMerged, requiredWidth, CellRangeAddress[].class); } } diff --git a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfText.java b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfText.java index bbeb4ac98b..5229b34c18 100644 --- a/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfText.java +++ b/src/scratchpad/src/org/apache/poi/hwmf/record/HwmfText.java @@ -225,9 +225,7 @@ public class HwmfText { * This does not include the extra optional padding on the byte array. */ private byte[] getTextBytes() { - byte[] ret = IOUtils.safelyAllocate(stringLength, MAX_RECORD_LENGTH); - System.arraycopy(rawTextBytes, 0, ret, 0, stringLength); - return ret; + return IOUtils.safelyClone(rawTextBytes, 0, stringLength, MAX_RECORD_LENGTH); } @Override diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java index 230174637e..6cf4027cad 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFOldDocument.java @@ -60,12 +60,12 @@ public class HWPFOldDocument extends HWPFDocumentCore { private final static Charset DEFAULT_CHARSET = StringUtil.WIN_1252; private OldTextPieceTable tpt; - + private StringBuilder _text; private final OldFontTable fontTable; private final Charset guessedCharset; - + public HWPFOldDocument(POIFSFileSystem fs) throws IOException { this(fs.getRoot()); } @@ -73,7 +73,7 @@ public class HWPFOldDocument extends HWPFDocumentCore { public HWPFOldDocument(DirectoryNode directory) throws IOException { super(directory); - + // Where are things? int sedTableOffset = LittleEndian.getInt(_mainStream, 0x88); int sedTableSize = LittleEndian.getInt(_mainStream, 0x8c); @@ -91,7 +91,7 @@ public class HWPFOldDocument extends HWPFDocumentCore { guessedCharset = guessCodePage(fontTable); int complexTableOffset = LittleEndian.getInt(_mainStream, 0x160); - + // We need to get hold of the text that makes up the // document, which might be regular or fast-saved ComplexFileTable cft = null; @@ -101,7 +101,7 @@ public class HWPFOldDocument extends HWPFDocumentCore { complexTableOffset, _fib.getFibBase().getFcMin(), guessedCharset ); tpt = (OldTextPieceTable)cft.getTextPieceTable(); - + } else { // TODO Discover if these older documents can ever hold Unicode Strings? // (We think not, because they seem to lack a Piece table) @@ -118,7 +118,7 @@ public class HWPFOldDocument extends HWPFDocumentCore { logger.log(POILogger.WARN, "Error with "+guessedCharset +". Backing off to Windows-1252"); } tpt.add(tp); - + } _text = tpt.getText(); @@ -171,19 +171,16 @@ public class HWPFOldDocument extends HWPFDocumentCore { // Generate a single Text Piece Table, with a single Text Piece // which covers all the (8 bit only) text in the file tpt = new OldTextPieceTable(); - byte[] textData = IOUtils.safelyAllocate( - _fib.getFibBase().getFcMac()-_fib.getFibBase().getFcMin(), MAX_RECORD_LENGTH); - System.arraycopy(_mainStream, _fib.getFibBase().getFcMin(), textData, 0, textData.length); + + byte[] textData = IOUtils.safelyClone(_mainStream, _fib.getFibBase().getFcMin(), + _fib.getFibBase().getFcMac()-_fib.getFibBase().getFcMin(), MAX_RECORD_LENGTH); int numChars = textData.length; if (CodePageUtil.DOUBLE_BYTE_CHARSETS.contains(guessedCharset)) { numChars /= 2; } - return new TextPiece( - 0, numChars, textData, pd - ); - + return new TextPiece(0, numChars, textData, pd); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java index 5191342c14..349f39b634 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/CHPFormattedDiskPage.java @@ -62,7 +62,7 @@ public final class CHPFormattedDiskPage extends FormattedDiskPage /** * This constructs a CHPFormattedDiskPage from a raw fkp (512 byte array * read from a Word file). - * + * * @deprecated Use * {@link #CHPFormattedDiskPage(byte[], int, CharIndexTranslator)} * instead @@ -134,17 +134,13 @@ public final class CHPFormattedDiskPage extends FormattedDiskPage int chpxOffset = 2 * LittleEndian.getUByte(_fkp, _offset + (((_crun + 1) * 4) + index)); //optimization if offset == 0 use "Normal" style - if(chpxOffset == 0) - { + if(chpxOffset == 0) { return new byte[0]; } int size = LittleEndian.getUByte(_fkp, _offset + chpxOffset); - byte[] chpx = IOUtils.safelyAllocate(size, MAX_RECORD_LENGTH); - - System.arraycopy(_fkp, _offset + ++chpxOffset, chpx, 0, size); - return chpx; + return IOUtils.safelyClone(_fkp, _offset + chpxOffset + 1, size, MAX_RECORD_LENGTH); } protected byte[] toByteArray( CharIndexTranslator translator ) @@ -184,7 +180,7 @@ public final class CHPFormattedDiskPage extends FormattedDiskPage if (index == 0) { throw new RecordFormatException("empty grpprl entry."); } - + // see if we couldn't fit some if ( index != size ) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java index 9d6b631e4c..7dc6081cc5 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java @@ -25,6 +25,7 @@ import java.util.List; import org.apache.poi.hwpf.model.io.HWPFFileSystem; import org.apache.poi.hwpf.sprm.SprmBuffer; +import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndianConsts; @@ -56,7 +57,7 @@ public class ComplexFileTable { offset++; int size = LittleEndian.getShort(tableStream, offset); offset += LittleEndianConsts.SHORT_SIZE; - byte[] bs = LittleEndian.getByteArray(tableStream, offset, size, MAX_RECORD_LENGTH); + byte[] bs = IOUtils.safelyClone(tableStream, offset, size, MAX_RECORD_LENGTH); offset += size; SprmBuffer sprmBuffer = new SprmBuffer(bs, false, 0); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/DocumentProperties.java b/src/scratchpad/src/org/apache/poi/hwpf/model/DocumentProperties.java index c9aa4326ad..f292643fb1 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/DocumentProperties.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/DocumentProperties.java @@ -23,11 +23,10 @@ import java.io.IOException; import org.apache.poi.hwpf.model.types.DOPAbstractType; import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; -import org.apache.poi.util.LittleEndian; /** * Comment me - * + * * @author Ryan Ackley */ @Internal @@ -54,8 +53,7 @@ public final class DocumentProperties extends DOPAbstractType final int supportedSize = DOPAbstractType.getSize(); if ( length != supportedSize ) { - this._preserved = LittleEndian.getByteArray( tableStream, offset - + supportedSize, length - supportedSize, MAX_RECORD_LENGTH ); + this._preserved = IOUtils.safelyClone( tableStream, offset + supportedSize, length - supportedSize, MAX_RECORD_LENGTH ); } else { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java index 15dca2fb16..6e055f186d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FileInformationBlock.java @@ -111,7 +111,6 @@ public final class FileInformationBlock _cbRgFcLcb = LittleEndian.getUShort( mainDocument, offset ); offset += LittleEndianConsts.SHORT_SIZE; - assert offset == 154; // skip fibRgFcLcbBlob (read later at fillVariableFields) offset += _cbRgFcLcb * LittleEndianConsts.INT_SIZE * 2; @@ -125,11 +124,8 @@ public final class FileInformationBlock offset += LittleEndianConsts.SHORT_SIZE; // first short is already read as _nFibNew - final int fibRgCswNewLength = ( _cswNew - 1 ) - * LittleEndianConsts.SHORT_SIZE; - _fibRgCswNew = IOUtils.safelyAllocate(fibRgCswNewLength, MAX_RECORD_LENGTH); - LittleEndian.getByteArray( mainDocument, offset, fibRgCswNewLength, MAX_RECORD_LENGTH ); - offset += fibRgCswNewLength; + final int fibRgCswNewLength = ( _cswNew - 1 ) * LittleEndianConsts.SHORT_SIZE; + _fibRgCswNew = IOUtils.safelyClone(mainDocument, offset, fibRgCswNewLength, MAX_RECORD_LENGTH); } else { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/OldSectionTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/OldSectionTable.java index f93604fffd..684d3bd8b5 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/OldSectionTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/OldSectionTable.java @@ -72,9 +72,8 @@ public final class OldSectionTable extends SectionTable // section properties, and we're trying to decode them as if they // were the new ones, we sometimes "need" more data than we have. // As a workaround, have a few extra 0 bytes on the end! - byte[] buf = IOUtils.safelyAllocate(sepxSize+2, Short.MAX_VALUE+2); fileOffset += LittleEndianConsts.SHORT_SIZE; - System.arraycopy(documentStream, fileOffset, buf, 0, buf.length); + byte[] buf = IOUtils.safelyClone(documentStream, fileOffset, sepxSize+2, Short.MAX_VALUE+2); sepx = new SEPX(sed, startAt, endAt, buf); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/OldTextPiece.java b/src/scratchpad/src/org/apache/poi/hwpf/model/OldTextPiece.java index 1386b0af65..b14c38223d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/OldTextPiece.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/OldTextPiece.java @@ -68,9 +68,7 @@ public class OldTextPiece extends TextPiece { @Override public byte[] getRawBytes() { - byte[] buf = new byte[rawBytes.length]; - System.arraycopy(rawBytes, 0, buf, 0, rawBytes.length); - return buf; + return rawBytes.clone(); } /** diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/OldTextPieceTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/OldTextPieceTable.java index 701c793996..e3cb94c868 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/OldTextPieceTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/OldTextPieceTable.java @@ -82,12 +82,10 @@ public class OldTextPieceTable extends TextPieceTable { int textSizeBytes = textSizeChars * multiple; // Grab the data that makes up the piece - byte[] buf = IOUtils.safelyAllocate(textSizeBytes, MAX_RECORD_LENGTH); - System.arraycopy(documentStream, start, buf, 0, textSizeBytes); + byte[] buf = IOUtils.safelyClone(documentStream, start, textSizeBytes, MAX_RECORD_LENGTH); // And now build the piece - final TextPiece newTextPiece = newTextPiece(nodeStartChars, nodeEndChars, buf, - pieces[x]); + final TextPiece newTextPiece = newTextPiece(nodeStartChars, nodeEndChars, buf, pieces[x]); _textPieces.add(newTextPiece); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PICFAndOfficeArtData.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PICFAndOfficeArtData.java index f75de37920..85205b7bb1 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PICFAndOfficeArtData.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PICFAndOfficeArtData.java @@ -23,6 +23,7 @@ import org.apache.poi.ddf.DefaultEscherRecordFactory; import org.apache.poi.ddf.EscherContainerRecord; import org.apache.poi.ddf.EscherRecord; import org.apache.poi.hwpf.model.types.PICFAbstractType; +import org.apache.poi.util.IOUtils; import org.apache.poi.util.Internal; import org.apache.poi.util.LittleEndian; @@ -55,8 +56,7 @@ public class PICFAndOfficeArtData _cchPicName = LittleEndian.getUByte( dataStream, offset ); offset += 1; - _stPicName = LittleEndian.getByteArray( dataStream, offset, - _cchPicName, MAX_RECORD_LENGTH); + _stPicName = IOUtils.safelyClone(dataStream, offset, _cchPicName, MAX_RECORD_LENGTH); offset += _cchPicName; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfCps.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfCps.java index 579ec187c7..658cb60c9e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfCps.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfCps.java @@ -128,9 +128,7 @@ public final class PlexOfCps { int start = LittleEndian.getInt(buf, offset + getIntOffset(index)); int end = LittleEndian.getInt(buf, offset + getIntOffset(index + 1)); - byte[] struct = IOUtils.safelyAllocate(_cbStruct, MAX_RECORD_LENGTH); - System.arraycopy(buf, offset + getStructOffset(index), struct, 0, - _cbStruct); + byte[] struct = IOUtils.safelyClone(buf, offset + getStructOffset(index), _cbStruct, MAX_RECORD_LENGTH); return new GenericPropertyNode(start, end, struct); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java index 5e7186b920..eb2292a6e0 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/SectionTable.java @@ -81,9 +81,8 @@ public class SectionTable { // The first short at the offset is the size of the grpprl. int sepxSize = LittleEndian.getShort(documentStream, fileOffset); - byte[] buf = IOUtils.safelyAllocate(sepxSize, MAX_RECORD_LENGTH); fileOffset += LittleEndianConsts.SHORT_SIZE; - System.arraycopy(documentStream, fileOffset, buf, 0, buf.length); + byte[] buf = IOUtils.safelyClone(documentStream, fileOffset, sepxSize, MAX_RECORD_LENGTH); _sections.add(new SEPX(sed, startAt, endAt, buf)); } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java b/src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java index 92378e8fed..f81c97880e 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java @@ -116,8 +116,7 @@ public class Sttb _data[i] = StringUtil.getFromUnicodeLE( buffer, offset, cchData ); offset += cchData * 2; - _extraData[i] = LittleEndian - .getByteArray( buffer, offset, _cbExtra ); + _extraData[i] = Arrays.copyOfRange( buffer, offset, offset+_cbExtra ); offset += _cbExtra; } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java index 60de580d80..d96d66da33 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/StyleDescription.java @@ -110,8 +110,7 @@ public final class StyleDescription { int upxSize = LittleEndian.getShort(std, varOffset); varOffset += LittleEndianConsts.SHORT_SIZE; - byte[] upx = IOUtils.safelyAllocate(upxSize, Short.MAX_VALUE); - System.arraycopy(std, varOffset, upx, 0, upxSize); + byte[] upx = IOUtils.safelyClone(std, varOffset, upxSize, Short.MAX_VALUE); _upxs[x] = new UPX(upx); varOffset += upxSize; diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java index fe79951db2..8649f06a3f 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java @@ -101,8 +101,7 @@ public class TextPieceTable implements CharIndexTranslator { int textSizeBytes = textSizeChars * multiple; // Grab the data that makes up the piece - byte[] buf = IOUtils.safelyAllocate(textSizeBytes, MAX_RECORD_LENGTH); - System.arraycopy(documentStream, start, buf, 0, textSizeBytes); + byte[] buf = IOUtils.safelyClone(documentStream, start, textSizeBytes, MAX_RECORD_LENGTH); // And now build the piece final TextPiece newTextPiece = newTextPiece(nodeStartChars, nodeEndChars, buf, diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java index 773f731d47..6ba7a30183 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/DOPAbstractType.java @@ -224,16 +224,16 @@ public abstract class DOPAbstractType { field_32_view = LittleEndian.getShort(data, 0x52 + offset); field_33_docinfo4 = LittleEndian.getInt(data, 0x54 + offset); field_34_adt = LittleEndian.getShort(data, 0x58 + offset); - field_35_doptypography = LittleEndian.getByteArray(data, 0x5a + offset,310); - field_36_dogrid = LittleEndian.getByteArray(data, 0x190 + offset,10); + field_35_doptypography = Arrays.copyOfRange(data, 0x5a + offset, 0x5a + offset+ 310); + field_36_dogrid = Arrays.copyOfRange(data, 0x190 + offset,0x190 + offset + 10); field_37_docinfo5 = LittleEndian.getShort(data, 0x19a + offset); field_38_docinfo6 = LittleEndian.getShort(data, 0x19c + offset); - field_39_asumyi = LittleEndian.getByteArray(data, 0x19e + offset,12); + field_39_asumyi = Arrays.copyOfRange(data, 0x19e + offset, 0x19e + offset + 12); field_40_cChWS = LittleEndian.getInt(data, 0x1aa + offset); field_41_cChWSFtnEdn = LittleEndian.getInt(data, 0x1ae + offset); field_42_grfDocEvents = LittleEndian.getInt(data, 0x1b2 + offset); field_43_virusinfo = LittleEndian.getInt(data, 0x1b6 + offset); - field_44_Spare = LittleEndian.getByteArray(data, 0x1ba + offset,30); + field_44_Spare = Arrays.copyOfRange(data, 0x1ba + offset, 0x1ba + offset + 30); field_45_reserved1 = LittleEndian.getInt(data, 0x1d8 + offset); field_46_reserved2 = LittleEndian.getInt(data, 0x1dc + offset); field_47_cDBC = LittleEndian.getInt(data, 0x1e0 + offset); @@ -1473,7 +1473,7 @@ public abstract class DOPAbstractType { /** * Sets the fFacingPages field value. - * + * */ @Internal public void setFFacingPages( boolean value ) @@ -1482,7 +1482,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fFacingPages field value. */ @Internal @@ -1493,7 +1493,7 @@ public abstract class DOPAbstractType { /** * Sets the fWidowControl field value. - * + * */ @Internal public void setFWidowControl( boolean value ) @@ -1502,7 +1502,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fWidowControl field value. */ @Internal @@ -1513,7 +1513,7 @@ public abstract class DOPAbstractType { /** * Sets the fPMHMainDoc field value. - * + * */ @Internal public void setFPMHMainDoc( boolean value ) @@ -1522,7 +1522,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fPMHMainDoc field value. */ @Internal @@ -1533,7 +1533,7 @@ public abstract class DOPAbstractType { /** * Sets the grfSupression field value. - * + * */ @Internal public void setGrfSupression( byte value ) @@ -1542,7 +1542,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the grfSupression field value. */ @Internal @@ -1553,7 +1553,7 @@ public abstract class DOPAbstractType { /** * Sets the fpc field value. - * + * */ @Internal public void setFpc( byte value ) @@ -1562,7 +1562,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fpc field value. */ @Internal @@ -1573,7 +1573,7 @@ public abstract class DOPAbstractType { /** * Sets the unused1 field value. - * + * */ @Internal public void setUnused1( boolean value ) @@ -1582,7 +1582,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the unused1 field value. */ @Internal @@ -1593,7 +1593,7 @@ public abstract class DOPAbstractType { /** * Sets the rncFtn field value. - * + * */ @Internal public void setRncFtn( byte value ) @@ -1602,7 +1602,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the rncFtn field value. */ @Internal @@ -1613,7 +1613,7 @@ public abstract class DOPAbstractType { /** * Sets the nFtn field value. - * + * */ @Internal public void setNFtn( short value ) @@ -1622,7 +1622,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the nFtn field value. */ @Internal @@ -1633,7 +1633,7 @@ public abstract class DOPAbstractType { /** * Sets the fOnlyMacPics field value. - * + * */ @Internal public void setFOnlyMacPics( boolean value ) @@ -1642,7 +1642,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fOnlyMacPics field value. */ @Internal @@ -1653,7 +1653,7 @@ public abstract class DOPAbstractType { /** * Sets the fOnlyWinPics field value. - * + * */ @Internal public void setFOnlyWinPics( boolean value ) @@ -1662,7 +1662,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fOnlyWinPics field value. */ @Internal @@ -1673,7 +1673,7 @@ public abstract class DOPAbstractType { /** * Sets the fLabelDoc field value. - * + * */ @Internal public void setFLabelDoc( boolean value ) @@ -1682,7 +1682,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fLabelDoc field value. */ @Internal @@ -1693,7 +1693,7 @@ public abstract class DOPAbstractType { /** * Sets the fHyphCapitals field value. - * + * */ @Internal public void setFHyphCapitals( boolean value ) @@ -1702,7 +1702,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fHyphCapitals field value. */ @Internal @@ -1713,7 +1713,7 @@ public abstract class DOPAbstractType { /** * Sets the fAutoHyphen field value. - * + * */ @Internal public void setFAutoHyphen( boolean value ) @@ -1722,7 +1722,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fAutoHyphen field value. */ @Internal @@ -1733,7 +1733,7 @@ public abstract class DOPAbstractType { /** * Sets the fFormNoFields field value. - * + * */ @Internal public void setFFormNoFields( boolean value ) @@ -1742,7 +1742,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fFormNoFields field value. */ @Internal @@ -1753,7 +1753,7 @@ public abstract class DOPAbstractType { /** * Sets the fLinkStyles field value. - * + * */ @Internal public void setFLinkStyles( boolean value ) @@ -1762,7 +1762,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fLinkStyles field value. */ @Internal @@ -1773,7 +1773,7 @@ public abstract class DOPAbstractType { /** * Sets the fRevMarking field value. - * + * */ @Internal public void setFRevMarking( boolean value ) @@ -1782,7 +1782,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fRevMarking field value. */ @Internal @@ -1793,7 +1793,7 @@ public abstract class DOPAbstractType { /** * Sets the fBackup field value. - * + * */ @Internal public void setFBackup( boolean value ) @@ -1802,7 +1802,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fBackup field value. */ @Internal @@ -1813,7 +1813,7 @@ public abstract class DOPAbstractType { /** * Sets the fExactCWords field value. - * + * */ @Internal public void setFExactCWords( boolean value ) @@ -1822,7 +1822,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fExactCWords field value. */ @Internal @@ -1833,7 +1833,7 @@ public abstract class DOPAbstractType { /** * Sets the fPagHidden field value. - * + * */ @Internal public void setFPagHidden( boolean value ) @@ -1842,7 +1842,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fPagHidden field value. */ @Internal @@ -1853,7 +1853,7 @@ public abstract class DOPAbstractType { /** * Sets the fPagResults field value. - * + * */ @Internal public void setFPagResults( boolean value ) @@ -1862,7 +1862,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fPagResults field value. */ @Internal @@ -1873,7 +1873,7 @@ public abstract class DOPAbstractType { /** * Sets the fLockAtn field value. - * + * */ @Internal public void setFLockAtn( boolean value ) @@ -1882,7 +1882,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fLockAtn field value. */ @Internal @@ -1893,7 +1893,7 @@ public abstract class DOPAbstractType { /** * Sets the fMirrorMargins field value. - * + * */ @Internal public void setFMirrorMargins( boolean value ) @@ -1902,7 +1902,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fMirrorMargins field value. */ @Internal @@ -1913,7 +1913,7 @@ public abstract class DOPAbstractType { /** * Sets the unused3 field value. - * + * */ @Internal public void setUnused3( boolean value ) @@ -1922,7 +1922,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the unused3 field value. */ @Internal @@ -1933,7 +1933,7 @@ public abstract class DOPAbstractType { /** * Sets the fDfltTrueType field value. - * + * */ @Internal public void setFDfltTrueType( boolean value ) @@ -1942,7 +1942,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fDfltTrueType field value. */ @Internal @@ -1953,7 +1953,7 @@ public abstract class DOPAbstractType { /** * Sets the fPagSupressTopSpacing field value. - * + * */ @Internal public void setFPagSupressTopSpacing( boolean value ) @@ -1962,7 +1962,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fPagSupressTopSpacing field value. */ @Internal @@ -1973,7 +1973,7 @@ public abstract class DOPAbstractType { /** * Sets the fProtEnabled field value. - * + * */ @Internal public void setFProtEnabled( boolean value ) @@ -1982,7 +1982,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fProtEnabled field value. */ @Internal @@ -1993,7 +1993,7 @@ public abstract class DOPAbstractType { /** * Sets the fDispFormFldSel field value. - * + * */ @Internal public void setFDispFormFldSel( boolean value ) @@ -2002,7 +2002,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fDispFormFldSel field value. */ @Internal @@ -2013,7 +2013,7 @@ public abstract class DOPAbstractType { /** * Sets the fRMView field value. - * + * */ @Internal public void setFRMView( boolean value ) @@ -2022,7 +2022,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fRMView field value. */ @Internal @@ -2033,7 +2033,7 @@ public abstract class DOPAbstractType { /** * Sets the fRMPrint field value. - * + * */ @Internal public void setFRMPrint( boolean value ) @@ -2042,7 +2042,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fRMPrint field value. */ @Internal @@ -2053,7 +2053,7 @@ public abstract class DOPAbstractType { /** * Sets the unused4 field value. - * + * */ @Internal public void setUnused4( boolean value ) @@ -2062,7 +2062,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the unused4 field value. */ @Internal @@ -2073,7 +2073,7 @@ public abstract class DOPAbstractType { /** * Sets the fLockRev field value. - * + * */ @Internal public void setFLockRev( boolean value ) @@ -2082,7 +2082,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fLockRev field value. */ @Internal @@ -2093,7 +2093,7 @@ public abstract class DOPAbstractType { /** * Sets the fEmbedFonts field value. - * + * */ @Internal public void setFEmbedFonts( boolean value ) @@ -2102,7 +2102,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fEmbedFonts field value. */ @Internal @@ -2113,7 +2113,7 @@ public abstract class DOPAbstractType { /** * Sets the oldfNoTabForInd field value. - * + * */ @Internal public void setOldfNoTabForInd( boolean value ) @@ -2122,7 +2122,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the oldfNoTabForInd field value. */ @Internal @@ -2133,7 +2133,7 @@ public abstract class DOPAbstractType { /** * Sets the oldfNoSpaceRaiseLower field value. - * + * */ @Internal public void setOldfNoSpaceRaiseLower( boolean value ) @@ -2142,7 +2142,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the oldfNoSpaceRaiseLower field value. */ @Internal @@ -2153,7 +2153,7 @@ public abstract class DOPAbstractType { /** * Sets the oldfSuppressSpbfAfterPageBreak field value. - * + * */ @Internal public void setOldfSuppressSpbfAfterPageBreak( boolean value ) @@ -2162,7 +2162,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the oldfSuppressSpbfAfterPageBreak field value. */ @Internal @@ -2173,7 +2173,7 @@ public abstract class DOPAbstractType { /** * Sets the oldfWrapTrailSpaces field value. - * + * */ @Internal public void setOldfWrapTrailSpaces( boolean value ) @@ -2182,7 +2182,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the oldfWrapTrailSpaces field value. */ @Internal @@ -2193,7 +2193,7 @@ public abstract class DOPAbstractType { /** * Sets the oldfMapPrintTextColor field value. - * + * */ @Internal public void setOldfMapPrintTextColor( boolean value ) @@ -2202,7 +2202,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the oldfMapPrintTextColor field value. */ @Internal @@ -2213,7 +2213,7 @@ public abstract class DOPAbstractType { /** * Sets the oldfNoColumnBalance field value. - * + * */ @Internal public void setOldfNoColumnBalance( boolean value ) @@ -2222,7 +2222,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the oldfNoColumnBalance field value. */ @Internal @@ -2233,7 +2233,7 @@ public abstract class DOPAbstractType { /** * Sets the oldfConvMailMergeEsc field value. - * + * */ @Internal public void setOldfConvMailMergeEsc( boolean value ) @@ -2242,7 +2242,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the oldfConvMailMergeEsc field value. */ @Internal @@ -2253,7 +2253,7 @@ public abstract class DOPAbstractType { /** * Sets the oldfSupressTopSpacing field value. - * + * */ @Internal public void setOldfSupressTopSpacing( boolean value ) @@ -2262,7 +2262,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the oldfSupressTopSpacing field value. */ @Internal @@ -2273,7 +2273,7 @@ public abstract class DOPAbstractType { /** * Sets the oldfOrigWordTableRules field value. - * + * */ @Internal public void setOldfOrigWordTableRules( boolean value ) @@ -2282,7 +2282,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the oldfOrigWordTableRules field value. */ @Internal @@ -2293,7 +2293,7 @@ public abstract class DOPAbstractType { /** * Sets the oldfTransparentMetafiles field value. - * + * */ @Internal public void setOldfTransparentMetafiles( boolean value ) @@ -2302,7 +2302,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the oldfTransparentMetafiles field value. */ @Internal @@ -2313,7 +2313,7 @@ public abstract class DOPAbstractType { /** * Sets the oldfShowBreaksInFrames field value. - * + * */ @Internal public void setOldfShowBreaksInFrames( boolean value ) @@ -2322,7 +2322,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the oldfShowBreaksInFrames field value. */ @Internal @@ -2333,7 +2333,7 @@ public abstract class DOPAbstractType { /** * Sets the oldfSwapBordersFacingPgs field value. - * + * */ @Internal public void setOldfSwapBordersFacingPgs( boolean value ) @@ -2342,7 +2342,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the oldfSwapBordersFacingPgs field value. */ @Internal @@ -2353,7 +2353,7 @@ public abstract class DOPAbstractType { /** * Sets the unused5 field value. - * + * */ @Internal public void setUnused5( byte value ) @@ -2362,7 +2362,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the unused5 field value. */ @Internal @@ -2373,7 +2373,7 @@ public abstract class DOPAbstractType { /** * Sets the rncEdn field value. - * + * */ @Internal public void setRncEdn( byte value ) @@ -2382,7 +2382,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the rncEdn field value. */ @Internal @@ -2393,7 +2393,7 @@ public abstract class DOPAbstractType { /** * Sets the nEdn field value. - * + * */ @Internal public void setNEdn( short value ) @@ -2402,7 +2402,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the nEdn field value. */ @Internal @@ -2413,7 +2413,7 @@ public abstract class DOPAbstractType { /** * Sets the epc field value. - * + * */ @Internal public void setEpc( byte value ) @@ -2422,7 +2422,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the epc field value. */ @Internal @@ -2433,7 +2433,7 @@ public abstract class DOPAbstractType { /** * Sets the nfcFtnRef1 field value. - * + * */ @Internal public void setNfcFtnRef1( byte value ) @@ -2442,7 +2442,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the nfcFtnRef1 field value. */ @Internal @@ -2453,7 +2453,7 @@ public abstract class DOPAbstractType { /** * Sets the nfcEdnRef1 field value. - * + * */ @Internal public void setNfcEdnRef1( byte value ) @@ -2462,7 +2462,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the nfcEdnRef1 field value. */ @Internal @@ -2473,7 +2473,7 @@ public abstract class DOPAbstractType { /** * Sets the fPrintFormData field value. - * + * */ @Internal public void setFPrintFormData( boolean value ) @@ -2482,7 +2482,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fPrintFormData field value. */ @Internal @@ -2493,7 +2493,7 @@ public abstract class DOPAbstractType { /** * Sets the fSaveFormData field value. - * + * */ @Internal public void setFSaveFormData( boolean value ) @@ -2502,7 +2502,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fSaveFormData field value. */ @Internal @@ -2513,7 +2513,7 @@ public abstract class DOPAbstractType { /** * Sets the fShadeFormData field value. - * + * */ @Internal public void setFShadeFormData( boolean value ) @@ -2522,7 +2522,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fShadeFormData field value. */ @Internal @@ -2533,7 +2533,7 @@ public abstract class DOPAbstractType { /** * Sets the fWCFtnEdn field value. - * + * */ @Internal public void setFWCFtnEdn( boolean value ) @@ -2542,7 +2542,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fWCFtnEdn field value. */ @Internal @@ -2553,7 +2553,7 @@ public abstract class DOPAbstractType { /** * Sets the wvkSaved field value. - * + * */ @Internal public void setWvkSaved( byte value ) @@ -2562,7 +2562,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the wvkSaved field value. */ @Internal @@ -2573,7 +2573,7 @@ public abstract class DOPAbstractType { /** * Sets the wScaleSaved field value. - * + * */ @Internal public void setWScaleSaved( short value ) @@ -2582,7 +2582,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the wScaleSaved field value. */ @Internal @@ -2593,7 +2593,7 @@ public abstract class DOPAbstractType { /** * Sets the zkSaved field value. - * + * */ @Internal public void setZkSaved( byte value ) @@ -2602,7 +2602,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the zkSaved field value. */ @Internal @@ -2613,7 +2613,7 @@ public abstract class DOPAbstractType { /** * Sets the fRotateFontW6 field value. - * + * */ @Internal public void setFRotateFontW6( boolean value ) @@ -2622,7 +2622,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fRotateFontW6 field value. */ @Internal @@ -2633,7 +2633,7 @@ public abstract class DOPAbstractType { /** * Sets the iGutterPos field value. - * + * */ @Internal public void setIGutterPos( boolean value ) @@ -2642,7 +2642,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the iGutterPos field value. */ @Internal @@ -2653,7 +2653,7 @@ public abstract class DOPAbstractType { /** * Sets the fNoTabForInd field value. - * + * */ @Internal public void setFNoTabForInd( boolean value ) @@ -2662,7 +2662,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fNoTabForInd field value. */ @Internal @@ -2673,7 +2673,7 @@ public abstract class DOPAbstractType { /** * Sets the fNoSpaceRaiseLower field value. - * + * */ @Internal public void setFNoSpaceRaiseLower( boolean value ) @@ -2682,7 +2682,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fNoSpaceRaiseLower field value. */ @Internal @@ -2693,7 +2693,7 @@ public abstract class DOPAbstractType { /** * Sets the fSupressSpdfAfterPageBreak field value. - * + * */ @Internal public void setFSupressSpdfAfterPageBreak( boolean value ) @@ -2702,7 +2702,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fSupressSpdfAfterPageBreak field value. */ @Internal @@ -2713,7 +2713,7 @@ public abstract class DOPAbstractType { /** * Sets the fWrapTrailSpaces field value. - * + * */ @Internal public void setFWrapTrailSpaces( boolean value ) @@ -2722,7 +2722,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fWrapTrailSpaces field value. */ @Internal @@ -2733,7 +2733,7 @@ public abstract class DOPAbstractType { /** * Sets the fMapPrintTextColor field value. - * + * */ @Internal public void setFMapPrintTextColor( boolean value ) @@ -2742,7 +2742,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fMapPrintTextColor field value. */ @Internal @@ -2753,7 +2753,7 @@ public abstract class DOPAbstractType { /** * Sets the fNoColumnBalance field value. - * + * */ @Internal public void setFNoColumnBalance( boolean value ) @@ -2762,7 +2762,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fNoColumnBalance field value. */ @Internal @@ -2773,7 +2773,7 @@ public abstract class DOPAbstractType { /** * Sets the fConvMailMergeEsc field value. - * + * */ @Internal public void setFConvMailMergeEsc( boolean value ) @@ -2782,7 +2782,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fConvMailMergeEsc field value. */ @Internal @@ -2793,7 +2793,7 @@ public abstract class DOPAbstractType { /** * Sets the fSupressTopSpacing field value. - * + * */ @Internal public void setFSupressTopSpacing( boolean value ) @@ -2802,7 +2802,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fSupressTopSpacing field value. */ @Internal @@ -2813,7 +2813,7 @@ public abstract class DOPAbstractType { /** * Sets the fOrigWordTableRules field value. - * + * */ @Internal public void setFOrigWordTableRules( boolean value ) @@ -2822,7 +2822,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fOrigWordTableRules field value. */ @Internal @@ -2833,7 +2833,7 @@ public abstract class DOPAbstractType { /** * Sets the fTransparentMetafiles field value. - * + * */ @Internal public void setFTransparentMetafiles( boolean value ) @@ -2842,7 +2842,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fTransparentMetafiles field value. */ @Internal @@ -2853,7 +2853,7 @@ public abstract class DOPAbstractType { /** * Sets the fShowBreaksInFrames field value. - * + * */ @Internal public void setFShowBreaksInFrames( boolean value ) @@ -2862,7 +2862,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fShowBreaksInFrames field value. */ @Internal @@ -2873,7 +2873,7 @@ public abstract class DOPAbstractType { /** * Sets the fSwapBordersFacingPgs field value. - * + * */ @Internal public void setFSwapBordersFacingPgs( boolean value ) @@ -2882,7 +2882,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fSwapBordersFacingPgs field value. */ @Internal @@ -2893,7 +2893,7 @@ public abstract class DOPAbstractType { /** * Sets the fSuppressTopSPacingMac5 field value. - * + * */ @Internal public void setFSuppressTopSPacingMac5( boolean value ) @@ -2902,7 +2902,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fSuppressTopSPacingMac5 field value. */ @Internal @@ -2913,7 +2913,7 @@ public abstract class DOPAbstractType { /** * Sets the fTruncDxaExpand field value. - * + * */ @Internal public void setFTruncDxaExpand( boolean value ) @@ -2922,7 +2922,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fTruncDxaExpand field value. */ @Internal @@ -2933,7 +2933,7 @@ public abstract class DOPAbstractType { /** * Sets the fPrintBodyBeforeHdr field value. - * + * */ @Internal public void setFPrintBodyBeforeHdr( boolean value ) @@ -2942,7 +2942,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fPrintBodyBeforeHdr field value. */ @Internal @@ -2953,7 +2953,7 @@ public abstract class DOPAbstractType { /** * Sets the fNoLeading field value. - * + * */ @Internal public void setFNoLeading( boolean value ) @@ -2962,7 +2962,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fNoLeading field value. */ @Internal @@ -2973,7 +2973,7 @@ public abstract class DOPAbstractType { /** * Sets the fMWSmallCaps field value. - * + * */ @Internal public void setFMWSmallCaps( boolean value ) @@ -2982,7 +2982,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fMWSmallCaps field value. */ @Internal @@ -2993,7 +2993,7 @@ public abstract class DOPAbstractType { /** * Sets the lvl field value. - * + * */ @Internal public void setLvl( byte value ) @@ -3002,7 +3002,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the lvl field value. */ @Internal @@ -3013,7 +3013,7 @@ public abstract class DOPAbstractType { /** * Sets the fGramAllDone field value. - * + * */ @Internal public void setFGramAllDone( boolean value ) @@ -3022,7 +3022,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fGramAllDone field value. */ @Internal @@ -3033,7 +3033,7 @@ public abstract class DOPAbstractType { /** * Sets the fGramAllClean field value. - * + * */ @Internal public void setFGramAllClean( boolean value ) @@ -3042,7 +3042,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fGramAllClean field value. */ @Internal @@ -3053,7 +3053,7 @@ public abstract class DOPAbstractType { /** * Sets the fSubsetFonts field value. - * + * */ @Internal public void setFSubsetFonts( boolean value ) @@ -3062,7 +3062,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fSubsetFonts field value. */ @Internal @@ -3073,7 +3073,7 @@ public abstract class DOPAbstractType { /** * Sets the fHideLastVersion field value. - * + * */ @Internal public void setFHideLastVersion( boolean value ) @@ -3082,7 +3082,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fHideLastVersion field value. */ @Internal @@ -3093,7 +3093,7 @@ public abstract class DOPAbstractType { /** * Sets the fHtmlDoc field value. - * + * */ @Internal public void setFHtmlDoc( boolean value ) @@ -3102,7 +3102,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fHtmlDoc field value. */ @Internal @@ -3113,7 +3113,7 @@ public abstract class DOPAbstractType { /** * Sets the fSnapBorder field value. - * + * */ @Internal public void setFSnapBorder( boolean value ) @@ -3122,7 +3122,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fSnapBorder field value. */ @Internal @@ -3133,7 +3133,7 @@ public abstract class DOPAbstractType { /** * Sets the fIncludeHeader field value. - * + * */ @Internal public void setFIncludeHeader( boolean value ) @@ -3142,7 +3142,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fIncludeHeader field value. */ @Internal @@ -3153,7 +3153,7 @@ public abstract class DOPAbstractType { /** * Sets the fIncludeFooter field value. - * + * */ @Internal public void setFIncludeFooter( boolean value ) @@ -3162,7 +3162,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fIncludeFooter field value. */ @Internal @@ -3173,7 +3173,7 @@ public abstract class DOPAbstractType { /** * Sets the fForcePageSizePag field value. - * + * */ @Internal public void setFForcePageSizePag( boolean value ) @@ -3182,7 +3182,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fForcePageSizePag field value. */ @Internal @@ -3193,7 +3193,7 @@ public abstract class DOPAbstractType { /** * Sets the fMinFontSizePag field value. - * + * */ @Internal public void setFMinFontSizePag( boolean value ) @@ -3202,7 +3202,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fMinFontSizePag field value. */ @Internal @@ -3213,7 +3213,7 @@ public abstract class DOPAbstractType { /** * Sets the fHaveVersions field value. - * + * */ @Internal public void setFHaveVersions( boolean value ) @@ -3222,7 +3222,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fHaveVersions field value. */ @Internal @@ -3233,7 +3233,7 @@ public abstract class DOPAbstractType { /** * Sets the fAutoVersions field value. - * + * */ @Internal public void setFAutoVersions( boolean value ) @@ -3242,7 +3242,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fAutoVersions field value. */ @Internal @@ -3253,7 +3253,7 @@ public abstract class DOPAbstractType { /** * Sets the fVirusPrompted field value. - * + * */ @Internal public void setFVirusPrompted( boolean value ) @@ -3262,7 +3262,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fVirusPrompted field value. */ @Internal @@ -3273,7 +3273,7 @@ public abstract class DOPAbstractType { /** * Sets the fVirusLoadSafe field value. - * + * */ @Internal public void setFVirusLoadSafe( boolean value ) @@ -3282,7 +3282,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the fVirusLoadSafe field value. */ @Internal @@ -3293,7 +3293,7 @@ public abstract class DOPAbstractType { /** * Sets the KeyVirusSession30 field value. - * + * */ @Internal public void setKeyVirusSession30( int value ) @@ -3302,7 +3302,7 @@ public abstract class DOPAbstractType { } /** - * + * * @return the KeyVirusSession30 field value. */ @Internal diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/LVLFAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/LVLFAbstractType.java index e101fe9e2e..79ade79b26 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/LVLFAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/LVLFAbstractType.java @@ -74,7 +74,7 @@ public abstract class LVLFAbstractType field_1_iStartAt = LittleEndian.getInt( data, 0x0 + offset ); field_2_nfc = data[ 0x4 + offset ]; field_3_info = data[ 0x5 + offset ]; - field_4_rgbxchNums = LittleEndian.getByteArray( data, 0x6 + offset,9 ); + field_4_rgbxchNums = Arrays.copyOfRange( data, 0x6 + offset, 0x6 + offset + 9 ); field_5_ixchFollow = data[ 0xf + offset ]; field_6_dxaIndentSav = LittleEndian.getInt( data, 0x10 + offset ); field_7_unused2 = LittleEndian.getInt( data, 0x14 + offset ); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/types/PICFAbstractType.java b/src/scratchpad/src/org/apache/poi/hwpf/model/types/PICFAbstractType.java index b41b2ba837..22d4b22dbe 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/types/PICFAbstractType.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/types/PICFAbstractType.java @@ -21,7 +21,8 @@ package org.apache.poi.hwpf.model.types; import java.util.Arrays; -import org.apache.poi.util.*; +import org.apache.poi.util.Internal; +import org.apache.poi.util.LittleEndian; /** * The PICF structure specifies the type of a picture, as well as the size of the @@ -29,17 +30,17 @@ import org.apache.poi.util.*; from Microsoft Office Word 97-2007 Binary File Format and [MS-DOC] - v20110608 Word (.doc) Binary File Format - + * <p> * NOTE: This source is automatically generated please do not modify this file. Either subclass or * remove the record in src/types/definitions. * <p> - * This class is internal. It content or properties may change without notice + * This class is internal. It content or properties may change without notice * due to changes in our knowledge of internal Microsoft Word binary structures. * @author Sergey Vladimirov; according to Microsoft Office Word 97-2007 Binary File Format Specification [*.doc] and [MS-DOC] - v20110608 Word (.doc) Binary File Format - + */ @Internal public abstract class PICFAbstractType @@ -103,10 +104,10 @@ public abstract class PICFAbstractType field_18_dyaReserved2 = LittleEndian.getShort( data, 0x2a + offset ); field_19_fReserved = data[ 0x2c + offset ]; field_20_bpp = data[ 0x2d + offset ]; - field_21_brcTop80 = LittleEndian.getByteArray( data, 0x2e + offset,4 ); - field_22_brcLeft80 = LittleEndian.getByteArray( data, 0x32 + offset,4 ); - field_23_brcBottom80 = LittleEndian.getByteArray( data, 0x36 + offset,4 ); - field_24_brcRight80 = LittleEndian.getByteArray( data, 0x3a + offset,4 ); + field_21_brcTop80 = Arrays.copyOfRange( data, 0x2e + offset, 0x2e + offset + 4 ); + field_22_brcLeft80 = Arrays.copyOfRange( data, 0x32 + offset, 0x32 + offset + 4 ); + field_23_brcBottom80 = Arrays.copyOfRange( data, 0x36 + offset, 0x36 + offset + 4 ); + field_24_brcRight80 = Arrays.copyOfRange( data, 0x3a + offset, 0x3a + offset + 4 ); field_25_dxaReserved3 = LittleEndian.getShort( data, 0x3e + offset ); field_26_dyaReserved3 = LittleEndian.getShort( data, 0x40 + offset ); field_27_cProps = LittleEndian.getShort( data, 0x42 + offset ); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java index ddd7b52aa2..c89661cd99 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/ParagraphSprmUncompressor.java @@ -18,6 +18,7 @@ package org.apache.poi.hwpf.sprm; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -314,11 +315,9 @@ public final class ParagraphSprmUncompressor case 0x3b: //obsolete break; - case 0x3e: - { - byte[] buf = new byte[sprm.size() - 3]; - System.arraycopy(buf, 0, sprm.getGrpprl(), sprm.getGrpprlOffset(), - buf.length); + case 0x3e: { + // TODO: REMOVEME + byte[] buf = Arrays.copyOfRange(sprm.getGrpprl(), sprm.getGrpprlOffset(), sprm.getGrpprlOffset() + (sprm.size() - 3)); newPAP.setAnld(buf); break; } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java index 7f64b01047..11072bc334 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SectionSprmUncompressor.java @@ -17,6 +17,8 @@ package org.apache.poi.hwpf.sprm; +import java.util.Arrays; + import org.apache.poi.hwpf.usermodel.BorderCode; import org.apache.poi.hwpf.usermodel.SectionProperties; import org.apache.poi.util.HexDump; @@ -69,8 +71,7 @@ public final class SectionSprmUncompressor extends SprmUncompressor newSEP.setIHeadingPgn ((byte) sprm.getOperand()); break; case 0x2: - byte[] buf = new byte[sprm.size() - 3]; - System.arraycopy(sprm.getGrpprl(), sprm.getGrpprlOffset(), buf, 0, buf.length); + byte[] buf = Arrays.copyOfRange(sprm.getGrpprl(), sprm.getGrpprlOffset(), sprm.getGrpprlOffset() + (sprm.size() - 3)); newSEP.setOlstAnm (buf); break; case 0x3: @@ -216,11 +217,11 @@ public final class SectionSprmUncompressor extends SprmUncompressor newSEP.setWTextFlow ((short) sprm.getOperand()); break; case 0x3C: - // [MS-DOC], v20140721, 2.6.4, sprmSRncFtn + // [MS-DOC], v20140721, 2.6.4, sprmSRncFtn newSEP.setRncFtn((short) sprm.getOperand()); break; case 0x3E: - // [MS-DOC], v20140721, 2.6.4, sprmSRncEdn + // [MS-DOC], v20140721, 2.6.4, sprmSRncEdn newSEP.setRncEdn((short) sprm.getOperand()); break; case 0x3F: diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java index 1bcee335e8..af937e6465 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmBuffer.java @@ -127,9 +127,8 @@ public final class SprmBuffer implements Duplicatable { // commented - buffer shall not contain any additional bytes -- // sergey // byte[] newBuf = new byte[_offset + addition + 6]; - byte[] newBuf = IOUtils.safelyAllocate(_offset + addition, MAX_RECORD_LENGTH); - System.arraycopy(_buf, 0, newBuf, 0, _buf.length); - _buf = newBuf; + IOUtils.safelyAllocateCheck(_offset + addition, MAX_RECORD_LENGTH); + _buf = Arrays.copyOf(_buf, _offset + addition); } } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmOperation.java b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmOperation.java index 287063c22d..3fc26d0712 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmOperation.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/sprm/SprmOperation.java @@ -17,6 +17,8 @@ package org.apache.poi.hwpf.sprm; +import java.util.Arrays; + import org.apache.poi.util.BitField; import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.Internal; @@ -75,9 +77,7 @@ public final class SprmOperation public byte[] toByteArray() { - byte[] result = new byte[size()]; - System.arraycopy( _grpprl, _offset, result, 0, size() ); - return result; + return Arrays.copyOfRange(_grpprl, _offset, _offset + size()); } public byte[] getGrpprl() diff --git a/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java b/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java index 04fa813732..3b5b1ec0b6 100644 --- a/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java +++ b/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java @@ -119,8 +119,7 @@ public final class TestCompressedRTF { MAPIRtfAttribute rtfAttr = (MAPIRtfAttribute) attr; // Truncate to header + flag + data for flag - byte[] data = new byte[16 + 12]; - System.arraycopy(rtfAttr.getRawData(), 0, data, 0, data.length); + byte[] data = Arrays.copyOf(rtfAttr.getRawData(), 16 + 12); // Decompress it CompressedRTF comp = new CompressedRTF(); diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java index 40e20429ed..299a71e7fc 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/usermodel/TestPictures.java @@ -26,6 +26,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.URL; +import java.util.Arrays; import java.util.List; import org.apache.poi.POIDataSamples; @@ -49,7 +50,7 @@ import org.junit.Test; * @author Yegor Kozlov */ public final class TestPictures { - private static POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); + private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance(); /** * Test read/write Macintosh PICT @@ -66,11 +67,11 @@ public final class TestPictures { Dimension nDim = nHeader.getSize(); assertEquals(expWidth, nDim.getWidth(), 0); assertEquals(expHeight, nDim.getHeight(), 0); - + Dimension dim = data.getImageDimensionInPixels(); assertEquals(Units.pointsToPixel(expWidth), dim.getWidth(), 0); assertEquals(Units.pointsToPixel(expHeight), dim.getHeight(), 0); - + HSLFPictureShape pict = new HSLFPictureShape(data); assertEquals(data.getIndex(), pict.getPictureIndex()); slide.addShape(pict); @@ -91,12 +92,12 @@ public final class TestPictures { //check picture data List<HSLFPictureData> pictures = ppt.getPictureData(); assertEquals(1, pictures.size()); - + HSLFPictureData pd = pictures.get(0); dim = pd.getImageDimension(); assertEquals(expWidth, dim.width); assertEquals(expHeight, dim.height); - + //the Picture shape refers to the PictureData object in the Presentation assertEquals(pict.getPictureData(), pd); @@ -107,10 +108,8 @@ public final class TestPictures { byte[] ppt_bytes = pd.getData(); assertEquals(src_bytes.length, ppt_bytes.length); //in PICT the first 512 bytes are MAC specific and may not be preserved, ignore them - byte[] b1 = new byte[src_bytes.length-512]; - System.arraycopy(src_bytes, 512, b1, 0, b1.length); - byte[] b2 = new byte[ppt_bytes.length-512]; - System.arraycopy(ppt_bytes, 512, b2, 0, b2.length); + byte[] b1 = Arrays.copyOfRange(src_bytes, 512, src_bytes.length); + byte[] b2 = Arrays.copyOfRange(ppt_bytes, 512, ppt_bytes.length); assertArrayEquals(b1, b2); } @@ -133,7 +132,7 @@ public final class TestPictures { Dimension dim = data.getImageDimensionInPixels(); assertEquals(Units.pointsToPixel(expWidth), dim.getWidth(), 0); assertEquals(Units.pointsToPixel(expHeight), dim.getHeight(), 0); - + HSLFPictureShape pict = new HSLFPictureShape(data); assertEquals(data.getIndex(), pict.getPictureIndex()); slide.addShape(pict); @@ -159,20 +158,18 @@ public final class TestPictures { dim = pd.getImageDimension(); assertEquals(expWidth, dim.width); assertEquals(expHeight, dim.height); - + //the Picture shape refers to the PictureData object in the Presentation assertEquals(pict.getPictureData(), pd); - + assertEquals(PictureType.WMF, pd.getType()); assertTrue(pd instanceof WMF); //compare the content of the initial file with what is stored in the PictureData byte[] ppt_bytes = pd.getData(); assertEquals(src_bytes.length, ppt_bytes.length); //in WMF the first 22 bytes - is a metafile header - byte[] b1 = new byte[src_bytes.length-22]; - System.arraycopy(src_bytes, 22, b1, 0, b1.length); - byte[] b2 = new byte[ppt_bytes.length-22]; - System.arraycopy(ppt_bytes, 22, b2, 0, b2.length); + byte[] b1 = Arrays.copyOfRange(src_bytes, 22, src_bytes.length); + byte[] b2 = Arrays.copyOfRange(ppt_bytes, 22, ppt_bytes.length); assertArrayEquals(b1, b2); } @@ -195,7 +192,7 @@ public final class TestPictures { Dimension dim = data.getImageDimensionInPixels(); assertEquals(Units.pointsToPixel(expWidth), dim.getWidth(), 0); assertEquals(Units.pointsToPixel(expHeight), dim.getHeight(), 0); - + HSLFPictureShape pict = new HSLFPictureShape(data); assertEquals(data.getIndex(), pict.getPictureIndex()); slide.addShape(pict); @@ -216,12 +213,12 @@ public final class TestPictures { //check picture data List<HSLFPictureData> pictures = ppt.getPictureData(); assertEquals(1, pictures.size()); - + HSLFPictureData pd = pictures.get(0); dim = pd.getImageDimension(); assertEquals(expWidth, dim.width); assertEquals(expHeight, dim.height); - + //the Picture shape refers to the PictureData object in the Presentation assertEquals(pict.getPictureData(), pd); @@ -393,10 +390,8 @@ public final class TestPictures { ppt_bytes = slTests.readFile("santa.wmf"); assertEquals(src_bytes.length, ppt_bytes.length); //ignore the first 22 bytes - it is a WMF metafile header - b1 = new byte[src_bytes.length-22]; - System.arraycopy(src_bytes, 22, b1, 0, b1.length); - b2 = new byte[ppt_bytes.length-22]; - System.arraycopy(ppt_bytes, 22, b2, 0, b2.length); + b1 = Arrays.copyOfRange(src_bytes, 22, src_bytes.length); + b2 = Arrays.copyOfRange(ppt_bytes, 22, ppt_bytes.length); assertArrayEquals(b1, b2); pict = (HSLFPictureShape)slides.get(3).getShapes().get(0); //the forth slide contains PICT @@ -407,10 +402,8 @@ public final class TestPictures { ppt_bytes = slTests.readFile("cow.pict"); assertEquals(src_bytes.length, ppt_bytes.length); //ignore the first 512 bytes - it is a MAC specific crap - b1 = new byte[src_bytes.length-512]; - System.arraycopy(src_bytes, 512, b1, 0, b1.length); - b2 = new byte[ppt_bytes.length-512]; - System.arraycopy(ppt_bytes, 512, b2, 0, b2.length); + b1 = Arrays.copyOfRange(src_bytes, 512, src_bytes.length); + b2 = Arrays.copyOfRange(ppt_bytes, 512, ppt_bytes.length); assertArrayEquals(b1, b2); pict = (HSLFPictureShape)slides.get(4).getShapes().get(0); //the fifth slide contains EMF @@ -457,7 +450,7 @@ public final class TestPictures { pdata = pict.getPictureData(); assertTrue(pdata instanceof WMF); assertEquals(PictureType.WMF, pdata.getType()); - + ppt.close(); } |