From c57cca2fcfb949cb88c0fdd9fdf074effcfabbc5 Mon Sep 17 00:00:00 2001 From: Matthias Bernt Date: Mon, 11 Nov 2024 15:50:36 +0100 Subject: [PATCH] fix bug for empty requirements an empty set of requirements gives an empty requirement string which was wrongly parsed to an CondaTarget with empty package name This triggered a `conda search ''` which took so much memory that other processes crashed. The fix is to parse an empty list of CondaTargets for an empty target string. In addition we check for empty package name during the creation of the CondaTarget (to make this more easily detectable in the future) --- lib/galaxy/tool_util/deps/conda_util.py | 2 +- lib/galaxy/tool_util/deps/mulled/mulled_build.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/galaxy/tool_util/deps/conda_util.py b/lib/galaxy/tool_util/deps/conda_util.py index 8bead7148a5d..ccc8cf2da06d 100644 --- a/lib/galaxy/tool_util/deps/conda_util.py +++ b/lib/galaxy/tool_util/deps/conda_util.py @@ -425,7 +425,7 @@ class CondaTarget: def __init__( self, package: str, version: Optional[str] = None, build: Optional[str] = None, channel: Optional[str] = None ) -> None: - if SHELL_UNSAFE_PATTERN.search(package) is not None: + if SHELL_UNSAFE_PATTERN.search(package) is not None or not package: raise ValueError(f"Invalid package [{package}] encountered.") self.capitalized_package = package self.package = package.lower() diff --git a/lib/galaxy/tool_util/deps/mulled/mulled_build.py b/lib/galaxy/tool_util/deps/mulled/mulled_build.py index be956c84a8b9..0faed0049f43 100644 --- a/lib/galaxy/tool_util/deps/mulled/mulled_build.py +++ b/lib/galaxy/tool_util/deps/mulled/mulled_build.py @@ -527,8 +527,8 @@ def add_single_image_arguments(parser): ) -def target_str_to_targets(targets_raw): - def parse_target(target_str): +def target_str_to_targets(targets_raw: str) -> List[CondaTarget]: + def parse_target(target_str: str) -> CondaTarget: if "=" in target_str: package_name, version = target_str.split("=", 1) build = None @@ -540,9 +540,10 @@ def parse_target(target_str): else: target = build_target(target_str) return target - - targets = [parse_target(_) for _ in targets_raw.split(",")] - return targets + if targets_raw.strip() == "": + return [] + else: + return [parse_target(_) for _ in targets_raw.split(",")] def args_to_mull_targets_kwds(args):