Validate base64 tokens when loading BPE files - #592
Open
weivwang wants to merge 1 commit into
Open
Conversation
weivwang
marked this pull request as ready for review
August 13, 2026 12:30
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Reject malformed Base64 token fields when loading
.tiktokenBPE files instead of silently discarding invalid characters.Python's permissive
base64.b64decodeturns input such as!!!intob"", so a corrupted vocabulary line could create an empty-byte token and continue loading. Enabling the standard library's strict validation keeps the existing per-line error context while preventing silent vocabulary corruption.Testing
.venv/bin/python -m pytest tests/test_load.py -q(2 passed).venv/bin/python -m pytest tests -q --deselect tests/test_encoding.py::test_simple --deselect tests/test_encoding.py::test_basic_encode(31 passed, 4 deselected by existing test selection).venv/bin/python -m compileall -q tiktoken tests/test_load.pygit diff --checkThe two deselected tests fetch tokenizer assets from
openaipublic.blob.core.windows.net; they failed before assertions because the local proxy terminated TLS withUNEXPECTED_EOF_WHILE_READING. The new loader tests use local files and cover both valid and invalid Base64 deterministically.