{"record":{"id":"e55c563cbf48e097","repo":"prestodb/presto","slug":"number-of-stripe-encryption-keys-did-not-match-num","errorCode":null,"errorMessage":"Number of stripe encryption keys did not match number of encryption groups.  Expected %s, but found %s","messagePattern":"Number of stripe encryption keys did not match number of encryption groups\\.  Expected (.+?), but found (.+?)","errorType":"exception","errorClass":"OrcCorruptionException","httpStatus":null,"severity":"critical","filePath":"presto-orc/src/main/java/com/facebook/presto/orc/OrcReader.java","lineNumber":299,"sourceCode":"        requireNonNull(stripeMetadataSourceFactory, \"stripeMetadataSourceFactory is null\");\n        this.stripeMetadataSource = requireNonNull(stripeMetadataSourceFactory.create(dwrfStripeCache), \"stripeMetadataSource is null\");\n    }\n\n    @VisibleForTesting\n    public static void validateEncryption(Footer footer, OrcDataSourceId dataSourceId)\n    {\n        if (!footer.getEncryption().isPresent()) {\n            return;\n        }\n        DwrfEncryption dwrfEncryption = footer.getEncryption().get();\n        int encryptionGroupSize = dwrfEncryption.getEncryptionGroups().size();\n        List<StripeInformation> stripes = footer.getStripes();\n        if (!stripes.isEmpty() && encryptionGroupSize > 0 && stripes.get(0).getKeyMetadata().isEmpty()) {\n            throw new OrcCorruptionException(dataSourceId, \"Stripe encryption keys are missing, but file is encrypted\");\n        }\n        for (StripeInformation stripe : stripes) {\n            if (!stripe.getKeyMetadata().isEmpty() && stripe.getKeyMetadata().size() != encryptionGroupSize) {\n                throw new OrcCorruptionException(\n                        dataSourceId,\n                        \"Number of stripe encryption keys did not match number of encryption groups.  Expected %s, but found %s\",\n                        encryptionGroupSize,\n                        stripe.getKeyMetadata().size());\n            }\n        }\n    }\n\n    public List<String> getColumnNames()\n    {\n        return footer.getTypes().get(0).getFieldNames();\n    }\n\n    public List<OrcType> getTypes()\n    {\n        return footer.getTypes();\n    }\n","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-orc/src/main/java/com/facebook/presto/orc/OrcReader.java#L281-L317","documentation":"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.","triggerScenarios":"Iterating footer stripes where a stripe has non-empty key metadata whose size differs from dwrfEncryption.getEncryptionGroups().size().","commonSituations":"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.","solutions":["Regenerate the file with a consistent writer configuration","Match the reader library version to the version that wrote the file","Inspect stripe key metadata counts to identify the corrupt stripes","Re-encrypt/rewrite the file with the correct number of encryption groups"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"int groups = encryption.get().getEncryptionGroups().size();\nfor (StripeInformation s : stripes) {\n    if (s.getKeyMetadata().isPresent() && s.getKeyMetadata().get().size() != groups) {\n        throw new IllegalStateException(\"stripe key count mismatch\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try { reader = new OrcReader(...); }\ncatch (OrcCorruptionException e) {\n    if (e.getMessage().startsWith(\"Number of stripe encryption keys\")) { /* regenerate file */ }\n}","preventionTips":["Write encrypted files with a fixed, tested number of encryption groups","Never hand-edit encrypted ORC footers","Validate written files with validateWrite"],"tags":["orc","dwrf","encryption","key-metadata","corruption"],"backgroundTag":"missing-encryption-key","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"}