Skip to content

fix(multimodal): detect truncated images at the frontend via pixel-le…#1307

Merged
hiworldwzj merged 3 commits into
mainfrom
image_check
May 14, 2026
Merged

fix(multimodal): detect truncated images at the frontend via pixel-le…#1307
hiworldwzj merged 3 commits into
mainfrom
image_check

Conversation

@shihaobai
Copy link
Copy Markdown
Collaborator

…vel decode

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces robust image verification to prevent server crashes caused by truncated or corrupted images. It implements a thread pool to perform pixel-level decoding verification using PIL, offloading this CPU-intensive task from the main event loop. Additionally, a new test script is included to verify that the API correctly rejects invalid images with a 4xx error. The review identified a potential runtime error during environment variable parsing for the thread pool configuration and suggested translating the test script's documentation into English for better accessibility.

Comment thread lightllm/server/multimodal_params.py Outdated
ImageFile.LOAD_TRUNCATED_IMAGES = False

_IMAGE_VERIFY_POOL = ThreadPoolExecutor(
max_workers=int(os.getenv("LIGHTLLM_IMAGE_VERIFY_WORKERS", str((os.cpu_count() or 4) * 2))),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The int() conversion could raise a ValueError if the LIGHTLLM_IMAGE_VERIFY_WORKERS environment variable is set to a non-numeric string. This would crash the server on startup. It would be more robust to handle this with a try-except block, log a warning, and fall back to the default value.

Comment on lines +1 to +8
"""验证残缺图片在 OpenAI /v1/chat/completions 接口被前端拦截为 4xx。

启动 server:
python -m lightllm.server.api_server --port 8000 --model_dir <your_vlm> --tp 1

运行:
python test/test_api/test_image_verify_api.py
"""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

For consistency with the rest of the codebase and to make it more accessible to non-Chinese speakers, please consider translating the docstring and comments into English.

Suggested change
"""验证残缺图片在 OpenAI /v1/chat/completions 接口被前端拦截为 4xx
启动 server
python -m lightllm.server.api_server --port 8000 --model_dir <your_vlm> --tp 1
运行
python test/test_api/test_image_verify_api.py
"""
"""Verify that truncated images are rejected with a 4xx error by the frontend
at the OpenAI /v1/chat/completions endpoint.
To run this test:
1. Start the server:
python -m lightllm.server.api_server --port 8000 --model_dir <your_vlm> --tp 1
2. Run the test script:
python test/test_api/test_image_verify_api.py
"""

@hiworldwzj hiworldwzj merged commit 8141c56 into main May 14, 2026
1 check passed
@hiworldwzj hiworldwzj deleted the image_check branch May 14, 2026 01:45
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.

2 participants