java-topology/defects/transformers/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.1 KiB
Raw Blame History

SCAN — HuggingFace Transformers — all 5 MOADs scanned 2026-03-31

Repository: https://github.com/huggingface/transformers Version: HEAD (depth=1 clone) Language: Python (primary), Rust (tokenizers backend)

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

transformers-0001 (pre-existing, UNDF-2026-000000914)

tokenization_python.py: convert_ids_to_tokens() calls self.all_special_ids property inside a loop — property rebuilds list every call. O(T×S) per decode. Patch: cache set(self.all_special_ids) before loop.

transformers-0003 (new)

Multiple tokenizers (marian, m2m100, speech_to_text, siglip, gpt_sw3): convert_tokens_to_string() calls if token in self.all_special_tokens inside loop. all_special_tokens is a list[str] property — O(S) per token. For m2m100 with 100+ language codes: S≈108, T=512 → 55K comparisons per decode call. Patch: cache set(self.all_special_tokens) before the loop in each tokenizer.

MOAD-0002 (Intertangle): CLEAN

Transformers has shared global registries (AUTO_MODEL_MAPPING, tokenizer registries) but these are read-only after init and legitimate plugin registries. No hot-path subsystem coupling through mutable shared state.

MOAD-0003 (Leaked Context): CLEAN

No threading.local or ContextVar holding per-request identity. Some models use globals for device tracking (e.g. attn_mask_npu_cache keyed by device) but these are device-scoped infrastructure, not request identity.

MOAD-0004 (Logged Secret): 1 DEFECT FOUND

transformers-0002 (new)

src/transformers/models/regnet/convert_regnet_seer_10b_to_pytorch.py line 236: logger.info(f"Token is {os.environ['HF_TOKEN']}") — logs HuggingFace auth token. Token grants write access to Hub model repos. CWE-312. Patch: replace with safe message omitting token value.

MOAD-0005 (Thundering Herd): CLEAN

Model loading is guarded by transformers file locking (filelock). No unprotected cache get+None+compute+set patterns found in hot paths. The ATTN_MASK_NPU_CACHE in npu_flash_attention.py is a device-keyed dict written once at first use per device — NPU inference is single-process; no concurrent races observed.