{"record":{"id":"bbe79b96e8b613ba","repo":"prestodb/presto","slug":"invalid-rlev2-encoded-stream","errorCode":null,"errorMessage":"Invalid RLEv2 encoded stream","messagePattern":"Invalid RLEv2 encoded stream","errorType":"exception","errorClass":"OrcCorruptionException","httpStatus":null,"severity":"error","filePath":"presto-orc/src/main/java/com/facebook/presto/orc/stream/LongInputStreamV2.java","lineNumber":189,"sourceCode":"\n        // read the next base width number of bytes to extract base value\n        long base = bytesToLongBE(input, baseWidth);\n        long mask = (1L << ((baseWidth * 8) - 1));\n        // if MSB of base value is 1 then base is negative value else positive\n        if ((base & mask) != 0) {\n            base = base & ~mask;\n            base = -base;\n        }\n\n        // unpack the data blob\n        long[] unpacked = new long[length];\n        packer.unpack(unpacked, 0, length, fb, input);\n\n        // unpack the patch blob\n        long[] unpackedPatch = new long[patchListLength];\n\n        if ((patchWidth + patchGapWidth) > 64 && !skipCorrupt) {\n            throw new OrcCorruptionException(input.getOrcDataSourceId(), \"Invalid RLEv2 encoded stream\");\n        }\n\n        int bitSize = LongDecode.getClosestFixedBits(patchWidth + patchGapWidth);\n        packer.unpack(unpackedPatch, 0, patchListLength, bitSize, input);\n\n        // apply the patch directly when decoding the packed data\n        int patchIndex = 0;\n        long currentGap;\n        long currentPatch;\n        long patchMask = ((1L << patchWidth) - 1);\n        currentGap = unpackedPatch[patchIndex] >>> patchWidth;\n        currentPatch = unpackedPatch[patchIndex] & patchMask;\n        long actualGap = 0;\n\n        // special case: gap is >255 then patch value will be 0.\n        // if gap is <=255 then patch value cannot be 0\n        while (currentGap == 255 && currentPatch == 0) {\n            actualGap += 255;","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-orc/src/main/java/com/facebook/presto/orc/stream/LongInputStreamV2.java#L171-L207","documentation":"In RLEv2 PATCHED_BASE decoding, the patch blob stores each patch entry using patchWidth + patchGapWidth bits; if their sum exceeds 64 bits the stream cannot be represented/decoded and Presto declares the RLEv2 stream invalid, throwing OrcCorruptionException. This check only fires when skipCorrupt is false.","triggerScenarios":"readPatchedBaseValues (invoked from readValues -> next) encounters a header whose decoded patchWidth and patchGapWidth sum to > 64; this requires a corrupt/malformed header byte (thirdByte/fourthByte) since valid ORC writers never emit such widths.","commonSituations":"Bit-flipped or truncated bytes inside a stripe, files produced by broken third-party ORC writers, corrupted storage blocks, or reading a non-ORC/garbage file whose bytes accidentally decode into a patched-base header.","solutions":["Treat the file/stripe as corrupt: validate with orc-tools and re-generate or re-copy the ORC file from a trusted source.","Identify and fix the writing tool: upgrade the producer (Hive/Spark/custom writer) to a conforming ORC writer version.","Re-run with ORC session properties that tolerate bad data (e.g. skip corrupt stripes / ignore corrupted blocks) if partial results are acceptable.","Check storage layer integrity (S3 checksums, HDFS block corruption reports) and repair affected blocks.","If the trigger is a framework bug, upgrade Presto to a version with updated RLEv2 handling."],"exampleFix":"// before: corrupt file fails the whole query\nSELECT * FROM t; -- Invalid RLEv2 encoded stream\n\n// after: tolerate bad stripes (Presto session properties)\nSET SESSION orc_broken_streams_on_file_boundary = true;\n-- or re-write the file:\nINSERT INTO t_fixed SELECT * FROM t_corrupt_source;","handlingStrategy":"validation","validationCode":"// Scan the file for decodable stripes before querying:\n// java -jar orc-tools-*.jar scan data.orc  -- exits non-zero / logs on corrupt streams","typeGuard":null,"tryCatchPattern":"try (OrcDataSource src = new FileOrcDataSource(path, config)) {\n    new OrcReader(src, config).readAll();\n} catch (OrcCorruptionException e) {\n    // quarantine the file and re-ingest from source\n}","preventionTips":["Only ingest ORC files from conforming, up-to-date writers.","Validate with orc-tools before registering external tables.","Enable storage checksums (S3 ETag/SHA, HDFS block verification).","Quarantine and re-ingest files that fail stripe validation instead of querying them.","Keep Presto updated for improved RLEv2 corruption tolerance options."],"tags":["orc","data-corruption","rlev2","presto"],"backgroundTag":"corrupt-orc-rle-stream","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"}