Layers: Fix opening UNC paths on windows

This commit is contained in:
Mike Auty
2022-02-23 00:00:07 +00:00
parent aa198f2709
commit 58697479bb
+15 -1
View File
@@ -10,10 +10,11 @@ import logging
import lzma
import os
import ssl
import sys
import urllib.parse
import urllib.request
import zipfile
from typing import Optional, Any, IO, List
from typing import Any, IO, List, Optional
from urllib import error
from volatility3 import framework
@@ -100,6 +101,19 @@ class ResourceAccessor(object):
"""
urllib.request.install_opener(urllib.request.build_opener(*self._handlers))
# Python bug 46654
if sys.platform == 'win32':
# We only need to worry about UNC paths on windows, on linux they'd be smb:// and need pysmb or similar
parsed_url = urllib.parse.urlparse(url, scheme = 'file')
if parsed_url.scheme == 'file' and parsed_url.netloc:
# Change the netloc to '/' and then prepend the netloc to the path
# Urlunparse will remove extra initial slashes from path, hence setting netloc
new_url = urllib.parse.urlunparse((parsed_url.scheme, '/',
'/' + parsed_url.netloc + parsed_url.path, parsed_url.params,
parsed_url.query, parsed_url.fragment))
vollog.log(constants.LOGLEVEL_VVVV, f'UNC path detected, converted path {url} to {new_url}')
url = new_url
try:
fp = urllib.request.urlopen(url, context = self._context)
except error.URLError as excp: