Skip to content

Add extraction disk-space preflight and high-expansion safeguards #7

Description

@tuki0918

Summary

BundlePack currently allows packages with up to 20 GiB of expanded data, while the compression-ratio guard only rejects archives larger than 1 GiB whose integer ratio exceeds 1,000. A structurally valid package can therefore consume most or all of a system volume during extraction.

On macOS, the current flow validates and expands into a temporary directory and then copies the payload to the final destination, so peak disk usage can approach twice the expanded size.

Impact

Opening and extracting an attacker-controlled but structurally valid package can exhaust the system or destination volume and disrupt BundlePack or other processes.

Evidence

  • Windows/BundlePack.Core/BundlePackConstants.cs:20-23
  • Windows/BundlePack.Core/BundlePackArchive.Validation.cs:236-241
  • macOS/BundlePack/Shared/ZipArchiveInspector.Validation.swift:219-225
  • macOS/BundlePack/App/PackageBuilder.swift:221-299

Reproduction outline

Create a valid archive whose expanded total is below 20 GiB and whose overall compression ratio is at most 1,000. A mix of highly compressible zero-filled files and a small amount of incompressible data can satisfy the current checks while causing large writes.

The audit did not generate the full-size fixture; the pass conditions are confirmed from the validation code.

Proposed change

  • Preflight available capacity before extraction.
  • Check temporary and destination volumes independently on macOS.
  • Include a safety margin and currently existing files in the budget.
  • Require explicit caller confirmation above a documented high-expansion threshold.
  • Add practical per-entry and total compression-ratio policy without silently changing the v1 numeric field layout.

Acceptance criteria

  • Extraction fails before writing payload bytes when capacity is insufficient.
  • Capacity checks are injectable and testable without allocating multi-GiB fixtures.
  • Boundary tests cover exact limit, limit minus one, and limit plus one.
  • Cancellation and failure leave no published partial destination.
  • Docs/FORMAT.md documents any reader policy limit changed by the fix.

Compatibility constraints

Do not silently change the v1 20 GiB field representation, ZIP32 layout, CRC and actual-size validation, or the requirement to extract only the reviewed archive bytes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions