java-topology/whitepaper/outreach/transformers-0004.md
russell@unturf.com 652608142a feat: close outreach doc gap — 276 docs (batches 11-16)
All projects with patches now have outreach docs. 276 new docs covering
CWE-407, CWE-312, CWE-362 across C, C++, Java, Python, Go, Rust, C#,
PHP, Ruby, JavaScript, Dart, Erlang, R, and more.

Outreach gap: 276 -> 0.
2026-04-15 13:57:42 -04:00

3.1 KiB
Raw Blame History

Hugging Face Transformers — CWE-407 Disclosure Brief (transformers-0004)

2026-04-13 · Patch available — awaiting upstream merge

Finding

Three O(T×S) defects across wav2vec2, wav2vec2_phoneme, and ESM tokenizers. self.all_special_ids and self.all_special_tokens properties are accessed inside per-token loops, rebuilding lists on every iteration. One site also has a type mismatch defect causing special token filtering to silently fail. Patched.

The Defects

transformers-0004a (PATCHED — MEDIUM): src/transformers/models/wav2vec2/tokenization_wav2vec2.py

# convert_ids_to_tokens() line 286 — property rebuilt per token:
if skip_special_tokens and index in self.all_special_ids:  # O(S) list + rebuild

# _decode() line 430 — same pattern:
if skip_special_tokens and token in self.all_special_tokens:  # O(S) list + rebuild

transformers-0004b (PATCHED — MEDIUM + BUG): src/transformers/models/wav2vec2_phoneme/tokenization_wav2vec2_phoneme.py

# _decode() line 417 — type mismatch (str vs list[int]):
if skip_special_tokens and token in self.all_special_ids:  # always False!

This check compares a str token against list[int] (all_special_ids), so membership test always returns False. Special tokens leak into output regardless of skip_special_tokens=True.

transformers-0004c (PATCHED — MEDIUM): src/transformers/models/esm/tokenization_esm.py

# get_special_tokens_mask() line 128 — property rebuilt per element:
return [1 if token in self.all_special_ids else 0 for token in token_ids_0]

Python evaluates self.all_special_ids once per comprehension element. ESM-2 with S=5 special tokens and T=1024 residues produces 5,120 property rebuilds per call.

Complexity Proof

transformers-0004a: At T=512, S=7-15 (wav2vec2):

  • ~7,680 wasted property rebuilds per decode call
  • ~8-12× speedup from eliminating rebuild overhead.

transformers-0004c: At T=1024, S=5 (ESM-2):

  • 5,120 property rebuilds per get_special_tokens_mask() call
  • ~5× speedup.

Impact

wav2vec2 powers speech recognition (ASR) workloads. ESM powers protein sequence analysis. Both fire on every inference request. The wav2vec2_phoneme type mismatch additionally means special tokens are never filtered from phoneme output, producing incorrect results.

The Fix

Cache all_special_ids/all_special_tokens as a set before each loop. Fix the wav2vec2_phoneme type mismatch by comparing against string tokens instead of integer IDs.

Patch

Fix available: defects/transformers-0004/patch/transformers-0004-wav2vec2-esm-all-special-ids-loop-scan.patch

Multi-file patch across three tokenizer implementations. 9/9 tests pass.

What We Ask

A patch is ready for review.

  1. Confirm receipt and assign a GitHub issue reference (huggingface/transformers).
  2. Assess severity — fires on every ASR decode and protein sequence analysis.
  3. Coordinate a disclosure date — we are targeting 90 days from first contact.
  4. We will credit the Hugging Face team in the public disclosure. Preferred acknowledgment format welcome.

Contact: see cover email. This brief is confidential until coordinated disclosure.