1. Peel
  2. The Pith
  3. Small files, big problems
Essay · Security

Small Files, Big Problems

Opening an archive is a security boundary.

By · · Updated · The Pith, no. 7 · 9 min read

A small orange matchbox casting an impossibly large shadow of tangled cables

There is something deceptively reassuring about a small file. A few kilobytes arriving in an inbox hardly seem capable of consuming the resources of an entire computer. We see a ZIP icon, double-click it, and expect a folder to appear.

But the size of an archive tells us how much information is stored in its current representation. It doesn’t establish how much work will be required to interpret that representation, how much storage will be needed to materialize it, or what the resulting filesystem operations will do.

An archive is not simply a collection of compressed bytes. It is a collection of claims. It describes files, names, lengths, relationships and, in some formats, instructions for reconstructing information. An archive reader must decide which of those claims it can accept.

That decision is one of the more interesting responsibilities of an archive engine. The moment we open a file supplied by someone else, we begin interpreting information outside our control. The moment we extract it, we may begin changing the state of the machine.

The size of the file is not the size of the operation

In The Impossible Compressor, we examined why structured information can be represented using considerably fewer bytes. The same property creates a resource-management problem. A decoder can reconstruct much more information than it receives.

That is normal behavior, not evidence of an attack. A repetitive scientific dataset, a disk image containing large empty regions, or an ordinary log archive can all compress remarkably well. A reader that rejects every high-ratio stream will also reject legitimate work.

The relevant question is whether the operation can remain within the resources the application has authorized. We need limits on actual decoded bytes, not just on the size declared in an archive header. We also need to consider entry count, memory consumption, elapsed time, temporary storage and the cumulative cost of nested operations (Figure 1).

Fig. 01 / Interactive

What has the application authorized?

Figure 1. A conceptual policy simulation, not an archive generator or a measured decoder. A real implementation must enforce the limit before it commits excess bytes.

Metadata is a claim, not a guarantee

Archive formats contain lengths and offsets because readers need to locate information efficiently. A directory record may tell us where an entry begins, how large its compressed representation is, and how much information should emerge from decoding.

Those fields are useful, but they are not inherently trustworthy. A parser needs to establish that an offset lies within the available input, that a length is representable by its arithmetic, and that the referenced region is consistent with the format. A successful conversion from a field to an integer does not establish that allocating that many bytes is appropriate.

Checked arithmetic is especially important here. An expression that adds an offset and a length may exceed the range of its integer type. The correct behavior is to reject an unrepresentable calculation rather than allow the result to wrap and use it as a new location.

There is also a distinction between structural validity and resource acceptability. An archive can be perfectly valid according to its format specification and still exceed the resources available to a particular application. A well-designed reader should be able to communicate that distinction. The file isn’t necessarily corrupt; the operation has exceeded a policy.

Extraction changes the filesystem

Reading a file and writing a file are different capabilities. An archive may contain a hierarchy of names, but that hierarchy is not permission to modify arbitrary locations on the machine.

When a user chooses a destination, the engine needs to preserve that boundary throughout the operation. Validating a name as a string is only part of the problem. Filesystem resolution can involve symbolic links, existing objects, platform-specific path semantics and changes that occur between a check and a subsequent operation.

Containment therefore needs to be enforced where filesystem operations occur, using platform-appropriate primitives and a well-defined policy for links and existing files. An engine should avoid relying exclusively on a preliminary string check or on a single canonicalization performed before extraction begins.

There are also decisions that aren’t strictly about escaping a directory. What happens when two entries resolve to the same destination? What if a file already exists? What if the destination filesystem treats names as equivalent that the archive format treats as distinct? These are product decisions as much as security decisions, and the safest default may be to stop and ask rather than silently overwrite information (Figure 2).

Fig. 02 / Interactive

Is this write authorized?

Figure 2. An illustrative fail-closed policy. A real reader must enforce these decisions at the filesystem operation itself; this isn’t a path sanitizer.

When one budget becomes many

Suppose we’re browsing an archive containing another archive. From a user’s perspective, it is natural to open the second object and inspect it. From an engine’s perspective, we’ve started another decoding and parsing operation within the first.

It is tempting to give every operation an independent resource allowance. But if the operations are part of one user request, those allowances need to be coordinated. Otherwise, the application has no meaningful limit on the work it performs as a whole.

I’d distinguish between the resources currently held and the work already performed. Memory can be released when a decoder closes. Temporary files can be removed. But elapsed computation and bytes processed are cumulative costs of the request. A parent operation should retain an accounting of those costs even after a child operation has completed (Figure 3).

Fig. 03 / Interactive

One request, several operations.

Each operation asks for 12 units of an abstract work budget. The whole request has 48 units.

    Figure 3. Illustrative resource accounting. The units are arbitrary and don’t correspond to a real archive, CPU time or byte count.

    Correct data is not necessarily trusted data

    Checksums are an important part of archive integrity. A CRC can detect many forms of accidental corruption, and a reader should validate it where the format provides one. But a checksum does not establish the identity of the person who produced the file.

    Cryptographic authentication provides a different guarantee, under different assumptions. A message authentication code requires a suitable secret key. A digital signature requires a trusted verification key and a policy establishing whose signatures are acceptable. Encryption alone does not necessarily provide authentication; authenticated encryption is designed to provide both confidentiality and integrity under its specified conditions.

    Even an authenticated archive still needs resource limits and safe extraction. Knowing who produced information does not establish that it is appropriate to write a particular file or allocate a particular amount of memory. An authorized sender can make a mistake. A trusted system can be compromised. A valid signature does not change the semantics of the archive (Figure 4).

    Fig. 04 / Interactive

    What does verification establish?

    Checks that pass

    Figure 4. Conceptual distinctions, not a cryptographic implementation. Formats without authentication need an explicit trust policy.

    Failure is part of the interface

    What should happen when an archive exceeds its output budget halfway through an extraction? Simply returning an error is not enough to describe the state of the operation. We need to know whether any files have been committed, whether temporary output remains, and whether an existing file has been modified.

    One possible architecture is to stage output, validate it, and commit it only when the necessary checks succeed. That can provide a useful per-file boundary. It does not automatically provide atomicity across an entire collection of files, particularly when a destination already contains data or spans different filesystems. The scope of the guarantee needs to be explicit.

    Cancellation deserves the same consideration. A user who stops an extraction should not be left guessing which results are complete and which are partial. Resource-limit errors, integrity failures, unsupported methods and permission failures should be distinguishable. If recovery is offered, recovered information should be labeled according to the evidence supporting its validity.

    These are not incidental implementation details. They define the contract between the archive engine and the application that depends on it (Figure 5).

    Fig. 05

    Trust is established in stages.

    1. Untrusted archive input
    2. Bounded parsingChecked lengths and offsets
    3. Policy evaluationDestination · resource limits
    4. Bounded decodingStaged output · integrity validation
    5. Contained commitExplicit overwrite policy
    6. ResultVerified files · failures · cleanup status
    Figure 5. A proposed architecture, not a verified description of the current Rind implementation. Failure or cancellation at any stage needs defined cleanup and reporting.

    How I would test this

    We don’t need dangerous archives to establish whether basic defensive policies work. We can deliberately configure very small resource budgets and use ordinary synthetic data to exercise the same boundaries. A test that allows only 64 bytes of decoded output can establish whether a reader stops before exceeding the allowance without creating a large file.

    We can test parser behavior with truncated benign records, test arithmetic helpers at their numerical boundaries, and test destination policy using abstract filesystem states or isolated temporary directories. The important part is to assert the state of the system after the operation, not merely check whether a function returned an error.

    Test Required observation
    Ordinary input exceeds a tiny output budget No excess output committed; explicit limit status
    Truncated benign record Controlled rejection; no out-of-bounds access
    Unrepresentable offset calculation Arithmetic failure handled before accessing input
    Unverified destination in policy mock No write authorized
    Cancellation during staged output Defined cleanup and reported committed state
    Checksum mismatch Output not represented as verified

    Fuzzing can complement these tests by exploring combinations that we did not anticipate. It should be run in an isolated environment with strict time, memory and output budgets. Findings need reproducible fixtures and regression tests. An absence of failures in a test campaign is evidence about the tested conditions, not a proof that the parser is secure.

    The following small example exercises the accounting rule itself. It deliberately avoids archive decoding and filesystem writes. This is a proposed unit-test pattern, not an implementation of a secure archive extractor.

    def admit_chunk(used, incoming, limit):
                  if not 0 <= used <= limit or incoming < 0:
                      raise ValueError("invalid accounting state")
                  if incoming > limit - used:
                      raise ValueError("output budget exceeded")
                  return used + incoming
              
              assert admit_chunk(48, 16, 64) == 64
              try:
                  admit_chunk(48, 17, 64)
              except ValueError:
                  pass
              else:
                  raise AssertionError("budget not enforced")

    In a real streaming implementation, the decoder must also be constrained before it allocates or produces excessive output. Checking a large buffer only after it has been created is too late to protect memory. The accounting rule is one component of a broader enforcement mechanism.

    Security is not another performance metric

    Throughout this series, we’ve been considering how to evaluate compression technology. We’ve looked at scoring formulas, information-theoretic limits, experimental bias and optimization frontiers. Security introduces a slightly different kind of requirement.

    If two implementations provide equivalent guarantees, it is reasonable to compare their throughput, memory consumption and latency. It is not reasonable to treat an implementation’s ability to write outside an authorized destination as a small penalty that can be offset by higher compression speed.

    Correctness and containment are qualification gates. The performance comparison begins after those requirements have been satisfied under the specified workload. We can then measure the costs of validation, staging, integrity checks and other necessary operations as part of complete application performance.

    For Peel and Rind, this is an opportunity to think about the archive experience in terms of explicit capabilities. Browsing, previewing, decoding and writing are different operations. They should not automatically inherit the same authority simply because they concern the same file. A preview may need no permanent filesystem changes at all; an extraction requires a destination and a defined policy.

    The smaller the operation we authorize, the less unnecessary work the engine needs to perform and the fewer effects it needs to manage. That is a useful intersection between performance, interaction design and security.

    The shadow of a small file

    The matchbox on the cover occupies very little space. Its shadow is much larger and more complicated. An archive can behave similarly: the stored representation is compact, while the operation it describes can have consequences far beyond its apparent size.

    What matters is not whether we can open every archive. It is whether we can establish what opening one will do, constrain that work, and communicate what happened when the operation couldn’t be completed.

    A useful archive engine doesn’t just reconstruct information. It establishes the boundaries within which that reconstruction is allowed to occur.

    References and further reading

    Research disclosure: figures are conceptual policy models; no empirical security or performance claims are made about Peel, Rind or competing software. Proposed integration tests have not been executed. The article expands the supplied draft with general defensive engineering principles.

    Read next · No. 06 · SecurityWhat Happens When a Single Bit Goes Wrong?Hostile input is one way an archive goes wrong. Plain damage is the other, measured one flipped bit at a time.
    Peel's icon: an orange on a cream tile

    Get Peel. Free forever.

    No account, no ads, no trial. Everything Peel does today stays free, and it keeps itself up to date.

    Download Peel 1.4.0 brew install --cask snackstudio/tap/peel
    Requirements
    macOS 13 Ventura or later, on Apple silicon or Intel.
    Install
    Open the installer and follow it. Or open the disk image and drag Peel to Applications, or run brew install --cask snackstudio/tap/peel in Terminal.
    Updates
    Peel updates itself, and every update is signed. To check now, choose Peel ▸ Check for Updates…
    Uninstall
    Drag Peel to the Trash, or run brew uninstall --cask peel.
    Price
    Free. No account, no ads, no trial.
    Privacy
    Your files never leave your Mac, and the app has no analytics. This site counts visits to learn what helps; the privacy policy says how.