Skip to content

Commit 018f03a

Browse files
authored
Merge pull request #5405 from reaperhulk/segfault-no-more
Fix a rare segfault
2 parents d67d98d + ba80574 commit 018f03a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

news/5366.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check for file existence and unlink first when clobbering existing files during a wheel install.

src/pip/_internal/wheel.py

+11
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,17 @@ def clobber(source, dest, is_base, fixer=None, filter=None):
285285
# uninstalled.
286286
ensure_dir(destdir)
287287

288+
# copyfile (called below) truncates the destination if it
289+
# exists and then writes the new contents. This is fine in most
290+
# cases, but can cause a segfault if pip has loaded a shared
291+
# object (e.g. from pyopenssl through its vendored urllib3)
292+
# Since the shared object is mmap'd an attempt to call a
293+
# symbol in it will then cause a segfault. Unlinking the file
294+
# allows writing of new contents while allowing the process to
295+
# continue to use the old copy.
296+
if os.path.exists(destfile):
297+
os.unlink(destfile)
298+
288299
# We use copyfile (not move, copy, or copy2) to be extra sure
289300
# that we are not moving directories over (copyfile fails for
290301
# directories) as well as to ensure that we are not copying

0 commit comments

Comments
 (0)