Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
190b3ef
fix(150075): adding tarinfo offset info before and after reading the …
grantlouisherman May 19, 2026
38118de
Merge branch 'main' into fix-150075-tar-addfile-no-offsets
grantlouisherman May 20, 2026
33533a1
Merge branch 'main' into fix-150075-tar-addfile-no-offsets
grantlouisherman May 20, 2026
38e1e9c
Merge branch 'main' into fix-150075-tar-addfile-no-offsets
grantlouisherman May 20, 2026
ee221f2
Merge branch 'main' into fix-150075-tar-addfile-no-offsets
grantlouisherman May 20, 2026
d6bd563
Merge branch 'main' into fix-150075-tar-addfile-no-offsets
grantlouisherman May 20, 2026
2705a52
📜🤖 Added by blurb_it.
blurb-it[bot] May 21, 2026
f8bb5b9
Merge branch 'main' into fix-150075-tar-addfile-no-offsets
grantlouisherman May 21, 2026
6e9dc62
Merge branch 'main' into fix-150075-tar-addfile-no-offsets
grantlouisherman May 21, 2026
1711dd3
Merge branch 'main' into fix-150075-tar-addfile-no-offsets
grantlouisherman May 21, 2026
ac9a33e
Merge branch 'main' into fix-150075-tar-addfile-no-offsets
grantlouisherman May 21, 2026
c29360b
Merge branch 'main' into fix-150075-tar-addfile-no-offsets
grantlouisherman May 21, 2026
f0ede88
Merge branch 'main' into fix-150075-tar-addfile-no-offsets
grantlouisherman May 21, 2026
c6bdfed
Merge branch 'main' into fix-150075-tar-addfile-no-offsets
grantlouisherman May 22, 2026
982749a
gh-149995: Update typing.py docstrings and documentation (#149996)
JelleZijlstra May 22, 2026
6807e9d
gh-133998: Fix gzip file creation when time is out of range (GH-134278)
adang1345 May 22, 2026
41f1cdc
gh-137571: Protect against possible UnboundLocalError in gzip._GzipRe…
serhiy-storchaka May 22, 2026
d692060
gh-149902: Remove dead packaging docs link and add a new section for …
miameows May 22, 2026
808ea13
gh-91372: Add mtime to gzip.open() (GH-32310)
ellaellela May 22, 2026
16d1813
gh-149879: Fix test_c_locale_coercion on Cygwin (#150250)
vstinner May 22, 2026
f26b7bb
Remove 'expat' dependency for Linux in `Misc/Brewfile` (#150118)
brettcannon May 22, 2026
627c8b2
Merge branch 'main' into fix-150075-tar-addfile-no-offsets
grantlouisherman May 22, 2026
b2ec8d1
Merge branch 'main' into fix-150075-tar-addfile-no-offsets
grantlouisherman May 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Lib/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2360,11 +2360,14 @@ def addfile(self, tarinfo, fileobj=None):
raise ValueError("fileobj not provided for non zero-size regular file")

tarinfo = copy.copy(tarinfo)

# get current offset
tarinfo.offset = self.offset
buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
self.fileobj.write(buf)
self.offset += len(buf)
# add original offset to block size
bufsize=self.copybufsize
tarinfo.offset_data = self.offset
# If there's data to follow, append it.
if fileobj is not None:
copyfileobj(fileobj, self.fileobj, tarinfo.size, bufsize=bufsize)
Expand Down
23 changes: 23 additions & 0 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,29 @@ class WriteTest(WriteTestBase, unittest.TestCase):

prefix = "w:"

def test_addfile_sets_offsets(self):
# gh-150075: addfile() must set offset and offset_data on the
# TarInfo stored in the archive so they match a subsequent read.
data = b"data"

with tarfile.open(tmpname, self.mode) as tar:
t1 = tarfile.TarInfo("test1.txt")
t1.size = len(data)
tar.addfile(t1, io.BytesIO(data))

t2 = tarfile.TarInfo("test2.txt")
t2.size = len(data)
tar.addfile(t2, io.BytesIO(data))

write_members = tar.getmembers()

with tarfile.open(tmpname) as tar:
read_members = tar.getmembers()

for w, r in zip(write_members, read_members):
self.assertEqual(w.offset, r.offset)
self.assertEqual(w.offset_data, r.offset_data)

def test_100_char_name(self):
# The name field in a tar header stores strings of at most 100 chars.
# If a string is shorter than 100 chars it has to be padded with '\0',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tar.addfile() doesn't set member offsets in 3.15. From reviewing the file it seemed like the copy was not adding the proper offsets to the tarinfo object. The way I fixed this is that I added the classes current offset of when.addFile is called and then added the block size after .tobuf function was called.
Loading