Repository navigation
[Security] Fix chat template resource-exhaustion DoS (GHSA-4hhp-h66f-… #50300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vllm-bot
merged 5 commits into
vllm-project:main
from
jperezdealgaba:fix/chat-template-resource-exhaustion-dos
Sep 30, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
99ffc7b
[Security] Fix chat template resource-exhaustion DoS (GHSA-4hhp-h66f-…
jperezdealgaba 07a0732
[Bugfix] Keep renderer async wrappers on a live pool after template t…
jperezdealgaba b820f42
[Bugfix] Import Executor for swappable renderer pool after rebase
jperezdealgaba 24d5713
Merge branch 'main' into fix/chat-template-resource-exhaustion-dos
jperezdealgaba bc87187
Merge branch 'main' into fix/chat-template-resource-exhaustion-dos
jperezdealgaba File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
| import asyncio | ||
| from dataclasses import dataclass | ||
| from typing import Any | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
| from vllm.renderers.base import _SwappableExecutor | ||
| from vllm.renderers.hf import HfRenderer | ||
| from vllm.renderers.params import TokenizeParams | ||
| from vllm.utils.async_utils import make_async | ||
|
|
||
| MODEL_NAME = "openai-community/gpt2" | ||
|
|
||
|
|
||
| @dataclass | ||
| class MockHFConfig: | ||
| model_type: str = "any" | ||
|
|
||
|
|
||
| @dataclass | ||
| class MockModelConfig: | ||
| runner_type = "generate" | ||
| model: str = MODEL_NAME | ||
| tokenizer: str = MODEL_NAME | ||
| trust_remote_code: bool = False | ||
| tokenizer_revision = None | ||
| tokenizer_mode = "auto" | ||
| hf_config = MockHFConfig() | ||
| encoder_config: dict[str, Any] | None = None | ||
| enable_prompt_embeds: bool = False | ||
| skip_tokenizer_init: bool = False | ||
| is_encoder_decoder: bool = False | ||
| is_multimodal_model: bool = False | ||
| renderer_num_workers: int = 1 | ||
| hidden_size: int = 768 | ||
| dtype: torch.dtype = torch.float32 | ||
|
|
||
| def get_hidden_size(self) -> int: | ||
| return self.hidden_size | ||
|
|
||
|
|
||
| @dataclass | ||
| class MockParallelConfig: | ||
| _api_process_rank: int = 0 | ||
|
|
||
|
|
||
| @dataclass | ||
| class MockVllmConfig: | ||
| model_config: MockModelConfig | ||
| parallel_config: MockParallelConfig | ||
|
|
||
|
|
||
| @dataclass | ||
| class DummyTokenizer: | ||
| truncation_side: str = "left" | ||
| max_chars_per_token: int = 1 | ||
| is_fast: bool = False | ||
|
|
||
| def decode(self, tokens: list[int], **kwargs): | ||
| return str(tokens) | ||
|
|
||
| def encode(self, text: str, **kwargs): | ||
| return list(range(len(text))) | ||
|
|
||
| def __call__(self, text: str, **kwargs): | ||
| return {"input_ids": self.encode(text, **kwargs)} | ||
|
|
||
|
|
||
| def _build_renderer() -> HfRenderer: | ||
| return HfRenderer( | ||
| MockVllmConfig(MockModelConfig(), parallel_config=MockParallelConfig()), | ||
| tokenizer=DummyTokenizer(), | ||
| ) | ||
|
|
||
|
|
||
| def test_swappable_executor_keeps_make_async_wrappers_alive(): | ||
| pool = _SwappableExecutor(max_workers=1) | ||
| async_add = make_async(lambda x: x + 1, executor=pool) | ||
|
|
||
| async def _run(): | ||
| assert await async_add(1) == 2 | ||
| old_inner = pool._inner | ||
| pool.replace_inner() | ||
|
|
||
| with pytest.raises(RuntimeError, match="cannot schedule new futures"): | ||
| old_inner.submit(lambda: None) | ||
|
|
||
| assert await async_add(40) == 41 | ||
|
|
||
| try: | ||
| asyncio.run(_run()) | ||
| finally: | ||
| pool.shutdown(wait=False) | ||
|
|
||
|
|
||
| def test_replace_executor_does_not_break_tokenize_or_decode(): | ||
| renderer = _build_renderer() | ||
| executor = renderer._executor | ||
| old_inner = executor._inner | ||
|
|
||
| async def _run(): | ||
| assert await renderer._tokenize_prompt_async( | ||
| {"prompt": "ab"}, | ||
| TokenizeParams(max_total_tokens=100), | ||
| ) | ||
| renderer._replace_executor() | ||
| assert renderer._executor is executor | ||
| assert executor._inner is not old_inner | ||
|
|
||
| with pytest.raises(RuntimeError, match="cannot schedule new futures"): | ||
| old_inner.submit(lambda: None) | ||
|
|
||
| tokenized = await renderer._tokenize_prompt_async( | ||
| {"prompt": "abc"}, | ||
| TokenizeParams(max_total_tokens=100), | ||
| ) | ||
| assert tokenized["prompt_token_ids"] == [0, 1, 2] | ||
| assert await renderer._async_tokenizer_decode([1, 2]) == "[1, 2]" | ||
|
|
||
| try: | ||
| asyncio.run(_run()) | ||
| finally: | ||
| renderer.shutdown() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL @BugenZhao