Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions modelconverter/utils/docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import tempfile
import zipfile
from contextlib import suppress
from pathlib import Path
from typing import Literal
from urllib.error import HTTPError, URLError
Expand Down Expand Up @@ -260,7 +261,7 @@
tmp_path: Path | None = None
try:
request = Request(url, headers={"User-Agent": "modelconverter"}) # noqa: S310
with urlopen(request, timeout=30) as response: # noqa: S310

Check failure on line 264 in modelconverter/utils/docker_utils.py

View workflow job for this annotation

GitHub Actions / semgrep/ci

Semgrep Issue

Detected a dynamic value being used with urllib. urllib supports 'file://' schemes, so a dynamic value controlled by a malicious actor may allow them to read arbitrary files. Audit uses of urllib calls to ensure user data cannot control the URLs, or consider using the 'requests' library instead.
if getattr(response, "status", 200) >= 400:
raise RuntimeError(
f"HTTP {response.status} while downloading {url}"
Expand Down Expand Up @@ -359,9 +360,13 @@
image = f"{image_repo}:{tag}"

candidate_images = [image]
# add full version if specified RVC4 tag is with build number included (e.g. version=2.32.6.250402 instead of version=2.32.6)
if target == "rvc4" and tag_version != version and image_tag is None:
candidate_images.append(f"{image_repo}:{version}-{bare_tag}")
if target == "rvc4":
candidate_images.append(f"{image_repo}-private:{tag}")
# add full version if specified RVC4 tag is with
# build number included (e.g. version=2.32.6.250402
# instead of version=2.32.6)
if tag_version != version and image_tag is None:
candidate_images.append(f"{image_repo}:{version}-{bare_tag}")

candidate_tags = set()
for candidate in candidate_images:
Expand All @@ -374,17 +379,17 @@
if tags:
return next(iter(tags))

logger.warning(
f"Image '{candidate_images[0]}' not found, pulling "
f"the latest image from 'ghcr.io/{candidate_images[0]}'..."
)
for candidate in candidate_images:
logger.warning(
f"Image '{candidate}' not found locally, pulling "
f"the latest image from 'ghcr.io/{candidate}'..."
)

try:
return pull_image(client, f"ghcr.io/{candidate_images[0]}")
with suppress(Exception):
return pull_image(client, f"ghcr.io/{candidate}")

except Exception:
logger.error("Failed to pull the image, building it locally...")
return docker_build(target, bare_tag, version, image)
logger.error("Failed to pull the image, building it locally...")
return docker_build(target, bare_tag, version, image)


def docker_exec(
Expand Down
Loading