Skip to content

Tar: string fields are truncated when they don't fit but we should throw instead #75921

@jozkee

Description

@jozkee

This table shows each field max allowed length, in bytes, according to which format you choose:

  V7 Ustar Gnu Pax
Name 100 256 Unlimited Unlimited
LinkName 100 100 Unlimited Unlimited
UserName N/A 32 32 Unlimited
GroupName N/A 32 32 Unlimited

Our current behavior using TarWriter.WriteEntry is to truncate fields when a string larger-than-the-limit is passed, but I think this is wrong since users may not be aware of such behavior.
I think we should instead throw when a field is unable to fit in the archive entry and there's no other way to preserve it.

That last bit is only true for a subset of the table, i.e:

  • Name and LinkName on V7 and Ustar.
  • UserName and GroupName on Ustar and Gnu.

For Name and LinkName on Pax and Gnu is acceptable to truncate as those formats are capable of storing those fields without limit restriction (although, they still populate the legacy fields).

I also checked how GNU Tar handles these cases and it aligns with what I just described.

cc @carlossanlop

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions