Top Description Fields Constructors Methods
org.apache.avro

public Class SystemLimitException

extends AvroRuntimeException
Class Inheritance
Imports
org.slf4j.LoggerFactory

Thrown to prevent making large allocations when reading potentially pathological input data from an untrusted source.

The following system properties can be set to limit the size of bytes, strings and collection types to be allocated:

The default is to permit sizes up to MAX_ARRAY_VM_LIMIT.

Field Summary

Modifier and TypeField and Description
pack-priv static final int
MAX_ARRAY_VM_LIMIT

The maximum length of array to allocate (unless necessary).

public static final String
public static final String
public static final String
private static int
private static int
private static int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

The size of the bytes if and only if it is within the limit and non-negative.
checkMaxBytesLength
(long
The proposed size of the bytes to read
length
)

Check to ensure that reading the bytes is within the specified limits.

public static int

Returns:

The total number of items in the collection if and only if it is within the limit and non-negative.
checkMaxCollectionLength
(long
The number of elements items read in the collection
existing
,
long
The next number of items to read. In normal usage, this is always a positive, permitted value. Negative and zero values have a special meaning in Avro decoding.
items
)

Check to ensure that reading the specified number of items remains within the specified limits.

public static int

Returns:

The size of the string if and only if it is within the limit and non-negative.
checkMaxStringLength
(long
The proposed size of the string to read
length
)

Check to ensure that reading the string size is within the specified limits.

private static int

Returns:

The value from the system property
getLimitFromProperty
(String
The system property to fetch
property
,
int
The value to use if the system property is not present or parsable as an int
defaultValue
)

Get an integer value stored in a system property, used to configure the system behaviour of decoders

pack-priv static void
resetLimits()

Reread the limits from the system properties.

Field Detail

MAX_ARRAY_VM_LIMITback to summary
pack-priv static final int MAX_ARRAY_VM_LIMIT

The maximum length of array to allocate (unless necessary). Some VMs reserve some header words in an array. Attempts to allocate larger arrays may result in OutOfMemoryError: Requested array size exceeds VM limit

See Also
JDK-8246725
MAX_BYTES_LENGTH_PROPERTYback to summary
public static final String MAX_BYTES_LENGTH_PROPERTY
MAX_COLLECTION_LENGTH_PROPERTYback to summary
public static final String MAX_COLLECTION_LENGTH_PROPERTY
MAX_STRING_LENGTH_PROPERTYback to summary
public static final String MAX_STRING_LENGTH_PROPERTY
maxBytesLengthback to summary
private static int maxBytesLength
maxCollectionLengthback to summary
private static int maxCollectionLength
maxStringLengthback to summary
private static int maxStringLength

Constructor Detail

SystemLimitExceptionback to summary
public SystemLimitException(String message)

Method Detail

checkMaxBytesLengthback to summary
public static int checkMaxBytesLength(long length)

Check to ensure that reading the bytes is within the specified limits.

Parameters
length:long

The proposed size of the bytes to read

Returns:int

The size of the bytes if and only if it is within the limit and non-negative.

Exceptions
UnsupportedOperationException:
if reading the datum would allocate a collection that the Java VM would be unable to handle
SystemLimitException:
if the decoding should fail because it would otherwise result in an allocation exceeding the set limit
AvroRuntimeException:
if the length is negative
checkMaxCollectionLengthback to summary
public static int checkMaxCollectionLength(long existing, long items)

Check to ensure that reading the specified number of items remains within the specified limits.

Parameters
existing:long

The number of elements items read in the collection

items:long

The next number of items to read. In normal usage, this is always a positive, permitted value. Negative and zero values have a special meaning in Avro decoding.

Returns:int

The total number of items in the collection if and only if it is within the limit and non-negative.

Exceptions
UnsupportedOperationException:
if reading the items would allocate a collection that the Java VM would be unable to handle
SystemLimitException:
if the decoding should fail because it would otherwise result in an allocation exceeding the set limit
AvroRuntimeException:
if the length is negative
checkMaxStringLengthback to summary
public static int checkMaxStringLength(long length)

Check to ensure that reading the string size is within the specified limits.

Parameters
length:long

The proposed size of the string to read

Returns:int

The size of the string if and only if it is within the limit and non-negative.

Exceptions
UnsupportedOperationException:
if reading the items would allocate a collection that the Java VM would be unable to handle
SystemLimitException:
if the decoding should fail because it would otherwise result in an allocation exceeding the set limit
AvroRuntimeException:
if the length is negative
getLimitFromPropertyback to summary
private static int getLimitFromProperty(String property, int defaultValue)

Get an integer value stored in a system property, used to configure the system behaviour of decoders

Parameters
property:String

The system property to fetch

defaultValue:int

The value to use if the system property is not present or parsable as an int

Returns:int

The value from the system property

resetLimitsback to summary
pack-priv static void resetLimits()

Reread the limits from the system properties.