From 5e81a454fd4485cb165398b820fcc492e581ec4e Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Mon, 11 Dec 2023 15:52:01 +0100 Subject: [PATCH] gh-112998: zipfile: fix extractall makedirs race condition --- Lib/zipfile/__init__.py | 7 +++++-- .../Library/2023-12-12-10-25-46.gh-issue-112998.F2QyD0.rst | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2023-12-12-10-25-46.gh-issue-112998.F2QyD0.rst diff --git a/Lib/zipfile/__init__.py b/Lib/zipfile/__init__.py index fe629ed1cf2fc5..ffbdc90b0ef000 100644 --- a/Lib/zipfile/__init__.py +++ b/Lib/zipfile/__init__.py @@ -1781,11 +1781,14 @@ def _extract_member(self, member, targetpath, pwd): # Create all upper directories if necessary. upperdirs = os.path.dirname(targetpath) if upperdirs and not os.path.exists(upperdirs): - os.makedirs(upperdirs) + os.makedirs(upperdirs, exist_ok=True) if member.is_dir(): if not os.path.isdir(targetpath): - os.mkdir(targetpath) + try: + os.mkdir(targetpath) + except FileExistsError: + pass return targetpath with self.open(member, pwd=pwd) as source, \ diff --git a/Misc/NEWS.d/next/Library/2023-12-12-10-25-46.gh-issue-112998.F2QyD0.rst b/Misc/NEWS.d/next/Library/2023-12-12-10-25-46.gh-issue-112998.F2QyD0.rst new file mode 100644 index 00000000000000..c0c79a41a84a7e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-12-12-10-25-46.gh-issue-112998.F2QyD0.rst @@ -0,0 +1,2 @@ +``zipfile`` - Avoid race condition creating parent directories when +extracting concurrently. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy