Reject Windows console devices and spaced device stems in snapshots

This commit is contained in:
Eremey Valetov committed 2026-11-07 05:53:32 -05:00
1 parent 8e1c22aa28
commit 229f6464f0
2 files changed
+3 -3

No files matched your search

+1 -1
View File
@@ -88,7 +88,7 @@ def test_empty_limits_lock_and_cli(tmp_path):
s.restore(repo, result['snapshot'], src)
@pytest.mark.parametrize('name', ['../escape', '/absolute', 'C:drive', 'con', 'a.', 'a\\b', 'a//b'])
@pytest.mark.parametrize('name', ['../escape', '/absolute', 'C:drive', 'con', 'a.', 'a\\b', 'a//b', 'CONIN$', 'ConOut$.log', 'CON .txt', 'aux .foo'])
def test_unsafe_manifest_paths(tmp_path, name):
src, repo = tmp_path/'src', tmp_path/'repo'
src.mkdir(); (src/'a').write_bytes(b'payload')
+2 -2
View File
@@ -30,7 +30,7 @@ MAX_MANIFEST = 64 * 1024 * 1024
MAX_ENTRIES = 100_000
MAX_REFS = 500_000
DIGEST = re.compile(r"[0-9a-f]{64}\Z")
RESERVED = re.compile(r"(?:con|prn|aux|nul|com[1-9¹²³]|lpt[1-9¹²³])(?:\.|$)", re.I)
RESERVED = re.compile(r"(?:con|conin\$|conout\$|prn|aux|nul|com[1-9¹²³]|lpt[1-9¹²³])\Z", re.I)
def _json(value):
@@ -169,7 +169,7 @@ def _path(value):
raise ValueError("snapshot path exceeds 64 components")
for part in parts:
if (part in ("", ".", "..") or part[-1:] in (".", " ") or
RESERVED.match(part) or len(part.encode("utf-8")) > 240 or
RESERVED.fullmatch(part.partition(".")[0].rstrip(" ")) or len(part.encode("utf-8")) > 240 or
any(ord(c) < 32 or ord(c) == 127 or c in '\\:< >"|?*'.replace(" ", "") for c in part)):
raise ValueError(f"path cannot be restored portably: {value!r}")
return tuple(parts)