{"record":{"id":"ae77e91c55224246","repo":"prestodb/presto","slug":"eof-while-reading-unsigned-vint","errorCode":null,"errorMessage":"EOF while reading unsigned vint","messagePattern":"EOF while reading unsigned vint","errorType":"exception","errorClass":"OrcCorruptionException","httpStatus":null,"severity":"error","filePath":"presto-orc/src/main/java/com/facebook/presto/orc/stream/LongDecode.java","lineNumber":138,"sourceCode":"    }\n\n    public static long readSignedVInt(OrcInputStream inputStream)\n            throws IOException\n    {\n        long result = readUnsignedVInt(inputStream);\n        return zigzagDecode(result);\n    }\n\n    private static long readUnsignedVInt(OrcInputStream inputStream)\n            throws IOException\n    {\n        long result = 0;\n        int offset = 0;\n        long b;\n        do {\n            b = inputStream.read();\n            if (b == -1) {\n                throw new OrcCorruptionException(inputStream.getOrcDataSourceId(), \"EOF while reading unsigned vint\");\n            }\n            result |= (b & 0b0111_1111) << offset;\n            offset += 7;\n        }\n        while ((b & 0b1000_0000) != 0);\n        return result;\n    }\n\n    public static long readVInt(boolean signed, OrcInputStream inputStream)\n            throws IOException\n    {\n        if (signed) {\n            return readSignedVInt(inputStream);\n        }\n        else {\n            return readUnsignedVInt(inputStream);\n        }\n    }","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-orc/src/main/java/com/facebook/presto/orc/stream/LongDecode.java#L120-L156","documentation":"Thrown by LongDecode.readUnsignedVInt when the underlying input reaches EOF (-1) while consuming an unsigned varint. ORC encodes many integers (lengths, dictionaries, secondary streams) as varints; a varint that never terminates before end-of-stream means the stream is truncated or corrupt, so the reader aborts instead of returning a bogus value.","triggerScenarios":"readUnsignedVInt (and readVInt built on it) loops while the high bit is set; input.read() returns -1 before a byte with the high bit clear is seen.","commonSituations":"ORC files truncated during upload/download; interrupted HDFS writes without checksums; corrupted S3 objects (bad multipart copy); footer declaring more values than the stream actually contains from a buggy writer.","solutions":["Verify the file with orc-tools meta/orc-dump; a varint EOF confirms truncation — re-copy from the source of truth.","Regenerate the ORC file from source data.","Enable/verify storage checksums to catch corruption during transfer or at rest.","Upgrade the writer (Hive/Spark/Presto) if its ORC writer version is known to emit incorrect stream lengths.","Wait for writing jobs to commit before querying external tables pointing at in-progress files."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-read integrity check\ntry (InputStream in = open(path)) {\n    byte[] ps = OrcMagic.MAGIC.getBytes(StandardCharsets.US_ASCII);\n    byte[] head = in.readNBytes(ps.length);\n    if (!Arrays.equals(head, ps)) { throw new IllegalStateException(\"not a complete ORC file: \" + path); }\n}","typeGuard":null,"tryCatchPattern":"try {\n    long v = LongDecode.readVInt(inputStream);\n} catch (OrcCorruptionException e) {\n    if (e.getMessage().contains(\"EOF while reading unsigned vint\")) {\n        return recovery.recopyFileAndReopen(path);\n    }\n    throw e;\n}","preventionTips":["Verify checksums (HDFS CRC / S3 ETag) before and after every transfer.","Use orc-tools meta validation as an ingest gate for external data.","Only query committed, immutable ORC files.","Upgrade writers known to emit wrong stream lengths (check release notes for ORC fixes)."],"tags":["orc","varint","eof","truncated-file"],"backgroundTag":"orc-file-corruption","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"}