Skip to content

The agent that grows with you

fix(release): inline Windows reserved-path check for pre-3.13 runners

ethernet4e45b783117f
diff --git a/scripts/releases/r2.py b/scripts/releases/r2.py
index 6f993af9e2a..1bf596615a4 100644
--- a/scripts/releases/r2.py
+++ b/scripts/releases/r2.py
@@ -6,7 +6,6 @@ import json
from pathlib import Path
import hmac
import http.client
-import ntpath
import os
import re
import sys
@@ -409,12 +408,37 @@ def is_full_sha(value: str) -> bool:
return bool(isinstance(value, str) and _FULL_SHA_RE.fullmatch(value))
+# Windows reserved names (CPython ntpath parity). COM/LPT superscript forms
+# (COM² etc.) are reserved under NTFS namespace rules, same as the digit forms.
+_WIN_RESERVED_NAMES = frozenset(
+ ["CON", "PRN", "AUX", "NUL", "CONIN$", "CONOUT$"]
+ + [f"COM{i}" for i in range(1, 10)] + ["COM¹", "COM²", "COM³"]
+ + [f"LPT{i}" for i in range(1, 10)] + ["LPT¹", "LPT²", "LPT³"]
+)
+
+
+def _is_windows_reserved(value: str) -> bool:
+ """True if any path component is reserved on Windows.
+
+ Port of ntpath.isreserved() (added in Python 3.13; release CI may run
+ older system Pythons, so inline the semantics rather than depend on it).
+ """
+ for part in reversed(value.split("/")):
+ # Trailing dots and spaces are reserved.
+ if part[-1:] in (".", " ") and part not in (".", ".."):
+ return True
+ stem = part.partition(".")[0].rstrip(" ").upper()
+ if stem in _WIN_RESERVED_NAMES:
+ return True
+ return False
+
+
def relative_artifact_path(value: str) -> str:
"""Validate the original path before any filesystem normalization."""
if (not isinstance(value, str) or not value or value.startswith("/")
or any(part in ("", ".", "..") for part in value.split("/"))
or any(c in value for c in "\\:%?#") or any(ord(c) < 32 for c in value)
- or ntpath.isreserved(value)):
+ or _is_windows_reserved(value)):
raise ValueError("Invalid release artifact path")
return value
diff --git a/tests/scripts/test_release_r2.py b/tests/scripts/test_release_r2.py
index 1aab2f03a0e..9ffe0e530e6 100644
--- a/tests/scripts/test_release_r2.py
+++ b/tests/scripts/test_release_r2.py
@@ -195,6 +195,35 @@ def test_channel_for_tag_maps_stable_vs_canary():
assert channel_for_tag("v0.28.0-canary.20260818") == "canary"
+def test_relative_artifact_path_rejects_windows_reserved_names_without_ntpath(monkeypatch):
+ """Windows-reserved names must be rejected even when ntpath.isreserved
+ does not exist (release CI legs run on system Pythons older than 3.13;
+ commit-builds-summary crashed on the bare AttributeError)."""
+ import ntpath
+
+ # Simulate a pre-3.13 ntpath: isreserved absent, as on the ubuntu-24.04
+ # system Python the release workflows run on. Red on the old code, which
+ # called ntpath.isreserved unconditionally.
+ monkeypatch.delattr(ntpath, "isreserved", raising=False)
+
+ def check(bad):
+ with pytest.raises(ValueError, match="Invalid release artifact path"):
+ r2.relative_artifact_path(bad)
+
+ # DOS device stems in every dotted form, in every component.
+ for bad in ("nul", "NUL.txt", "con.tar.gz", "desktop/aux.js", "com1",
+ "lpt9.zip", "a/prn.gz", "COM¹.txt", "x/CONOUT$/y"):
+ check(bad)
+ # Trailing dots and spaces are reserved on Windows (internal ones are not).
+ for bad in ("foo.", "foo ", "dir/foo.", "dir/foo..", "dir/foo .tar.gz."):
+ check(bad)
+ # Real artifact names, including the nested Termux receipt shape, pass.
+ for good in ("app.msix", "deb/pool/hermes_0.28.0_aarch64.deb",
+ "HermesBundled-0.28.0-win-x64.msix", "key.asc", "com10.txt",
+ "xcom1.tar.gz", "hermes-agent-setup.exe"):
+ assert r2.relative_artifact_path(good) == good
+
+
def test_staging_key_and_feed_dir_layout_keys():
assert staging_key_for("v0.28.0", "HermesBundled-0.28.0-win-x64.msix") == (
"releases/tag/v0.28.0/HermesBundled-0.28.0-win-x64.msix"