java-topology/defects/vllm/SCAN-2026-03-31.md
russell@unturf.com 81bef63b2e transformers+vllm: 3 new defects, all 5 MOADs scanned
transformers-0002: MOAD-0004 (CWE-312) regnet convert script logs HF_TOKEN verbatim
transformers-0003: MOAD-0001 (CWE-407) convert_tokens_to_string O(T×S) list scan
  - marian, m2m_100, speech_to_text, siglip, gpt_sw3 all affected
  - all_special_tokens is list[str]; fix: cache set() before loop; 5x speedup

vllm-0002: MOAD-0001 (CWE-407) Grok2Tokenizer O(N×V) dict.values() scan
  - decode() and convert_ids_to_tokens() use .values() view per token
  - sibling Mistral tokenizer already uses frozenset correctly
  - fix: add _special_token_ids frozenset at __init__; 10x speedup at N=2048, V=200

MOADs 0002/0003/0005 CLEAN for both repos
2026-03-31 20:17:09 -04:00

2.2 KiB

SCAN — vLLM — all 5 MOADs scanned 2026-03-31

Repository: https://github.com/vllm-project/vllm Version: HEAD (depth=1 clone) Language: Python, C++ (CUDA kernels)

MOAD-0001 (CWE-407): 2 DEFECTS FOUND

vllm-0001 (pre-existing, UNDF-2026-000000874)

vllm/lora/punica_wrapper/utils.py: lora_index_to_id.index(x) called per token in convert_mapping() — O(L) list.index() per token in a prompt-length loop. Patch: pre-build dict {lora_id: index} for O(1) lookup.

vllm-0002 (new)

vllm/tokenizers/grok2.py: decode() and convert_ids_to_tokens() use token_id not in self._special_tokens.values() — dict.values() is a view, membership scan is O(V) per token. V = number of special tokens in Grok-2. Called per output token during streaming LLM inference. The sibling Mistral tokenizer in the same codebase already uses _special_token_ids_set: frozenset[int] correctly. Patch: add self._special_token_ids = frozenset(self._special_tokens.values()) at init time and replace both .values() checks. Speedup: ~10x at N=2048, V=200.

MOAD-0002 (Intertangle): CLEAN

vLLM has well-separated subsystems. The engine, scheduler, model runner, and workers communicate through clean interfaces (SchedulerOutput, ExecuteModelReq). No hot-path coupling through mutable global god objects found.

MOAD-0003 (Leaked Context): CLEAN

_current_stream_tls = threading.local() in vllm/utils/torch_utils.py tracks the current CUDA stream per thread — this is CUDA device state (infrastructure), not per-request identity. No request-scoped identity leaked through ThreadLocal.

contextvars.ContextVar("_NoInitOrTensorImpl.is_active") in tensorizer.py is a task-scoped boolean flag for serialization, not per-request identity.

MOAD-0004 (Logged Secret): CLEAN

No environment variable secrets (API keys, tokens) logged verbatim in logger calls. vLLM's VLLM_API_KEY is read but not logged. MODELSCOPE_API_TOKEN is passed to client constructor, not printed.

MOAD-0005 (Thundering Herd): CLEAN

_CPU_MOE_LAYER_CACHE is written once per layer at model init (weakref.ref), read-only during inference. No concurrent cache miss+compute+set pattern. KV cache allocation uses the v1 scheduler which runs in a single async loop. Block pool allocation is single-threaded per scheduler step.