Fix extract_zipped_paths infinite loop when provided invalid unc path (#5851)

This commit is contained in:
Thomas Lam
2021-08-02 19:40:34 -05:00
committed by GitHub
parent b227e3cb82
commit d8829f9f24
2 changed files with 8 additions and 0 deletions
+4
View File
@@ -251,6 +251,10 @@ def extract_zipped_paths(path):
archive, member = os.path.split(path)
while archive and not os.path.exists(archive):
archive, prefix = os.path.split(archive)
if not prefix:
# If we don't check for an empty prefix after the split (in other words, archive remains unchanged after the split),
# we _can_ end up in an infinite loop on a rare corner case affecting a small number of users
break
member = '/'.join([prefix, member])
if not zipfile.is_zipfile(archive):
+4
View File
@@ -285,6 +285,10 @@ class TestExtractZippedPaths:
assert os.path.exists(extracted_path)
assert filecmp.cmp(extracted_path, __file__)
def test_invalid_unc_path(self):
path = r"\\localhost\invalid\location"
assert extract_zipped_paths(path) == path
class TestContentEncodingDetection: