mirror of https://github.com/apache/poi.git
configurable max record len
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894525 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8644c69b4c
commit
e823df8029
|
@ -32,10 +32,25 @@ import org.apache.poi.util.LittleEndian;
|
|||
*/
|
||||
public class EscherComplexProperty extends EscherProperty {
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000_000;
|
||||
private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000_000;
|
||||
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
|
||||
|
||||
private byte[] complexData;
|
||||
|
||||
/**
|
||||
* @param length the max record length allowed for EscherComplexProperty
|
||||
*/
|
||||
public static void setMaxRecordLength(int length) {
|
||||
MAX_RECORD_LENGTH = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the max record length allowed for EscherComplexProperty
|
||||
*/
|
||||
public static int getMaxRecordLength() {
|
||||
return MAX_RECORD_LENGTH;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a complex property using the property id and a byte array containing the complex
|
||||
* data value size.
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.poi.hpsf;
|
|||
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
|
||||
/**
|
||||
* <p>Class to manipulate data in the Clipboard Variant ({@link
|
||||
* Variant#VT_CF VT_CF}) format.</p>
|
||||
|
@ -121,7 +122,8 @@ public final class Thumbnail {
|
|||
public static final int CF_BITMAP = 2;
|
||||
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 1_000_000;
|
||||
private static final int DEFAULT_MAX_RECORD_LENGTH = 1_000_000;
|
||||
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
|
||||
|
||||
/**
|
||||
* <p>A <code>byte[]</code> to hold a thumbnail image in ({@link
|
||||
|
@ -129,7 +131,19 @@ public final class Thumbnail {
|
|||
*/
|
||||
private byte[] _thumbnailData;
|
||||
|
||||
/**
|
||||
* @param length the max record length allowed for SubRecord
|
||||
*/
|
||||
public static void setMaxRecordLength(int length) {
|
||||
MAX_RECORD_LENGTH = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the max record length allowed for SubRecord
|
||||
*/
|
||||
public static int getMaxRecordLength() {
|
||||
return MAX_RECORD_LENGTH;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Default Constructor. If you use it then one you'll have to add
|
||||
|
|
|
@ -38,8 +38,26 @@ import org.apache.poi.util.Removal;
|
|||
public final class DrawingGroupRecord extends AbstractEscherHolderRecord {
|
||||
public static final short sid = 0xEB;
|
||||
|
||||
static final int MAX_RECORD_SIZE = 8228;
|
||||
private static final int MAX_DATA_SIZE = MAX_RECORD_SIZE - 4;
|
||||
private static final int DEFAULT_MAX_RECORD_SIZE = 8228;
|
||||
private static int MAX_RECORD_SIZE = DEFAULT_MAX_RECORD_SIZE;
|
||||
|
||||
/**
|
||||
* @param size the max record size allowed for DrawingGroupRecord
|
||||
*/
|
||||
public static void setMaxRecordSize(int size) {
|
||||
MAX_RECORD_SIZE = size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the max record size allowed for DrawingGroupRecord
|
||||
*/
|
||||
public static int getMaxRecordSize() {
|
||||
return MAX_RECORD_SIZE;
|
||||
}
|
||||
|
||||
private static int getMaxDataSize() {
|
||||
return MAX_RECORD_SIZE - 4;
|
||||
}
|
||||
|
||||
public DrawingGroupRecord() {}
|
||||
|
||||
|
@ -112,7 +130,7 @@ public final class DrawingGroupRecord extends AbstractEscherHolderRecord {
|
|||
|
||||
static int grossSizeFromDataSize(int dataSize)
|
||||
{
|
||||
return dataSize + ( (dataSize - 1) / MAX_DATA_SIZE + 1 ) * 4;
|
||||
return dataSize + ( (dataSize - 1) / getMaxDataSize() + 1 ) * 4;
|
||||
}
|
||||
|
||||
private int writeData( int offset, byte[] data, byte[] rawData )
|
||||
|
@ -121,8 +139,9 @@ public final class DrawingGroupRecord extends AbstractEscherHolderRecord {
|
|||
int writtenRawData = 0;
|
||||
while (writtenRawData < rawData.length)
|
||||
{
|
||||
int segmentLength = Math.min( rawData.length - writtenRawData, MAX_DATA_SIZE);
|
||||
if (writtenRawData / MAX_DATA_SIZE >= 2)
|
||||
final int maxDataSize = getMaxDataSize();
|
||||
int segmentLength = Math.min( rawData.length - writtenRawData, maxDataSize);
|
||||
if (writtenRawData / maxDataSize >= 2)
|
||||
writeContinueHeader( data, offset, segmentLength );
|
||||
else
|
||||
writeHeader( data, offset, segmentLength );
|
||||
|
|
|
@ -92,8 +92,22 @@ public final class EscherAggregate extends AbstractEscherHolderRecord {
|
|||
// not a real sid - dummy value
|
||||
public static final short sid = 9876;
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 100_000_000;
|
||||
private static final int DEFAULT_MAX_RECORD_LENGTH = 100_000_000;
|
||||
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
|
||||
|
||||
/**
|
||||
* @param length the max record length allowed for EscherAggregate
|
||||
*/
|
||||
public static void setMaxRecordLength(int length) {
|
||||
MAX_RECORD_LENGTH = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the max record length allowed for EscherAggregate
|
||||
*/
|
||||
public static int getMaxRecordLength() {
|
||||
return MAX_RECORD_LENGTH;
|
||||
}
|
||||
|
||||
/** @deprecated not used */
|
||||
@Deprecated
|
||||
|
|
|
@ -86,7 +86,22 @@ public abstract class SubRecord implements Duplicatable, GenericRecord {
|
|||
|
||||
|
||||
//arbitrarily selected; may need to increase
|
||||
private static final int MAX_RECORD_LENGTH = 1_000_000;
|
||||
private static final int DEFAULT_MAX_RECORD_LENGTH = 1_000_000;
|
||||
private static int MAX_RECORD_LENGTH = DEFAULT_MAX_RECORD_LENGTH;
|
||||
|
||||
/**
|
||||
* @param length the max record length allowed for SubRecord
|
||||
*/
|
||||
public static void setMaxRecordLength(int length) {
|
||||
MAX_RECORD_LENGTH = length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the max record length allowed for SubRecord
|
||||
*/
|
||||
public static int getMaxRecordLength() {
|
||||
return MAX_RECORD_LENGTH;
|
||||
}
|
||||
|
||||
protected SubRecord() {}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.poi.util.HexDump;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
final class TestDrawingGroupRecord {
|
||||
private static final int MAX_RECORD_SIZE = 8228;
|
||||
private static final int MAX_RECORD_SIZE = DrawingGroupRecord.getMaxRecordSize();
|
||||
private static final int MAX_DATA_SIZE = MAX_RECORD_SIZE - 4;
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue