[3.10] gh-130577: tarfile now validates archives to ensure member offsets are non-negative (GH-137027)#137176
Closed
gpshead wants to merge 1 commit intopython:3.10from
Closed
[3.10] gh-130577: tarfile now validates archives to ensure member offsets are non-negative (GH-137027)#137176gpshead wants to merge 1 commit intopython:3.10from
gpshead wants to merge 1 commit intopython:3.10from
Conversation
…er offsets are non-negative (pythonGH-137027) (cherry picked from commit 7040aa5) Co-authored-by: Alexander Urieles <aeurielesn@users.noreply.github.com> Co-authored-by: Gregory P. Smith <greg@krypto.org>
mgorny
reviewed
Jul 30, 2025
Comment on lines
+4277
to
+4308
| 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') | ||
|
|
||
|
|
Contributor
There was a problem hiding this comment.
This seems to have been mistakenly added in a merge error.
Contributor
There was a problem hiding this comment.
I don't think this can ever work … there is no test.archiver_test module in 3.10. It came with the solution for #114959 which has never been backported to 3.10 or lower.
Contributor
There was a problem hiding this comment.
Sure, but OverwriteTests are not even a part of 7040aa5.
mgorny
reviewed
Aug 7, 2025
Comment on lines
+4277
to
+4308
| 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') | ||
|
|
||
|
|
Contributor
There was a problem hiding this comment.
In case this helps:
Suggested change
| 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') |
Member
|
Alternative backport without the OverwriteTests class: #137644 |
Member
|
The alternative was merged. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
(cherry picked from commit 7040aa5)
tarfile.StreamError: seeking backwards is not alloweddue to unskipped block with bad checksum #130577