mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Fix extract_zipped_paths infinite loop when provided invalid unc path (#5851)
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user