{"record":{"id":"050a90f790321ae5","repo":"prestodb/presto","slug":"decoded-value-out-of-range-for-a-32bit-number","errorCode":null,"errorMessage":"Decoded value out of range for a 32bit number","messagePattern":"Decoded value out of range for a 32bit number","errorType":"exception","errorClass":"OrcCorruptionException","httpStatus":null,"severity":"error","filePath":"presto-orc/src/main/java/com/facebook/presto/orc/stream/LongInputStreamV1.java","lineNumber":137,"sourceCode":"    @Override\n    public void next(int[] values, int items)\n            throws IOException\n    {\n        int offset = 0;\n        while (items > 0) {\n            if (used == numValuesInRun) {\n                numValuesInRun = 0;\n                used = 0;\n                readHeader();\n            }\n\n            int chunkSize = min(numValuesInRun - used, items);\n            if (repeat) {\n                for (int i = 0; i < chunkSize; i++) {\n                    long literal = repeatBase + ((used + i) * delta);\n                    int value = (int) literal;\n                    if (literal != value) {\n                        throw new OrcCorruptionException(input.getOrcDataSourceId(), \"Decoded value out of range for a 32bit number\");\n                    }\n                    values[offset + i] = value;\n                }\n            }\n            else {\n                for (int i = 0; i < chunkSize; i++) {\n                    long literal = input.readVarint(signed);\n                    int value = (int) literal;\n                    if (literal != value) {\n                        throw new OrcCorruptionException(input.getOrcDataSourceId(), \"Decoded value out of range for a 32bit number\");\n                    }\n                    values[offset + i] = value;\n                }\n            }\n            used += chunkSize;\n            offset += chunkSize;\n            items -= chunkSize;\n        }","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-orc/src/main/java/com/facebook/presto/orc/stream/LongInputStreamV1.java#L119-L155","documentation":"next(int[], items) for INT (32-bit) columns decodes values via run-length reconstruction (repeatBase + (used + i) * delta) into a long, then narrows to int. If the long does not fit in 32 bits (narrowing changed the value), the underlying data violates the column's declared INT type. The library throws OrcCorruptionException rather than silently returning a wrapped/truncated value.","triggerScenarios":"next() called on a 32-bit LongInputStreamV1 where a run-mode literal repeatBase + (used + i) * delta overflows the int range — caused by corrupt delta/base bytes or wrong schema mapping (column actually encodes 64-bit values).","commonSituations":"Schema evolution mismatches (column declared INT in this reader's schema but written as BIGINT elsewhere), ORC files corrupted by bit-flips, or a reader interpreting the wrong column stream index after schema reordering.","solutions":["Verify the table/column schema matches the file: if values are genuinely 64-bit, change the column to BIGINT so the 64-bit decode path is used.","Validate the ORC file with orc-tools; corrupt base/delta bytes indicate file damage — restore from backup.","Confirm the reader's column mapping/orcSchema matches the writer's schema to avoid decoding the wrong stream with the wrong width.","If the writer is buggy (emits out-of-range values for INT columns), fix or upgrade the writer."],"exampleFix":"// before: column declared as INT in Hive/Presto but data written as BIGINT\nCREATE TABLE t (v INT) STORED AS ORC; // fails: out of range for 32bit\n// after\nCREATE TABLE t (v BIGINT) STORED AS ORC;","handlingStrategy":"validation","validationCode":"ColumnType expected = readSchemaType(orcFile, \"my_col\");\nif (expected == ColumnType.LONG || expected == ColumnType.BIGINT) {\n    // use the 64-bit read path; do not map this stream to int[]\n    throw new SchemaMismatchException(\"my_col is BIGINT in file; cannot decode as int\");\n}","typeGuard":"// Java: no runtime narrowing possible silently — guard explicitly\nstatic boolean fitsInt(long v) { return v >= Integer.MIN_VALUE && v <= Integer.MAX_VALUE; }\n// use: if (!fitsInt(literal)) handleOverflow();","tryCatchPattern":"try {\n    return intStream.next(values, items);\n} catch (OrcCorruptionException e) {\n    if (e.getMessage().contains(\"out of range for a 32bit number\")) {\n        LOG.error(\"Column declared INT contains 64-bit values; re-read as BIGINT\");\n        return bigIntReader.next(); // fall back to the wide-typed reader\n    }\n    throw e;\n}","preventionTips":["Keep metastore/table schema in sync with the file's embedded ORC schema.","Declare columns as BIGINT when values may exceed int range.","Validate files with orc-tools to catch corrupted base/delta bytes early.","Test schema-evolution paths (widening types) before deploying reader changes."],"tags":["orc","corruption","schema-mismatch","integer-overflow"],"backgroundTag":"value-out-of-range-for-type","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"}