Skip to content
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

bpo-39017 Fix infinite loop in the tarfile module #21454

Merged
merged 4 commits into from Jul 15, 2020

Conversation

rishi93
Copy link
Contributor

@rishi93 rishi93 commented Jul 12, 2020

Add a check for length = 0 in the _proc_pax function to avoid running into an infinite loop

https://bugs.python.org/issue39017

Add a check for length = 0 in the _proc_pax function to avoid running into an infinite loop
Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you note the CVE number that got assigned to this flaw?

Lib/test/test_tarfile.py Outdated Show resolved Hide resolved
def test_length_zero_header(self):
with self.assertRaisesRegex(tarfile.ReadError, "file could not be opened successfully"):
with tarfile.open(support.findfile('recursion.tar')) as tar:
tar.getmembers()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this tar.getmembers() can be replaced with pass since it should never be called. Or you can call tarfile.is_tarfile instead of with tarfile.open.... Feel free to ignore this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the comment, I replaced the tar.getmembers() with pass as you suggested

rishi93 and others added 2 commits July 14, 2020 12:39
Add relevant CVE number in inline comments

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Replace code that is never called with pass in tarfile testcase
@encukou encukou merged commit 5a8d121 into python:master Jul 15, 2020
@miss-islington
Copy link
Contributor

Thanks @rishi93 for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7, 3.8, 3.9.
🐍🍒⛏🤖

@encukou
Copy link
Member

encukou commented Jul 15, 2020

Thank you!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 15, 2020
Avoid infinite loop when reading specially crafted TAR files using the tarfile module
(CVE-2019-20907).
(cherry picked from commit 5a8d121)

Co-authored-by: Rishi <rishi_devan@mail.com>
@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Jul 15, 2020
@bedevere-bot
Copy link

GH-21482 is a backport of this pull request to the 3.9 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 15, 2020
Avoid infinite loop when reading specially crafted TAR files using the tarfile module
(CVE-2019-20907).
(cherry picked from commit 5a8d121)

Co-authored-by: Rishi <rishi_devan@mail.com>
@bedevere-bot
Copy link

GH-21483 is a backport of this pull request to the 3.8 branch.

@bedevere-bot
Copy link

GH-21484 is a backport of this pull request to the 3.7 branch.

@bedevere-bot
Copy link

GH-21485 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 15, 2020
Avoid infinite loop when reading specially crafted TAR files using the tarfile module
(CVE-2019-20907).
(cherry picked from commit 5a8d121)

Co-authored-by: Rishi <rishi_devan@mail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 15, 2020
Avoid infinite loop when reading specially crafted TAR files using the tarfile module
(CVE-2019-20907).
(cherry picked from commit 5a8d121)

Co-authored-by: Rishi <rishi_devan@mail.com>
@rishi93
Copy link
Contributor Author

rishi93 commented Jul 15, 2020

Thank you everyone, for this opportunity

miss-islington added a commit that referenced this pull request Jul 15, 2020
…GH-21482)

Avoid infinite loop when reading specially crafted TAR files using the tarfile module
(CVE-2019-20907).
(cherry picked from commit 5a8d121)


Co-authored-by: Rishi <rishi_devan@mail.com>

Automerge-Triggered-By: @encukou
miss-islington added a commit that referenced this pull request Jul 15, 2020
…GH-21483)

Avoid infinite loop when reading specially crafted TAR files using the tarfile module
(CVE-2019-20907).
(cherry picked from commit 5a8d121)


Co-authored-by: Rishi <rishi_devan@mail.com>

Automerge-Triggered-By: @encukou
ned-deily pushed a commit that referenced this pull request Jul 15, 2020
…1484)

Avoid infinite loop when reading specially crafted TAR files using the tarfile module
(CVE-2019-20907).
(cherry picked from commit 5a8d121)

Co-authored-by: Rishi <rishi_devan@mail.com>
ned-deily pushed a commit that referenced this pull request Jul 15, 2020
Avoid infinite loop when reading specially crafted TAR files using the tarfile module
(CVE-2019-20907).
(cherry picked from commit 5a8d121)

Co-authored-by: Rishi <rishi_devan@mail.com>
@rishi93 rishi93 deleted the fix-issue-39017 branch July 15, 2020 12:59
encukou pushed a commit that referenced this pull request Jul 15, 2020
Avoid infinite loop when reading specially crafted TAR files using the tarfile module
(CVE-2019-20907).
(cherry picked from commit 5a8d121)

Co-authored-by: Rishi <rishi_devan@mail.com>
larryhastings pushed a commit that referenced this pull request Jul 16, 2020
…#21489)

Avoid infinite loop when reading specially crafted TAR files using the tarfile module
(CVE-2019-20907).
(cherry picked from commit 5a8d121)

Co-authored-by: Rishi <rishi_devan@mail.com>
arun-mani-j pushed a commit to arun-mani-j/cpython that referenced this pull request Jul 21, 2020
Avoid infinite loop when reading specially crafted TAR files using the tarfile module
(CVE-2019-20907).
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Aug 4, 2020
Avoid infinite loop when reading specially crafted TAR files using the tarfile module
(CVE-2019-20907).
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Aug 20, 2020
Avoid infinite loop when reading specially crafted TAR files using the tarfile module
(CVE-2019-20907).
xzy3 pushed a commit to xzy3/cpython that referenced this pull request Oct 18, 2020
Avoid infinite loop when reading specially crafted TAR files using the tarfile module
(CVE-2019-20907).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants