{"record":{"id":"9aca07ed62255d79","repo":"prestodb/presto","slug":"index-out-of-bound-s-length-s","errorCode":null,"errorMessage":"Index out of bound: %s (length: %s)","messagePattern":"Index out of bound: (.+?) \\(length: (.+?)\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-parquet/src/main/java/com/facebook/presto/parquet/spark/VariantUtil.java","lineNumber":140,"sourceCode":"\n    public static final int U24_MAX = 0xFFFFFF;\n    public static final int U32_SIZE = 4;\n\n    // Both variant value and variant metadata need to be no longer than 16MiB.\n    public static final int SIZE_LIMIT = U24_MAX + 1;\n\n    public static final int MAX_DECIMAL4_PRECISION = 9;\n    public static final int MAX_DECIMAL8_PRECISION = 18;\n    public static final int MAX_DECIMAL16_PRECISION = 38;\n\n    private VariantUtil() {}\n\n    // Check the validity of an array index `position`. Throw `MALFORMED_VARIANT` if it is out of bound,\n    // meaning that the variant is malformed.\n    static void checkIndex(int position, int length)\n    {\n        if (position < 0 || position >= length) {\n            throw new IllegalArgumentException(String.format(\"Index out of bound: %s (length: %s)\", position, length));\n        }\n    }\n\n    // Read a little-endian signed long value from `bytes[position, position + numBytes)`.\n    static long readLong(byte[] bytes, int position, int numBytes)\n    {\n        checkIndex(position, bytes.length);\n        checkIndex(position + numBytes - 1, bytes.length);\n        long result = 0;\n        // All bytes except the most significant byte should be unsign-extended and shifted (so we need\n        // `& 0xFF`). The most significant byte should be sign-extended and is handled after the loop.\n        for (int i = 0; i < numBytes - 1; ++i) {\n            long unsignedByteValue = bytes[position + i] & 0xFF;\n            result |= unsignedByteValue << (8 * i);\n        }\n        long signedByteValue = bytes[position + numBytes - 1];\n        result |= signedByteValue << (8 * (numBytes - 1));\n        return result;","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-parquet/src/main/java/com/facebook/presto/parquet/spark/VariantUtil.java#L122-L158","documentation":"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.","triggerScenarios":"Thrown at presto-parquet/src/main/java/com/facebook/presto/parquet/spark/VariantUtil.java:140 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Rewrite or re-ingest the malformed variant data","Validate variant payloads at write time with the same bounds checks","Upgrade the writer/reader pair to a consistent variant format version"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}