prestodb/presto · critical · PrestoException
GENERIC_INTERNAL_ERROR
GENERIC_INTERNAL_ERROR
Error message
Encrypted data size is too small: %s. It must be at least the size of the initialization vector: %s.
What it means
AesSpillCipher.decrypt requires the encrypted buffer to start with an initialization vector of ivBytes length; if the remaining bytes are fewer than ivBytes the input is not a valid ciphertext produced by this cipher. It is surfaced as GENERIC_INTERNAL_ERROR because corrupt spill data is an internal invariant violation, not a user error.
Source
Thrown at presto-main-base/src/main/java/com/facebook/presto/spiller/AesSpillCipher.java:54
// 256-bit AES CTR mode
private static final String CIPHER_NAME = "AES/CTR/NoPadding";
private static final int KEY_BITS = 256;
private SecretKey key;
private final int ivBytes;
AesSpillCipher()
{
this.key = generateNewSecretKey();
this.ivBytes = createEncryptCipher().getIV().length;
}
@Override
public ByteBuffer decrypt(ByteBuffer encryptedData)
{
int length = encryptedData.remaining();
if (length < ivBytes) {
throw new PrestoException(GENERIC_INTERNAL_ERROR, format("Encrypted data size is too small: %s. It must be at least the size of the initialization vector: %s.", length, ivBytes));
}
byte[] iv = new byte[ivBytes];
encryptedData.get(iv);
Cipher cipher = createDecryptCipher(new IvParameterSpec(iv));
ByteBuffer output = ByteBuffer.allocate(cipher.getOutputSize(encryptedData.remaining()));
try {
cipher.doFinal(encryptedData, output);
((Buffer) output).flip();
return output;
}
catch (GeneralSecurityException e) {
throw new PrestoException(GENERIC_INTERNAL_ERROR, "Cannot decrypt previously encrypted data: " + e.getMessage(), e);
}
}
@Override
public byte[] decrypt(byte[] encryptedData)
{View on GitHub (pinned to 55bb57d202)
Solutions
- Verify spill encryption configuration matches between write and read paths (spiller cipher settings unchanged across restarts/versions)
- Delete/recover the corrupted spill files and re-run the query
- Check for disk-full or crash conditions that could truncate spill writes
- Investigate reader code for offsets/alignment bugs that shrink the buffer below ivBytes
Example fix
// before
ByteBuffer decrypted = cipher.decrypt(possiblyTruncatedBuffer);
// after
if (encrypted.remaining() >= IV_LENGTH) {
ByteBuffer decrypted = cipher.decrypt(encrypted);
} else {
throw new IOException("Spill block truncated: " + encrypted.remaining() + " bytes");
} Defensive patterns
Strategy: validation
Validate before calling
if (encryptedData == null || encryptedData.remaining() < IV_LENGTH_BYTES) {
throw new IOException("Spill block too small to contain IV: "
+ (encryptedData == null ? 0 : encryptedData.remaining()) + " bytes");
} Type guard
boolean isPlausibleCiphertext(ByteBuffer buffer) {
return buffer != null && buffer.remaining() >= IV_LENGTH_BYTES;
} Try / catch
try {
ByteBuffer plain = cipher.decrypt(encrypted);
} catch (PrestoException e) {
if (e.getErrorCode().toCode() == GENERIC_INTERNAL_ERROR.toCode()
&& e.getMessage().contains("too small")) {
// treat spill block as corrupt: discard and recompute/re-read source
}
} Prevention
- Never disable spill encryption on some nodes only — keep config uniform across the cluster
- Clean stale spill directories after crash or version upgrades
- Monitor disk usage to avoid truncated writes
- Persist a marker/length header with encrypted blocks so readers can detect truncation
When it happens
Trigger: Calling decrypt(ByteBuffer) with a buffer containing fewer than ivBytes bytes — e.g. a truncated, empty, or plaintext (never-encrypted) spill file being read as encrypted data, or an offset/read bug that misaligns the buffer.
Common situations: Spill files truncated by disk-full or premature cleanup; mismatched spill encryption configuration (data written unencrypted but read with an AesSpillCipher, or vice versa); partially written files after a crash; memory/disk corruption.
Related errors
- HIVE_INVALID_BUCKET_FILES
- spill path %s is not writable; adjust experimental.spiller-s
- OUT_OF_SPILL_SPACE
- could not close some single stream spillers
- could not create spill path %s; adjust experimental.spiller-
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/6b09211d2ee54785.
Report an issue: GitHub.