abpframework/abp · critical · AbpException

The content is too large for the encrypted BLOB format (chun

Error message

The content is too large for the encrypted BLOB format (chunk index overflow)!

What it means

TryCalculateEncryptedLength projects the ciphertext size from the plaintext length. The chunk index (including the terminal record) is a 32-bit value, so if chunkRecordCount - 1 would exceed int.MaxValue the codec throws up front — before writing terabytes of unusable ciphertext — rather than failing mid-stream.

Source

Thrown at framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobEncryptionCodec.cs:650

        // Both are required: without Position the remaining length is unknown (the stream
        // may already be partially consumed), and guessing it would report a wrong
        // ciphertext length and cause a short write on length-strict providers.
        try
        {
            var plainLength = plainStream.Length - plainStream.Position;
            if (plainLength < 0)
            {
                return null;
            }

            var fullChunkCount = plainLength / chunkSize;
            var chunkRecordCount = fullChunkCount + (plainLength % chunkSize > 0 ? 1 : 0) + 1; // +1: terminal record

            // The chunk index (including the terminal record) is a 32-bit value; fail
            // before any output instead of after writing terabytes of ciphertext
            if (chunkRecordCount - 1 > int.MaxValue)
            {
                throw new AbpException("The content is too large for the encrypted BLOB format (chunk index overflow)!");
            }

            checked
            {
                return Magic.Length + 1L + HeaderSize + plainLength +
                       chunkRecordCount * (ChunkLengthPrefixSize + GcmTagSize);
            }
        }
        catch (Exception ex) when (ex is NotSupportedException || ex is IOException)
        {
            // The length is optional; a probe failure must not fail the save
            return null;
        }
        catch (OverflowException)
        {
            return null;
        }
    }

View on GitHub (pinned to 7ed43b1931)

Solutions

  1. Increase the configured chunk size so the content fits within int.MaxValue chunks.
  2. Split the content into multiple BLOBs each under the limit.
  3. Enforce a content-size ceiling at the application layer (chunkSize * int.MaxValue).
  4. Audit and correct chunkSize — it should be multi-MB, not KB.

Example fix

// before
Configure<AbpBlobStoringEncryptionOptions>(o => o.ChunkSize = 16 * 1024);
await blob.SaveAsync("huge", giantStream); // throws [91]

// after
Configure<AbpBlobStoringEncryptionOptions>(o => o.ChunkSize = 8 * 1024 * 1024);
// or split 'giantStream' into multiple blobs below the ceiling
Defensive patterns

Strategy: validation

Validate before calling

// Reject content too large to fit the 32-bit chunk-index space.
static void AssertFitsEncryptedFormat(long contentLength, int chunkSize)
{
    var chunkRecords = contentLength / chunkSize
        + (contentLength % chunkSize > 0 ? 1 : 0) + 1;
    if (chunkRecords - 1 > int.MaxValue)
        throw new InvalidOperationException(
            $"Content ({contentLength} B) exceeds the encrypted format limit for chunkSize={chunkSize}.");
}

Type guard

public sealed record ChunkSize(int Value)
{
    public ChunkSize(int bytes)
    {
        if (bytes is < 1024 or > 64 * 1024 * 1024)
            throw new ArgumentOutOfRangeException(nameof(bytes));
        Value = bytes;
    }
}

Try / catch

try
{
    await blob.SaveAsync(name, bigStream);
}
catch (AbpException ex) when (ex.Message.Contains("chunk index overflow"))
{
    logger.LogError(ex, "Content too large for the encrypted format; raise ChunkSize or split.");
    throw;
}

Prevention

When it happens

Trigger: Saving a stream whose Length/Position imply a plaintext that requires more than int.MaxValue chunk records (content/chunkSize > 2^31) given the configured chunk size.

Common situations: Tiny chunkSize configured against very large content; an accidental huge input stream; misconfigured chunkSize default.

Related errors


AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13). Data as JSON: /api/errors/f880997f142d9fdb. Report an issue: GitHub.