prestodb/presto · error · IllegalArgumentException

Index out of bound: %s (length: %s)

Error message

Index out of bound: %s (length: %s)

What it means

Bounds helper in VariantUtil: a byte position or index read from a variant's binary payload falls outside the array (e.g. position+numBytes exceeds length). Per the MALFORMED_VARIANT contract, this indicates the variant value itself is malformed — corrupted or written by an incompatible producer.

Source

Thrown at presto-parquet/src/main/java/com/facebook/presto/parquet/spark/VariantUtil.java:140

    public static final int U24_MAX = 0xFFFFFF;
    public static final int U32_SIZE = 4;

    // Both variant value and variant metadata need to be no longer than 16MiB.
    public static final int SIZE_LIMIT = U24_MAX + 1;

    public static final int MAX_DECIMAL4_PRECISION = 9;
    public static final int MAX_DECIMAL8_PRECISION = 18;
    public static final int MAX_DECIMAL16_PRECISION = 38;

    private VariantUtil() {}

    // Check the validity of an array index `position`. Throw `MALFORMED_VARIANT` if it is out of bound,
    // meaning that the variant is malformed.
    static void checkIndex(int position, int length)
    {
        if (position < 0 || position >= length) {
            throw new IllegalArgumentException(String.format("Index out of bound: %s (length: %s)", position, length));
        }
    }

    // Read a little-endian signed long value from `bytes[position, position + numBytes)`.
    static long readLong(byte[] bytes, int position, int numBytes)
    {
        checkIndex(position, bytes.length);
        checkIndex(position + numBytes - 1, bytes.length);
        long result = 0;
        // All bytes except the most significant byte should be unsign-extended and shifted (so we need
        // `& 0xFF`). The most significant byte should be sign-extended and is handled after the loop.
        for (int i = 0; i < numBytes - 1; ++i) {
            long unsignedByteValue = bytes[position + i] & 0xFF;
            result |= unsignedByteValue << (8 * i);
        }
        long signedByteValue = bytes[position + numBytes - 1];
        result |= signedByteValue << (8 * (numBytes - 1));
        return result;

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Rewrite or re-ingest the malformed variant data
  2. Validate variant payloads at write time with the same bounds checks
  3. Upgrade the writer/reader pair to a consistent variant format version
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at presto-parquet/src/main/java/com/facebook/presto/parquet/spark/VariantUtil.java:140 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/9aca07ed62255d79. Report an issue: GitHub.