iOfficeAI/OfficeCLI · error · CliException

decompression_bomb

decompression_bomb

Error message

Cannot open {Path.GetFileName(filePath)}: package has {archive.Entries.Count} entries (limit {DocumentLimits.MaxZipEntries}); rejected as a potential decompression bomb.

What it means

Thrown by the decompression-bomb guard (GuardDecompressionBomb) when the OOXML zip package contains more than DocumentLimits.MaxZipEntries (100,000) entries. This pre-scan uses ZipFile.OpenRead to read only the central directory — no entry is inflated — so it is cheap and catches crafted archives with millions of tiny entries designed to exhaust memory or processing time before the Open XML SDK touches them.

Source

Thrown at src/officecli/Handlers/DocumentHandlerFactory.cs:182

    /// corrupt_file error for it.
    /// </summary>
    private static void GuardDecompressionBomb(string filePath)
    {
        ZipArchive archive;
        try
        {
            archive = ZipFile.OpenRead(filePath);
        }
        catch (InvalidDataException)
        {
            // Not a valid zip container — let OpenHandler surface corrupt_file.
            return;
        }

        using (archive)
        {
            if (archive.Entries.Count > DocumentLimits.MaxZipEntries)
                throw new CliException(
                    $"Cannot open {Path.GetFileName(filePath)}: package has {archive.Entries.Count} entries " +
                    $"(limit {DocumentLimits.MaxZipEntries}); rejected as a potential decompression bomb.")
                {
                    Code = "decompression_bomb",
                    Suggestion = "Verify the file is a genuine .docx/.xlsx/.pptx and not a crafted archive."
                };

            long totalUncompressed = 0;
            long totalCompressed = 0;
            foreach (var entry in archive.Entries)
            {
                totalUncompressed += entry.Length;
                totalCompressed += entry.CompressedLength;

                if (totalUncompressed > DocumentLimits.MaxUncompressedBytes)
                    throw new CliException(
                        $"Cannot open {Path.GetFileName(filePath)}: uncompressed size exceeds " +
                        $"{DocumentLimits.MaxUncompressedBytes / (1024 * 1024 * 1024)} GiB; " +

View on GitHub (pinned to 1ced45e900)

Solutions

  1. Verify the file is genuine: 'unzip -l <file>' to list entries and confirm the count.
  2. If the file is legitimate but unusually large, review whether the entry count is real or the file is corrupt.
  3. Do not raise the limit — it exists for DoS protection. If you have a genuine use case, file a bug report with the document details.
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check zip entry count before opening
using var archive = System.IO.Compression.ZipFile.OpenRead(filePath);
if (archive.Entries.Count > 100_000)
    throw new InvalidOperationException($"Suspicious entry count: {archive.Entries.Count}");

Try / catch

try
{
    var handler = DocumentHandlerFactory.Open(filePath);
}
catch (CliException ex) when (ex.Code == "decompression_bomb" && ex.Message.Contains("entries"))
{
    // The zip has too many entries — likely adversarial
    logger.LogError("Rejected file with {Count} zip entries (limit 100000).", ex.Message);
    throw;
}

Prevention

When it happens

Trigger: A .docx/.xlsx/.pptx file whose zip central directory lists more than 100,000 entries. Legitimate Office documents rarely exceed a few hundred entries (one per XML part plus embedded media), so this threshold is far above any real document. A crafted file could stuff millions of zero-byte entries to exhaust zip-enumeration time or memory.

Common situations: A malicious or adversarial file crafted specifically to attack zip-processing tools; extremely rarely, a legitimate workbook with an enormous number of embedded objects (images, OLE parts) — but even then, hitting 100,000 entries would be extraordinary.

Related errors


AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13). Data as JSON: /api/errors/7e6b1496ab293630. Report an issue: GitHub.