{"record":{"id":"7d24badde3668d53","repo":"prestodb/presto","slug":"invalid-metadata-length-s","errorCode":null,"errorMessage":"Invalid metadata length %s","messagePattern":"Invalid metadata length (.+?)","errorType":"exception","errorClass":"OrcCorruptionException","httpStatus":null,"severity":"error","filePath":"presto-orc/src/main/java/com/facebook/presto/orc/cache/StorageOrcFileTailSource.java","lineNumber":117,"sourceCode":"        checkOrcVersion(orcDataSource, postScript.getVersion());\n        validateWrite(writeValidation, orcDataSource, validation -> validation.getVersion().equals(postScript.getVersion()), \"Unexpected version\");\n\n        int bufferSize = toIntExact(postScript.getCompressionBlockSize());\n\n        // check compression codec is supported\n        CompressionKind compressionKind = postScript.getCompression();\n        validateWrite(writeValidation, orcDataSource, validation -> validation.getCompression() == compressionKind, \"Unexpected compression\");\n\n        PostScript.HiveWriterVersion hiveWriterVersion = postScript.getHiveWriterVersion();\n\n        int footerSize = toIntExact(postScript.getFooterLength());\n        int metadataSize = toIntExact(postScript.getMetadataLength());\n\n        if (footerSize < 0) {\n            throw new OrcCorruptionException(orcDataSource.getId(), \"Invalid footer length %s\", footerSize);\n        }\n        if (metadataSize < 0) {\n            throw new OrcCorruptionException(orcDataSource.getId(), \"Invalid metadata length %s\", metadataSize);\n        }\n\n        // read DWRF stripe cache only if this feature is enabled and it has meaningful data\n        boolean readDwrfStripeCache = dwrfStripeCacheEnabled\n                && postScript.getDwrfStripeCacheLength().isPresent()\n                && postScript.getDwrfStripeCacheMode().isPresent()\n                && postScript.getDwrfStripeCacheMode().get() != DwrfStripeCacheMode.NONE;\n        int dwrfStripeCacheSize = 0;\n        if (readDwrfStripeCache) {\n            dwrfStripeCacheSize = postScript.getDwrfStripeCacheLength().getAsInt();\n            checkSizes(orcDataSource, metadataSize, dwrfStripeCacheSize);\n        }\n\n        // check if extra bytes need to be read\n        Slice completeFooterSlice;\n        int completeFooterSize = dwrfStripeCacheSize + metadataSize + footerSize + postScriptSize + SIZE_OF_BYTE;\n        if (completeFooterSize > buffer.length) {\n            // allocate a new buffer large enough for the complete footer","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-orc/src/main/java/com/facebook/presto/orc/cache/StorageOrcFileTailSource.java#L99-L135","documentation":"Like the footer check, the PostScript's metadataLength must be non-negative; a negative value is impossible in a valid ORC file. The library throws OrcCorruptionException because the tail bytes cannot represent a real ORC postscript.","triggerScenarios":"getOrcFileTail decodes a PostScript whose getMetadataLength() is negative.","commonSituations":"Corrupted storage blocks, truncated and re-appended files, or reads of files produced by unsupported/buggy writers.","solutions":["Run orc-tools metadata validation on the file to confirm corruption.","Restore the file from a backup or upstream source.","Enable and check HDFS/disk checksums to find the corruption source.","Verify the writing engine version is one supported by this Presto ORC reader."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { tail = source.getOrcFileTail(ds, reader, validation, false, time); }\ncatch (OrcCorruptionException e) { failQueryWithFileLocation(ds.getId(), e); }","preventionTips":["Enable storage checksums","Avoid in-place edits of ORC files","Validate files after write with a metadata read-back"],"tags":["orc","corrupt-file","metadata"],"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"}