SentencePiece Normalizer Trie Out-of-Bounds Read β PoC
Summary
sentencepiece 0.2.1 (current PyPI release) loads .spm model files without validating the embedded darts-clone trie in precompiled_charsmap. Normalizer::Init() calls set_array() without subsequently calling validate(). As a result, commonPrefixSearch() accesses array_[node_pos] beyond the allocated bounds during tokenization β silently, without crash or exception.
Target
| Field | Value |
|---|---|
| Package | sentencepiece |
| Confirmed affected | 0.2.1 (current PyPI release) |
| Potentially affected | <= 0.2.1 |
| Fixed versions | None released |
| Fix | PR #1216 (main branch, unreleased) |
| Fix commit | 57a257f02ebb07ad489eb889d4ef4694b65ba9d6 |
Vulnerability
Root cause: Normalizer::Init() in src/normalizer.cc (~line 62):
// sentencepiece 0.2.1 β missing validate():
trie_->set_array(const_cast<char *>(trie_blob.data()),
trie_blob.size() / trie_->unit_size());
// β trie_->validate() is NOT called
third_party/darts_clone/darts.h then accesses array_[node_pos] in commonPrefixSearch() and traverse() with no bounds check. A crafted .spm file with an OOB root unit offset causes every tokenization call to read heap memory beyond the trie buffer.
Distinction from GHSA-38vq-g6vr-w8wf
GHSA-38vq-g6vr-w8wf (CVE-2026-1260) patched a builder-path root (PrefixMatcher) in v0.2.1. This report concerns a distinct loader-path root (Normalizer::Init), which is present in v0.2.1 and not fixed in any released version. See GHSA_38VQ_DISTINCTION.md for full comparison.
PoC Behavior
sp.Load('malformed_normalizer.spm')β succeeds (no exception)sp.EncodeAsPieces('hello world')β returns output without crash- OOB read is silent: root unit[0] offset=45800, trie size_=44800, OOB by 1000 units
No code execution is claimed. No ASAN instrumentation was used. See expected_output.txt for full observed behavior.
Reproduction
pip install sentencepiece==0.2.1
# Option A: use pre-crafted model
python3 demonstrate_oob.py malformed_normalizer.spm
# Option B: craft model from scratch
python3 craft_malformed_spm.py output.spm
python3 demonstrate_oob.py output.spm
Files
| File | Description |
|---|---|
malformed_normalizer.spm |
Pre-crafted malformed model (root unit[0] offset=45800, OOB) |
craft_malformed_spm.py |
Script to craft a malformed model from a trained base |
demonstrate_oob.py |
Script demonstrating silent load + tokenization |
requirements.txt |
sentencepiece==0.2.1 |
expected_output.txt |
Expected script output and OOB parameters |
PR_1216_PATCH_EVIDENCE.md |
PR #1216 details: diff, merge commit, release status |
GHSA_38VQ_DISTINCTION.md |
Root-by-root comparison with GHSA-38vq-g6vr-w8wf |
SHA256SUMS.txt |
File integrity checksums |
References
- Fix PR: https://github.com/google/sentencepiece/pull/1216
- Related advisory (distinct root): GHSA-38vq-g6vr-w8wf / CVE-2026-1260
- Package: https://pypi.org/project/sentencepiece/