Skip to content

Commit

Permalink
Fix extract_zipped_paths infinite loop when provided invalid unc path
Browse files Browse the repository at this point in the history
  • Loading branch information
tl-hbk committed Jun 30, 2021
1 parent 1466ad7 commit ad17472
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions requests/utils.py
Expand Up @@ -245,6 +245,9 @@ 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:
# Needed to prevent infinite looping when provided invalid UNC path
break
member = '/'.join([prefix, member])

if not zipfile.is_zipfile(archive):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_utils.py
Expand Up @@ -285,6 +285,10 @@ def test_zipped_paths_extracted(self, tmpdir):
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:

Expand Down

0 comments on commit ad17472

Please sign in to comment.