Skip to content

Commit a7fde72

Browse files
refactor(ox): be more defensive
1 parent f506815 commit a7fde72

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ dependencies = [
9999
"aiopath>=0.6.11,<1",
100100
"boto3>=1.40.64,<2",
101101
"certifi>=2025.10.5,<2026",
102+
"defusedxml>=0.7.1",
102103
"dicom-validator>=0.7.3,<1",
103104
"dicomweb-client[gcp]>=0.59.3,<1",
104105
"duckdb>=0.10.0,<=1.4.1",

src/aignostics/qupath/_service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ def _extract_qupath( # noqa: C901, PLR0912, PLR0915
707707
f"cat '{payload_path.resolve()!s}' | gunzip -dc | cpio -i",
708708
]
709709
if platform.system() == "Darwin"
710-
else ["7z", "x", str(payload_path.resolve()), "-o" + str(payload_extract_dir.resolve())]
710+
else ["7z", "x", str(payload_path.resolve()), f"-o{payload_extract_dir.resolve()!s}"]
711711
)
712712
subprocess.run( # noqa: S603
713713
command,

src/aignostics/third_party/showinfm/showinfm.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,12 @@ def show_in_file_manager(
343343
for d in directories:
344344
if verbose:
345345
print("Executing Windows shell to open", d)
346-
os.startfile(d)
346+
# Validate path exists and is a directory before opening
347+
path_obj = Path(d)
348+
if path_obj.exists() and path_obj.is_dir():
349+
os.startfile(d) # noqa: S606
350+
elif verbose:
351+
print(f"Skipping invalid or non-directory path: {d}", file=sys.stderr)
347352
else:
348353
if uris_and_paths:
349354
# Some file managers must be passed only one or zero paths / URIs

src/aignostics/wsi/_openslide_handler.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Handler for wsi files using OpenSlide."""
22

3-
import xml.etree.ElementTree as ET # noqa: S405
43
from pathlib import Path
54
from typing import Any
65

6+
import defusedxml.ElementTree as ET # noqa: N817
77
import openslide
88
from openslide import ImageSlide, OpenSlide, open_slide
99
from PIL.Image import Image
@@ -44,11 +44,10 @@ def _detect_format(self) -> str | None:
4444
str: The detected format of the TIFF file.
4545
"""
4646
props = dict(self.slide.properties)
47-
4847
# Check for libvips signature in XML metadata
4948
if TIFF_IMAGE_DESCRIPTION in props:
5049
try:
51-
root = ET.fromstring(props[TIFF_IMAGE_DESCRIPTION]) # noqa: S314
50+
root = ET.fromstring(props[TIFF_IMAGE_DESCRIPTION])
5251
if root.get("xmlns") == "http://www.vips.ecs.soton.ac.uk//dzsave":
5352
return "pyramidal-tiff (libvips)"
5453
except ET.ParseError:
@@ -87,7 +86,7 @@ def _parse_xml_image_description(self, xml_string: str) -> dict[str, Any]: # no
8786
dict[str, Any]: Parsed image description as a dictionary with metadata properties.
8887
"""
8988
try:
90-
root = ET.fromstring(xml_string) # noqa: S314
89+
root = ET.fromstring(xml_string)
9190
namespace = {"ns": "http://www.vips.ecs.soton.ac.uk//dzsave"}
9291
image_desc: dict[str, Any] = {
9392
"date": root.get("date"),

uv.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)