Skip to content

Fix C tokenizer handling of embedded NUL - #367

Open
sean0407 wants to merge 1 commit into
earwig:mainfrom
sean0407:codex/mwparserfromhell-355-nul-tokenizer
Open

sean0407 wants to merge 1 commit into
earwig:mainfrom
sean0407:codex/mwparserfromhell-355-nul-tokenizer

Conversation

@sean0407

Copy link
Copy Markdown

Summary

Preserve embedded NUL characters in the C tokenizer by using an out-of-range codepoint for tokenizer boundaries and treating NUL as ordinary input text.

Evidence

  • Reproduced the issue on current main: the C tokenizer returned 'a' for a\x00b, while the pure-Python tokenizer returned the full input.
  • Root cause: Tokenizer_read() returned \\0 for end of input and the C marker table also classified \\0 as an end marker, so a real NUL stopped parsing.
  • The boundary sentinel now cannot collide with valid Unicode input. Added tokenizer fixtures for embedded NUL in plain text, a longer string, and a template.
  • Checks run: isolated C-extension build passed; pytest -q tests --ignore=tests/test_docs.py passed (2,011 tests); the C and Python tokenizer outputs match for all three reproductions.

Merge Danger

Door: two-way

Blast Radius: localized

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant