-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
[3.9] gh-130577: tarfile now validates archives to ensure member offsets are non-negative (GH-137027) #137177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gpshead
wants to merge
1
commit into
python:3.9
Choose a base branch
from
gpshead:backport-7040aa5-3.9
base: 3.9
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -48,6 +48,7 @@ def sha256sum(data): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
xzname = os.path.join(TEMPDIR, "testtar.tar.xz") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tmpname = os.path.join(TEMPDIR, "tmp.tar") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dotlessname = os.path.join(TEMPDIR, "testtar") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
SPACE = b" " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sha256_regtype = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"e09e4bc8b3c9d9177e77256353b36c159f5f040531bbd4b024a8f9b9196c71ce" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -4234,6 +4235,193 @@ def valueerror_filter(tarinfo, path): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.expect_exception(TypeError) # errorlevel is not int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class OverwriteTests(archiver_tests.OverwriteTests, unittest.TestCase): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
testdir = os.path.join(TEMPDIR, "testoverwrite") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@classmethod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def setUpClass(cls): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
p = cls.ar_with_file = os.path.join(TEMPDIR, 'tar-with-file.tar') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cls.addClassCleanup(os_helper.unlink, p) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
with tarfile.open(p, 'w') as tar: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
t = tarfile.TarInfo('test') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
t.size = 10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tar.addfile(t, io.BytesIO(b'newcontent')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
p = cls.ar_with_dir = os.path.join(TEMPDIR, 'tar-with-dir.tar') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cls.addClassCleanup(os_helper.unlink, p) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
with tarfile.open(p, 'w') as tar: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tar.addfile(tar.gettarinfo(os.curdir, 'test')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
p = os.path.join(TEMPDIR, 'tar-with-implicit-dir.tar') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cls.ar_with_implicit_dir = p | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
cls.addClassCleanup(os_helper.unlink, p) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
with tarfile.open(p, 'w') as tar: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
t = tarfile.TarInfo('test/file') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
t.size = 10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tar.addfile(t, io.BytesIO(b'newcontent')) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def open(self, path): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return tarfile.open(path, 'r') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def extractall(self, ar): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ar.extractall(self.testdir, filter='fully_trusted') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+4238
to
+4269
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as in the 3.10 backport, this seems to have been mistakenly added as a result of merge error.
Comment on lines
+4238
to
+4269
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case that helps update it:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class OffsetValidationTests(unittest.TestCase): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tarname = tmpname | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
invalid_posix_header = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# name: 100 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tarfile.NUL * tarfile.LENGTH_NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# mode, space, null terminator: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ b"000755" + SPACE + tarfile.NUL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# uid, space, null terminator: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ b"000001" + SPACE + tarfile.NUL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# gid, space, null terminator: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ b"000001" + SPACE + tarfile.NUL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# size, space: 12 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ b"\xff" * 11 + SPACE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# mtime, space: 12 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * 11 + SPACE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# chksum: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ b"0011407" + tarfile.NUL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# type: 1 byte | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.REGTYPE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# linkname: 100 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * tarfile.LENGTH_LINK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# magic: 6 bytes, version: 2 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.POSIX_MAGIC | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# uname: 32 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * 32 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# gname: 32 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * 32 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# devmajor, space, null terminator: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * 6 + SPACE + tarfile.NUL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# devminor, space, null terminator: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * 6 + SPACE + tarfile.NUL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# prefix: 155 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * tarfile.LENGTH_PREFIX | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# padding: 12 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * 12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
invalid_gnu_header = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# name: 100 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tarfile.NUL * tarfile.LENGTH_NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# mode, null terminator: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ b"0000755" + tarfile.NUL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# uid, null terminator: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ b"0000001" + tarfile.NUL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# gid, space, null terminator: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ b"0000001" + tarfile.NUL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# size, space: 12 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ b"\xff" * 11 + SPACE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# mtime, space: 12 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * 11 + SPACE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# chksum: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ b"0011327" + tarfile.NUL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# type: 1 byte | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.REGTYPE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# linkname: 100 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * tarfile.LENGTH_LINK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# magic: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.GNU_MAGIC | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# uname: 32 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * 32 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# gname: 32 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * 32 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# devmajor, null terminator: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# devminor, null terminator: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# padding: 167 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * 167 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
invalid_v7_header = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# name: 100 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tarfile.NUL * tarfile.LENGTH_NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# mode, space, null terminator: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ b"000755" + SPACE + tarfile.NUL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# uid, space, null terminator: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ b"000001" + SPACE + tarfile.NUL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# gid, space, null terminator: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ b"000001" + SPACE + tarfile.NUL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# size, space: 12 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ b"\xff" * 11 + SPACE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# mtime, space: 12 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * 11 + SPACE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# chksum: 8 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ b"0010070" + tarfile.NUL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# type: 1 byte | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.REGTYPE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# linkname: 100 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * tarfile.LENGTH_LINK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# padding: 255 bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+ tarfile.NUL * 255 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
valid_gnu_header = tarfile.TarInfo("filename").tobuf(tarfile.GNU_FORMAT) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
data_block = b"\xff" * tarfile.BLOCKSIZE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def _write_buffer(self, buffer): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
with open(self.tarname, "wb") as f: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
f.write(buffer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def _get_members(self, ignore_zeros=None): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
with open(self.tarname, "rb") as f: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
with tarfile.open( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mode="r", fileobj=f, ignore_zeros=ignore_zeros | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) as tar: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return tar.getmembers() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def _assert_raises_read_error_exception(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
with self.assertRaisesRegex( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
tarfile.ReadError, "file could not be opened successfully" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self._get_members() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_invalid_offset_header_validations(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for tar_format, invalid_header in ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
("posix", self.invalid_posix_header), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
("gnu", self.invalid_gnu_header), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
("v7", self.invalid_v7_header), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
with self.subTest(format=tar_format): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self._write_buffer(invalid_header) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self._assert_raises_read_error_exception() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_early_stop_at_invalid_offset_header(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
buffer = self.valid_gnu_header + self.invalid_gnu_header + self.valid_gnu_header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self._write_buffer(buffer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
members = self._get_members() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.assertEqual(len(members), 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.assertEqual(members[0].name, "filename") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.assertEqual(members[0].offset, 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_ignore_invalid_archive(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# 3 invalid headers with their respective data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
buffer = (self.invalid_gnu_header + self.data_block) * 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self._write_buffer(buffer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
members = self._get_members(ignore_zeros=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.assertEqual(len(members), 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def test_ignore_invalid_offset_headers(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for first_block, second_block, expected_offset in ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(self.valid_gnu_header), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(self.invalid_gnu_header + self.data_block), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(self.invalid_gnu_header + self.data_block), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(self.valid_gnu_header), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1024, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self._write_buffer(first_block + second_block) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
members = self._get_members(ignore_zeros=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.assertEqual(len(members), 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.assertEqual(members[0].name, "filename") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
self.assertEqual(members[0].offset, expected_offset) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def setUpModule(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
support.unlink(TEMPDIR) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
os.makedirs(TEMPDIR) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Library/2025-07-23-00-35-29.gh-issue-130577.c7EITy.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
:mod:`tarfile` now validates archives to ensure member offsets are | ||
non-negative. (Contributed by Alexander Enrique Urieles Nieto in | ||
:gh:`130577`.) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
archiver_tests
are not imported and do not exist in 3.9 sources.