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 Aug 3, 2021
1 parent b227e3c commit d8829f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions requests/utils.py
Expand Up @@ -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):
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 d8829f9

Please sign in to comment.