invoke-ai/InvokeAI · error
Empty path segments not allowed in subfolder path
Error message
Empty path segments not allowed in subfolder path
What it means
_validate_subfolder rejects empty path segments: a subfolder like 'a//b' or a trailing slash 'a/' splits into '' parts, which is treated as malformed input rather than silently collapsed. The library requires a clean, canonical relative path.
Source
Thrown at invokeai/app/services/video_files/video_files_disk.py:218
def validate_path(self, path: Union[str, Path]) -> bool:
path = path if isinstance(path, Path) else Path(path)
return path.exists()
@staticmethod
def _validate_subfolder(subfolder: str) -> None:
"""Validates a subfolder path to prevent directory traversal."""
if not subfolder:
return
if "\\" in subfolder:
raise ValueError("Backslashes not allowed in subfolder path")
if subfolder.startswith("/"):
raise ValueError("Absolute paths not allowed in subfolder path")
for part in subfolder.split("/"):
if part == "..":
raise ValueError("Parent directory references not allowed in subfolder path")
if part == "":
raise ValueError("Empty path segments not allowed in subfolder path")
def __get_sidecar_path(self, video_name: str, video_subfolder: str = "") -> Path:
sidecar_name = Path(video_name).stem + ".json"
if video_subfolder:
self._validate_subfolder(video_subfolder)
sidecar_path = self.__sidecars_folder / video_subfolder / sidecar_name
else:
sidecar_path = self.__sidecars_folder / sidecar_name
resolved_base = self.__sidecars_folder.resolve()
resolved_sidecar_path = sidecar_path.resolve()
if not resolved_sidecar_path.is_relative_to(resolved_base):
raise ValueError("Sidecar path outside outputs folder, potential directory traversal detected")
return resolved_sidecar_path
def __read_sidecar(self, video_name: str, video_subfolder: str = "") -> Optional[dict]:
path = self.__get_sidecar_path(video_name, video_subfolder=video_subfolder)
if not path.exists():
return NoneView on GitHub (pinned to 0b6a024f2f)
Solutions
- Strip duplicate and trailing slashes: subfolder = '/'.join(p for p in raw.split('/') if p)
- Normalize input with posixpath.normpath and re-check it is relative and non-empty
- Fix the code that constructs the subfolder string so it never introduces empty segments
Example fix
// before
subfolder = f"{base}/{name}/"
// after
subfolder = "/".join(p for p in f"{base}/{name}".split("/") if p) Defensive patterns
Strategy: validation
Validate before calling
import posixpath
def normalize_subfolder(raw: str) -> str:
cleaned = "/".join(p for p in raw.split("/") if p not in ("", "."))
assert ".." not in cleaned.split("/"), "traversal not allowed"
return cleaned Type guard
def is_clean_path(sub: str) -> bool:
return sub != "" and "//" not in sub and not sub.endswith("/") Try / catch
try:
path = service.get_path(video_name, subfolder=raw)
except ValueError as e:
if "Empty path segments" in str(e):
path = service.get_path(video_name, subfolder=normalize_subfolder(raw))
else:
raise Prevention
- Join path components with a helper instead of string concatenation
- Trim trailing slashes from client input before storing
- Write unit tests for subfolder strings with double slashes and trailing slashes
When it happens
Trigger: Passing subfolder='a//b', 'a/', '/a' (leading slash handled separately but trailing still fails), or '' inside get_path / __get_sidecar_path.
Common situations: String concatenation building subpaths ('base' + '/' + name where name already has a slash), URL path segments pasted into config, trailing-slash forms submitted from clients.
Related errors
- Backslashes not allowed in subfolder path
- Absolute paths not allowed in subfolder path
- Empty path segments not allowed in subfolder path
- No existing parent found for {path}
- Not a valid file or directory: {model_path}
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/29f6e1d60e23c21e.
Report an issue: GitHub.