Skip to content

fix: check output paths in linear time - #410

Merged
uniqueg merged 2 commits into
devfrom
fix/output-path-wildcards
Nov 4, 2026
Merged

uniqueg merged 2 commits into
devfrom
fix/output-path-wildcards

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #408.

  • has_wildcards replaces the regular expression for wildcards in output paths: a linear scan with the same matches (*, ?, or a [ with a ] at least two characters later).
  • validate_task limits each path of a task to 4096 bytes of UTF-8 (path of inputs and outputs, path_prefix, volumes, and workdir, stdin, stdout and stderr of executors), so also after plugins changed the task. Longer ones get 400 Bad Request.
  • docs/api.md documents the limit.

Verification

  • pytest: full suite, with Helm 3.22.1 and the built chart dependencies. New tests: exhaustive comparison with the old pattern on all strings of [, ] and a up to length 8; 1 MB paths checked in under a second; each path field; the limit in bytes; a lone surrogate; POST /tasks answers 400 and keeps nothing.
  • pre-commit run on the changed files (ruff, semgrep, gitleaks, ast-grep, mypy): passed.
  • Not run locally: the Compose smoke test and the docs build (both run in CI).

Declined review findings

  • PATH_MAX includes the terminating NUL, so 4095 would be the exact Linux limit (low): kept 4096, the common value, and the docstring and docs say it is the value of PATH_MAX, and that backends may allow less.

🤖 Generated with Claude Code

Summary by Sourcery

Enforce efficient output wildcard validation and a 4096-byte limit across task paths.

Bug Fixes:

  • Replace wildcard detection for output paths with a linear-time check to prevent inefficient processing of long paths.
  • Reject tasks containing any path longer than 4096 UTF-8 bytes, including paths introduced or modified by plugins.

Documentation:

  • Document the 4096-byte task path limit in the API documentation.

Tests:

  • Add coverage for wildcard-detection equivalence and linear-time behavior.
  • Add validation coverage for all supported task path fields, byte-based limits, and rejection of oversized tasks without persistence.

uniqueg and others added 2 commits November 4, 2026 05:23
Replace the regular expression that finds wildcards in output paths,
which took quadratic time on some paths, with a linear scan that finds
the same wildcards. Limit the size of the paths of a task to 4096 bytes
in `validate_task`, so also after plugins changed the task.

Closes #408

Co-Authored-By: Claude Opus 5.5 <[email protected]>
State which fields the limit covers, test the response of the API and
lone surrogates, and test the scan directly on brackets only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@uniqueg uniqueg added this to the v0.5.0 milestone Nov 4, 2026
@sourcery-ai

sourcery-ai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR makes output wildcard compatibility checks linear-time and bounds every task path to 4096 UTF-8 bytes through centralized post-plugin validation, rejecting oversized tasks before persistence or relay and documenting the behavior.

Sequence diagram for bounded task submission validation

sequenceDiagram
    actor Client
    participant API as Task API
    participant Plugins
    participant Validator as validate_task
    participant Store as Task persistence
    participant Backend

    Client->>API: POST /tasks
    API->>Plugins: Run task pipeline
    Plugins-->>API: Return possibly modified task
    API->>Validator: validate_task(payload)
    Validator->>Validator: _task_paths(task)
    alt Any path exceeds MAX_PATH_SIZE
        Validator-->>API: ValueError
        API-->>Client: 400 Bad Request
        API-->>Store: Do not persist task
        API-->>Backend: Do not relay task
    else All paths are within 4096 UTF-8 bytes
        Validator-->>API: Valid task
        API->>Store: Persist task
        API->>Backend: Relay task
        API-->>Client: Accepted
    end
Loading

Flow diagram for linear-time output wildcard detection

flowchart LR
    Path[Output path] --> Check{Contains * or ?}
    Check -->|Yes| Wildcard[Wildcards detected]
    Check -->|No| Opening[Find first opening bracket]
    Opening --> Bracket{Closing bracket at least two positions later}
    Bracket -->|Yes| Wildcard
    Bracket -->|No| Clear[No wildcards]
Loading

File-Level Changes

Change Details Files
Replaced regex-based output wildcard detection with a linear-time compatibility check.
  • Detect * and ? directly and bracket expressions using first-opening/last-closing bracket positions.
  • Preserve the previous wildcard semantics and add exhaustive equivalence and large-input performance coverage.
pro_tes/ga4gh/tes/versions.py
tests/ga4gh/tes/test_versions.py
Added centralized validation for the UTF-8 byte length of every task path, including paths changed by plugins.
  • Enumerate input/output paths, output prefixes, volumes, executor working directories, and standard-stream paths.
  • Reject paths over 4096 bytes, including correctly handling multibyte characters and lone surrogates.
  • Validate before task persistence or relay and cover all fields and the exact boundary.
pro_tes/gateway.py
tests/test_gateway.py
tests/ga4gh/tes/test_server.py
Documented the task path-size limit and backend compatibility caveat in the API documentation.
  • Describe the 4096-byte PATH_MAX-based limit and the affected fields.
  • State that backends may impose a smaller limit and distinguish this rejection from inline-content limits.
docs/api.md

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 proTES | 🛠️ Build #35632898 | 📁 Comparing c1fd96b against latest (5a57844)

  🔍 Preview build  

2 files changed
± api/index.html
± reference/index.html

@codecov

codecov Bot commented Nov 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (5a57844) to head (c1fd96b).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #410   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           24        24           
  Lines         2479      2500   +21     
=========================================
+ Hits          2479      2500   +21     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 4, 2026 04:47

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="pro_tes/gateway.py" line_range="262" />
<code_context>
-    TesTask(**payload)
+    task = TesTask(**payload)
     tes_task(payload)
+    for path in _task_paths(task):
+        # JSON can carry lone surrogates
+        if len(path.encode("utf-8", errors="surrogatepass")) > MAX_PATH_SIZE:
</code_context>
<issue_to_address>
**Oversized plugin paths reach backend**

When a forward-phase plugin adds or changes an outbound path to more than 4096 bytes, `check_outbound` sanitizes a copy and calls `tes_task` without checking the path limit, so the backend runs a task that exceeds the limit while the stored task retains the earlier path.

Validate the outbound task's paths against `MAX_PATH_SIZE` in `check_outbound` before sending it to the backend.
</issue_to_address>

### Comment 2
<location path="docs/api.md" line_range="45" />
<code_context>
-   proTES is configured to remove them, and tasks with inline contents of
-   inputs over `max_inline_content`, with `413 Content Too Large`: see
+   proTES is configured to remove them, and tasks with a path over 4096
+   bytes (the value of `PATH_MAX` on Linux; `path` of inputs and outputs, `path_prefix`,
+   `volumes`, and `workdir`, `stdin`, `stdout` and `stderr` of executors);
+   tasks with inline contents of inputs over `max_inline_content` are
</code_context>
<issue_to_address>
**Generated clients miss path limit**

When a client relies on the published OpenAPI schema to construct or validate a task with a path over 4096 UTF-8 bytes, the published OpenAPI schema still defines task path fields as unconstrained strings, so clients generated from it accept paths that the server rejects with `400 Bad Request`.

Describe the 4096-byte limit in the published schema for each affected field, noting that it is a byte limit rather than a character-count limit.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: pro_tes/gateway.py:262, docs/api.md:45


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread pro_tes/gateway.py Resolved
Comment thread docs/api.md Resolved
@uniqueg
uniqueg merged commit c924f3f into dev Nov 4, 2026
44 checks passed
@uniqueg
uniqueg deleted the fix/output-path-wildcards branch November 4, 2026 04:54
uniqueg added a commit that referenced this pull request Nov 4, 2026
Brings in the review fixes #410, #412, #417, #419, #420, #421.

The only conflict is in the module docstring of
`pro_tes/ga4gh/tes/backends.py`: keeps this branch's removal of the
FOCA 0.19 caveat about redirects, and the sentence of #419 about tasks
in the view `FULL`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: linear check for wildcards in output paths

1 participant