Class SystemLimitException

All Implemented Interfaces:
Serializable

public class SystemLimitException extends AvroRuntimeException
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:

  • org.apache.avro.limits.byte.maxLength
  • limits the maximum size of byte types.
  • org.apache.avro.limits.collectionItems.maxLength
  • limits the maximum number of map and list items that can be read at once single sequence.
  • org.apache.avro.limits.string.maxLength
  • limits the maximum size of string types.
The default is to permit sizes up to MAX_ARRAY_VM_LIMIT.
See Also:
  • Field Details

  • Constructor Details

    • SystemLimitException

      public SystemLimitException(String message)
  • Method Details

    • checkMaxBytesLength

      public static int checkMaxBytesLength(long length)
      Check to ensure that reading the bytes is within the specified limits.
      Parameters:
      length - The proposed size of the bytes to read
      Returns:
      The size of the bytes if and only if it is within the limit and non-negative.
      Throws:
      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
    • checkMaxCollectionLength

      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 - The number of elements items read in the collection
      items - 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:
      The total number of items in the collection if and only if it is within the limit and non-negative.
      Throws:
      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
    • checkMaxCollectionLength

      public static int checkMaxCollectionLength(long items)
      Check to ensure that reading the specified number of items remains within the specified limits.
      Parameters:
      items - 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:
      The total number of items in the collection if and only if it is within the limit and non-negative.
      Throws:
      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
    • checkMaxStringLength

      public static int checkMaxStringLength(long length)
      Check to ensure that reading the string size is within the specified limits.
      Parameters:
      length - The proposed size of the string to read
      Returns:
      The size of the string if and only if it is within the limit and non-negative.
      Throws:
      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