Skip to content

Unexpected disk preallocation when extracting GNU sparse tar entries #128283

@artahir-dev

Description

@artahir-dev

When extracting GNU sparse tar entries, System.Formats.Tar preallocates using the entry’s logical size rather than the packed data size. That means a small sparse archive can cause a large disk reservation during extraction, which is surprising on small or quota-limited volumes.

I traced this through GnuSparseStream.Length returning the declared real size and TarEntry.CreateFileStreamOptions using that value for PreallocationSize. The extractor then writes the sparse content normally, so the output file is expected, but the preallocation behavior can still create unexpected storage pressure.

Minimal repro:

  1. Create a GNU sparse tar entry with a very small payload and a large declared GNU.sparse.realsize.
  2. Extract it with TarFile.ExtractToDirectory(...) or TarEntry.ExtractToFile(...).
  3. Observe that extraction reserves space based on the expanded size, not the packed archive size.

This seems like a behavior/documentation issue, or possibly something to reconsider for sparse entries, since it can make extraction more expensive than users expect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions