Skip to content

tarfile: addfile() doesn't set member offsetsΒ #150075

Closed

Description

@spbnick

Bug report

Bug description:

It appears that tarfile.TarFile.addfile() sets neither offset nor offset_data attributes in the TarInfo added to self.members, when it's done adding the file. Members in a reopened TAR have correct values.

Reproducer

from io import BytesIO
from tarfile import TarFile, TarInfo

with TarFile("test.tar", "w") as tar:
    data = b"data"

    tarinfo = TarInfo("test1.txt")
    tarinfo.size = len(data)
    tar.addfile(tarinfo, BytesIO(data))

    tarinfo = TarInfo("test2.txt")
    tarinfo.size = len(data)
    tar.addfile(tarinfo, BytesIO(data))

    for member in tar.getmembers():
        print(member.name, member.offset, member.offset_data)

with TarFile("test.tar", "r") as tar:
    for member in tar.getmembers():
        print(member.name, member.offset, member.offset_data)

Expected output

test1.txt 0 512
test2.txt 1024 1536
test1.txt 0 512
test2.txt 1024 1536

Actual output

test1.txt 0 0
test2.txt 0 0
test1.txt 0 512
test2.txt 1024 1536

CPython versions tested on:

3.15

Operating systems tested on:

Linux

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on May 19, 2026
  2. changed the title [-]tarfile: addfile() doesn't set member offset_data[/-] [+]tarfile: addfile() doesn't set member offsets[/+] on May 19, 2026
  3. grantlouisherman commented on May 19, 2026

    @grantlouisherman
    Contributor

    @spbnick @aisk is it possible for me take a look?

  4. spbnick commented on May 19, 2026

    @spbnick
    Author

    @grantlouisherman, I'm not sure anyone can stop you 😁 πŸ‘

  5. grantlouisherman commented on May 19, 2026

    @grantlouisherman
    Contributor

    This is true but people can be faster @spbnick

  6. ankhikarmakar commented on May 19, 2026

    @ankhikarmakar
    Contributor

    I'd like to take this β€” picked from where I left off in #150019

  7. grantlouisherman commented on May 19, 2026

    @grantlouisherman
    Contributor

    @ankhikarmakar im already starting to look at it if that’s alright

  8. added a commit that references this issue on Oct 21, 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 error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions