prestodb/presto · error · OrcCorruptionException
Invalid metadata length %s
Error message
Invalid metadata length %s
What it means
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.
Source
Thrown at presto-orc/src/main/java/com/facebook/presto/orc/cache/StorageOrcFileTailSource.java:117
checkOrcVersion(orcDataSource, postScript.getVersion());
validateWrite(writeValidation, orcDataSource, validation -> validation.getVersion().equals(postScript.getVersion()), "Unexpected version");
int bufferSize = toIntExact(postScript.getCompressionBlockSize());
// check compression codec is supported
CompressionKind compressionKind = postScript.getCompression();
validateWrite(writeValidation, orcDataSource, validation -> validation.getCompression() == compressionKind, "Unexpected compression");
PostScript.HiveWriterVersion hiveWriterVersion = postScript.getHiveWriterVersion();
int footerSize = toIntExact(postScript.getFooterLength());
int metadataSize = toIntExact(postScript.getMetadataLength());
if (footerSize < 0) {
throw new OrcCorruptionException(orcDataSource.getId(), "Invalid footer length %s", footerSize);
}
if (metadataSize < 0) {
throw new OrcCorruptionException(orcDataSource.getId(), "Invalid metadata length %s", metadataSize);
}
// read DWRF stripe cache only if this feature is enabled and it has meaningful data
boolean readDwrfStripeCache = dwrfStripeCacheEnabled
&& postScript.getDwrfStripeCacheLength().isPresent()
&& postScript.getDwrfStripeCacheMode().isPresent()
&& postScript.getDwrfStripeCacheMode().get() != DwrfStripeCacheMode.NONE;
int dwrfStripeCacheSize = 0;
if (readDwrfStripeCache) {
dwrfStripeCacheSize = postScript.getDwrfStripeCacheLength().getAsInt();
checkSizes(orcDataSource, metadataSize, dwrfStripeCacheSize);
}
// check if extra bytes need to be read
Slice completeFooterSlice;
int completeFooterSize = dwrfStripeCacheSize + metadataSize + footerSize + postScriptSize + SIZE_OF_BYTE;
if (completeFooterSize > buffer.length) {
// allocate a new buffer large enough for the complete footerView on GitHub (pinned to 55bb57d202)
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.
Defensive patterns
Strategy: try-catch
Try / catch
try { tail = source.getOrcFileTail(ds, reader, validation, false, time); }
catch (OrcCorruptionException e) { failQueryWithFileLocation(ds.getId(), e); } Prevention
- Enable storage checksums
- Avoid in-place edits of ORC files
- Validate files after write with a metadata read-back
When it happens
Trigger: getOrcFileTail decodes a PostScript whose getMetadataLength() is negative.
Common situations: Corrupted storage blocks, truncated and re-appended files, or reads of files produced by unsupported/buggy writers.
Related errors
- HIVE_INVALID_METADATA
- Invalid file size %s
- Invalid postscript length %s
- Invalid footer length %s
- Invalid ORC metadata %s or DWRF stripe cache size %s
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/7d24badde3668d53.
Report an issue: GitHub.