Skip to content

Incorrect parsing of TarInfo header when GNU long name and type AREGTYPE are combined #141707

Closed

Description

@e-nomem

Bug report

Bug description:

When an entry uses GNU long name encoding the tarfile module reads in the data blocks for the name and then calls self.fromtarfile() again to get the 'actual' header. This second header is the source of truth for everything except the name which is just garbage data.

The problem is that fromtarfile() eventually calls frombuf() where this logic incorrectly uses the garbage data and overrides the entry type to directory, corrupting the entry.

Because the entry is detected as a directory, the offset is not updated properly and the next call to read a TarInfo entry will usually result in an exception. However, the exception lands up in this block where neither of the if conditions are met, so the exception is silently discarded. tarinfo remains None and the code eventually decides that there are no more entries in the tar file.

I initially ran into this issue due to reports of invalid sdists being generated by maturin.
See: PyO3/maturin#2855

CPython versions tested on:

3.9, 3.10, 3.11, 3.12, 3.13, 3.14

Operating systems tested on:

macOS, Linux

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Nov 18, 2025
  2. konstin commented on Dec 11, 2025

    @konstin
    Contributor

    uv is affected by this too: astral-sh/uv#17043

  3. added 2 commits that reference this issue on Dec 24, 2025
  4. added a commit that references this issue on Jan 16, 2026
  5. added a commit that references this issue on Mar 11, 2026
  6. added 4 commits that reference this issue on Mar 11, 2026
  7. 1 remaining item

  8. added 2 commits that reference this issue on Mar 17, 2026
  9. added a commit that references this issue on Apr 25, 2026
  10. added 2 commits that reference this issue on Apr 30, 2026
  11. added a commit that references this issue on May 18, 2026
  12. added 3 commits that reference this issue on Sep 18, 2026
  13. added 3 commits that reference this issue on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errortype-securityA security issue

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions