Skip to content

Tar reader checksum checking #117455

Closed

Description

@tmds

I noticed this while working on #117410:

int checksum = (int)TarHelpers.ParseOctal<uint>(spanChecksum);
// Zero checksum means the whole header is empty
if (checksum == 0)
{
return null;
}

There's no reason to treat zero separate from any other checksum value.
I think this code should be removed.

@ericstj @dotnet/area-system-formats-tar wdyt?

Activity

  1. added
    untriaged
    on Jul 9, 2025
  2. added
    needs-area-label
    on Jul 9, 2025
  3. tmds commented on Jul 9, 2025

    @tmds
    MemberAuthor

    Separate issue/question:

    I don't find code that verifies the checksum has the expected value for the header that is read. Is this missing?

  4. changed the title [-]Tar reader doesn't permit a zero checksum[/-] [+]Tar reader checksum checking[/+] on Jul 9, 2025
  5. added and removed
    untriaged
    on Jul 9, 2025
  6. dotnet-policy-service commented on Jul 9, 2025

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-formats-tar
    See info in area-owners.md if you want to be subscribed.

  7. removed
    needs-area-label
    on Jul 9, 2025
  8. ericstj commented on Jul 9, 2025

    @ericstj
    Member

    Seems to me like it's just a fast-path to avoid work when the header is known to be empty. If it's not causing any observable bug then I would leave it.

    Are you thinking of a case where the checksum is 0 and the header is not empty? Could we craft such a case to prove we have a bug?

    (PS: please assign a milestone when removing untriaged - milestone should be where we want to take action. In this case since a bug here would mean data corruption I've assigned 10.0.0)

  9. added this to the 10.0.0 milestone on Jul 9, 2025
  10. tmds commented on Jul 9, 2025

    @tmds
    MemberAuthor

    Seems to me like it's just a fast-path to avoid work when the header is known to be empty.

    It doesn't look like that. On a checksum that has a value zero it returns as if there is no entry to be read.

    I think the expected behavior is to check the checksum is correct and throw InvalidDataException if it isn't.
    Currently, the checksum is never checked.

  11. am11 commented on Jul 10, 2025

    @am11
    Member

    I think the expected behavior is to check the checksum is correct and throw InvalidDataException if it isn't.

    Do other tools (tar(1), 7zip etc.) allow invalid checksum during extraction; warn-and-continue behavior? If so, would be nice to add a bail-out switch for lenient extraction.

  12. tmds commented on Jul 10, 2025

    @tmds
    MemberAuthor

    tar has no options to ignore invalid checksums.

    If the checksum is incorrect, do you want to assume the size is correct to move to the next entry.
    I'm not sure this is a use-case the TarReader should try to support.

  13. tmds commented on Jul 11, 2025

    @tmds
    MemberAuthor

    I won't have time to work on this till mid/end of August. If the issue is still open then, I'll pick it up.

  14. 1 remaining item

  15. self-assigned this
    on Aug 11, 2025
  16. rzikm commented on Aug 11, 2025

    @rzikm
    Member

    I tried to add checksum checking in #118577, but there are failing tests (some tests expect us to pass on invalid checksums). Also, if we go ahead with this, there would be no way to ignore the checksum mismatches, which can potentially break some users. @ericstj do you think we should proceed with the change?

  17. ericstj commented on Aug 11, 2025

    @ericstj
    Member

    I'm reluctant to take any change here unless there is real customer impact. I think @tmds noticed this through code inspection and felt it was necessary follow up from other changes that were made.

    If fixing this introduces new failure points without fixing any customer-impacting bug, then I'd suggest we move it to next release or even wont-fix it. We try to be as compatible as possible with file formats that may have come from many different clients, while still being spec compliant. I'm not hearing a super strong argument for spec compliance here, but if there is one then that could drive a fix-in-net11 vs wont-fix decision.

  18. tmds commented on Aug 11, 2025

    @tmds
    MemberAuthor

    The behavior of GNU tar is to skip to the next entry and try and extract that. The error code of the tar command will be non-zero when there is an incorrect checksum.

    An incorrect checksum indicates a corruption in the tar file.

    Imo checksums should be checked by default.

  19. rzikm commented on Aug 12, 2025

    @rzikm
    Member

    Imo checksums should be checked by default.

    I agree, but I am reluctant to introduce this change this late in .NET 10 cycle. If we want to do it in 10, then I would err on the side of caution and add an app context switch to escape to previous behavior.

    I'm not hearing a super strong argument for spec compliance here, but if there is one then that could drive a fix-in-net11 vs wont-fix decision.

    I agree with moving this to next release for now. And maybe we can figure out some reasonable API change that would allow users ignore checksum failures (at their own peril).

  20. modified the milestones: 10.0.0, 11.0.0 on Aug 12, 2025
  21. rzikm commented on Oct 2, 2025

    @rzikm
    Member

    I did some investigation, I created a tar file and manually corrupted the checksum,

    Implementation Behavior
    GNU tar Skips the entry, extracts the rest, prints warning and exits with an error code.
    BSD tar Repors checksum error, does not extract anything
    Windows Explorer Refuses to open the file ('The archive is invalid')
    Python throws bad checksum error
    Go 'Invalid Tar header' during TarReader.Next, stops processing
    Rust TarError { desc: "failed to iterate over archive", io: Custom { kind: Other, error: "archive header checksum mismatch" } } }

    I am starting to see a pattern here. Given the amount of implementations that enforce checksum matches, I would try to make the change for .NET 11. Since it is early in the release, there is enough time for community to give feedback. Thoughts, @ericstj?

  22. tmds commented on Oct 2, 2025

    @tmds
    MemberAuthor

    GNU tar Skips the entry, extracts the rest, prints warning

    And returns an error code. So a script that checks for failure will stop at this point.

  23. ericstj commented on Oct 6, 2025

    @ericstj
    Member

    Yep, I'm supportive of making this change early in .NET 11 and documenting it as breaking.

  24. added a commit that references this issue on Oct 21, 2025
    a1c4bad
  25. locked and limited conversation to collaborators on Nov 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions