prestodb/presto · critical · OrcCorruptionException

Number of stripe encryption keys did not match number of enc

Error message

Number of stripe encryption keys did not match number of encryption groups.  Expected %s, but found %s

What it means

Each stripe's key metadata must have exactly one entry per footer encryption group. A mismatch means the stripe cannot be decrypted consistently for all groups, so OrcCorruptionException is thrown with expected vs found counts.

Source

Thrown at presto-orc/src/main/java/com/facebook/presto/orc/OrcReader.java:299

        requireNonNull(stripeMetadataSourceFactory, "stripeMetadataSourceFactory is null");
        this.stripeMetadataSource = requireNonNull(stripeMetadataSourceFactory.create(dwrfStripeCache), "stripeMetadataSource is null");
    }

    @VisibleForTesting
    public static void validateEncryption(Footer footer, OrcDataSourceId dataSourceId)
    {
        if (!footer.getEncryption().isPresent()) {
            return;
        }
        DwrfEncryption dwrfEncryption = footer.getEncryption().get();
        int encryptionGroupSize = dwrfEncryption.getEncryptionGroups().size();
        List<StripeInformation> stripes = footer.getStripes();
        if (!stripes.isEmpty() && encryptionGroupSize > 0 && stripes.get(0).getKeyMetadata().isEmpty()) {
            throw new OrcCorruptionException(dataSourceId, "Stripe encryption keys are missing, but file is encrypted");
        }
        for (StripeInformation stripe : stripes) {
            if (!stripe.getKeyMetadata().isEmpty() && stripe.getKeyMetadata().size() != encryptionGroupSize) {
                throw new OrcCorruptionException(
                        dataSourceId,
                        "Number of stripe encryption keys did not match number of encryption groups.  Expected %s, but found %s",
                        encryptionGroupSize,
                        stripe.getKeyMetadata().size());
            }
        }
    }

    public List<String> getColumnNames()
    {
        return footer.getTypes().get(0).getFieldNames();
    }

    public List<OrcType> getTypes()
    {
        return footer.getTypes();
    }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Regenerate the file with a consistent writer configuration
  2. Match the reader library version to the version that wrote the file
  3. Inspect stripe key metadata counts to identify the corrupt stripes
  4. Re-encrypt/rewrite the file with the correct number of encryption groups
Defensive patterns

Strategy: try-catch

Validate before calling

int groups = encryption.get().getEncryptionGroups().size();
for (StripeInformation s : stripes) {
    if (s.getKeyMetadata().isPresent() && s.getKeyMetadata().get().size() != groups) {
        throw new IllegalStateException("stripe key count mismatch");
    }
}

Try / catch

try { reader = new OrcReader(...); }
catch (OrcCorruptionException e) {
    if (e.getMessage().startsWith("Number of stripe encryption keys")) { /* regenerate file */ }
}

Prevention

When it happens

Trigger: Iterating footer stripes where a stripe has non-empty key metadata whose size differs from dwrfEncryption.getEncryptionGroups().size().

Common situations: Files written by mismatched writer versions (encryption group count changed mid-write), corrupted or hand-edited encrypted files, tooling that rewrote stripes without updating keys.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/e55c563cbf48e097. Report an issue: GitHub.