Skip to content

[#22190][fix] Resolve file:// URIs and special characters in load_image - #22193

Merged
tongyuantongyu merged 1 commit into
NVIDIA:mainfrom
sohailshk:fix/image-file-uri
Nov 19, 2026
Merged

tongyuantongyu merged 1 commit into
NVIDIA:mainfrom
sohailshk:fix/image-file-uri

Conversation

@sohailshk

@sohailshk sohailshk commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Dev Engineer Review

  • tensorrt_llm/inputs/utils.py (+2/-2): load_image and async_load_image now resolve local and file: sources with _normalize_file_uri before loading. The synchronous and asynchronous paths both pass the normalized value as a Path. The async path no longer uses urlparse(...).path, which caused the bug in #22190.
  • The helper returns bare paths unchanged, according to the PR description. Bare paths that contain #, ?, or ; should load correctly. The helper's handling of literal %xx text in bare paths was not verified in the source.
  • The diff changes no public declarations, configuration, or dependencies.
  • The PR description reports the change on macOS with a stub package init. It reports no CUDA test run.

QA Engineer Review

  • Test file added or modified: tests/unittest/inputs/test_async_media_loading.py (+43 lines). It adds TestLoadImageLocalFile.
  • Test function: TestLoadImageLocalFile::test_sync_and_async_load_the_same_file. It covers 6 filenames, each used as a bare path and as a file:// URI, for 12 cases across load_image and async_load_image.
  • Filenames cover plain text, spaces, and the reserved characters #, ?, and ;.
  • The PR reports 9 of 12 cases fail on the base branch and all 12 pass with the change. The full file reports 37 passing tests. These results come from the PR description, not from a CI run that was inspected.
  • Test-list changes: none. The changed-file list does not include tests/integration/test_lists/test-db/ or tests/integration/test_lists/qa/. Whether an existing list entry covers this unit test file is not available.
  • Coverage verdict: sufficient for the reported local-file cases. The change does not cover CUDA paths, and the CUDA test suite was not run. Confirm CI results on the current head before merge.

Per-File QA Perspective

  • tensorrt_llm/inputs/utils.py: QA should confirm that load_image and async_load_image load a file:// URI with percent-encoded names. QA should also confirm that bare paths with #, ?, or ; load in both functions. Test the default multimodal loader with a local file:// image in offline mode.
  • tests/unittest/inputs/test_async_media_loading.py: The new test compares synchronous and asynchronous PIL output against a reference image for each case. It is a unit test and needs no GPU.

Description

Fixes #22190.

load_image passed a file:// URI to PIL as a literal file name, so it raised FileNotFoundError. async_load_image took urlparse(...).path without unquoting, so a percent-encoded name was never found, and a bare path containing #, ? or ; was cut at that character.

Both functions now resolve local sources with _normalize_file_uri, as ImageMediaIO.load_file and the audio loaders already do. Bare paths are returned unchanged by that helper.

Test Coverage

tests/unittest/inputs/test_async_media_loading.py::TestLoadImageLocalFile::test_sync_and_async_load_the_same_file (12 cases: bare path and file:// URI, for plain, space, #, ?, ; and % file names, through both load_image and async_load_image). On the base branch 9 of the 12 fail, with the change all pass; the whole file passes (37 tests). tests/unittest/inputs is already on the l0_cpu list.

Run on macOS with a stub package init (no CUDA, no compiled bindings); the CUDA test suite was not run.

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

load_image passed a file:// URI to PIL as a literal file name, so it
raised FileNotFoundError, and async_load_image took urlparse().path
without unquoting, so a percent-encoded name was never found and a bare
path containing '#', '?' or ';' was cut at that character.

Resolve local sources through _normalize_file_uri in both functions, as
ImageMediaIO.load_file and the audio loaders already do.

Signed-off-by: sohailshk <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The synchronous and asynchronous image loaders now normalize local paths and file: URIs before loading. New tests cover bare paths and file URIs with spaces and reserved characters.

Changes

Local image loading

Layer / File(s) Summary
Normalize local image inputs and verify loading
tensorrt_llm/inputs/utils.py, tests/unittest/inputs/test_async_media_loading.py
Both loaders pass normalized local paths to PIL. Tests compare synchronous and asynchronous results with reference pixels for six filenames, using bare paths and file URIs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to d5af7

Local image loading now handles file:// URIs, percent-encoded names, and bare paths containing reserved characters in both the synchronous and asynchronous loaders. The change is small, the tests cover the affected cases, and no merge-blocking risk is evident.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: load_image and async_load_image now resolve file:// URIs and special characters in local paths. It follows the required [ticket][type] Summary format with the issue nu…
Description check Passed The description covers the problem, the fix, and the test coverage. It states the test file, the 12 cases, the base-branch failures, and the platform used. It also marks the checklist. It does not fol…
Linked Issues check Passed Issue #22190 requires (1) load_image to load file:// URIs, and (2) async_load_image to load percent-encoded names and bare paths containing #, ?, or ;. The diff at head changes `load_image…
Out of Scope Changes check Passed The whole-PR diff against the merge base changes two call sites in tensorrt_llm/inputs/utils.py (load_image and async_load_image) and adds one test class in tests/unittest/inputs/test_async_media_…
Full details: Title check

Explanation

The title names the main change: load_image and async_load_image now resolve file:// URIs and special characters in local paths. It follows the required [ticket][type] Summary format with the issue number and the fix type. It matches the raw summary and the PR objectives.

Full details: Description check

Explanation

The description covers the problem, the fix, and the test coverage. It states the test file, the 12 cases, the base-branch failures, and the platform used. It also marks the checklist. It does not follow the template's Description wording exactly, but it has the required sections and enough detail. The checklist items are restated with the bullet text trimmed, and the template's commented guidance is not included. These are minor gaps.

Full details: Linked Issues check

Explanation

Issue #22190 requires (1) load_image to load file:// URIs, and (2) async_load_image to load percent-encoded names and bare paths containing #, ?, or ;. The diff at head changes load_image (tensorrt_llm/inputs/utils.py) to call _load_and_convert_image(Path(_normalize_file_uri(image))) for the ''/file schemes. It also changes async_load_image to call _load_and_convert_image with Path(_normalize_file_uri(image)) instead of Path(parsed_url.path). The raw string now reaches the helper, so urlparse no longer truncates bare paths at #, ?, or ;, and file:// URIs are unquoted. The same helper is already used by load_audio and async_load_audio for file scheme inputs. The reported test TestLoadImageLocalFile::test_sync_and_async_load_the_same_file covers the 12 cases (bare and file:// forms, sync and async). The PR reports 9 of 12 failing on base and all passing on head. The test file was not read during this review. The body of _normalize_file_uri was not read directly, because the read was truncated. The bare-path pass-through relies on the PR description and the existing load_audio usage. No non-coding requirements exist in the issue.

Full details: Out of Scope Changes check

Explanation

The whole-PR diff against the merge base changes two call sites in tensorrt_llm/inputs/utils.py (load_image and async_load_image) and adds one test class in tests/unittest/inputs/test_async_media_loading.py. Both changes address the local-file loading defect in #22190. No unrelated code paths, public signatures, or other modalities are changed in the reviewed diff. The helper _normalize_file_uri is imported from existing code and not modified by this PR.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between e275e3a and d5af7ea.

Files selected for processing: 2

  • tensorrt_llm/inputs/utils.py
  • tests/unittest/inputs/test_async_media_loading.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

@svc-trtllm-gh-bot svc-trtllm-gh-bot added the Community want to contribute PRs initiated from Community label Nov 12, 2026
@tongyuantongyu

Copy link
Copy Markdown
Member

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #85715 [ run ] triggered by Bot. Commit: d5af7ea Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #85715 [ run ] completed with state SUCCESS. Commit: d5af7ea
/LLM/main/L0_MergeRequest_PR pipeline #70965 completed with status: 'SUCCESS'

CI Report

Link to invocation

@github-actions

Copy link
Copy Markdown

Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements.

@tongyuantongyu
tongyuantongyu merged commit 7935bf5 into NVIDIA:main Nov 19, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

load_image fails on file:// URIs and async_load_image mishandles percent-encoded paths and #, ?, ; in file names

5 participants