Skip to content

Encoding: Fix _wp_scan_utf8() budget scanning#49

Open
sirreal wants to merge 3 commits into
trunkfrom
fix/utf8-scan-codepoint-budget
Open

Encoding: Fix _wp_scan_utf8() budget scanning#49
sirreal wants to merge 3 commits into
trunkfrom
fix/utf8-scan-codepoint-budget

Conversation

@sirreal

@sirreal sirreal commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • Cap _wp_scan_utf8() ASCII fast-path scanning by the remaining code point budget.
  • Avoid scanning an entire ASCII run when callers request only a small number of code points.
  • Preserve returned spans and found code point counts for existing UTF-8 callers.

Testing

  • PHPUnit coverage for zero budgets, long ASCII runs, offsets, multibyte boundaries, and invalid spans.
  • Differential UTF-8 span validation and PHPCS pass.
  • codex review --base trunk.

Trac ticket: https://core.trac.wordpress.org/ticket/65372

Use of AI Tools

AI assistance: Yes
Tool(s): Claude, Codex
Model(s): Fable 5, GPT-5.5
Used for: Fuzz test design, diagnosis, PR description cleanup, and code review.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

sirreal added 2 commits June 11, 2026 12:34
When _wp_scan_utf8() is called with max_code_points but no max_bytes, the ASCII fast path previously called strspn() across the entire remaining ASCII run before checking the code point limit. This made _wp_utf8_codepoint_span( large ASCII text, 0, 5 ) scan the full string.

Bound strspn() by the remaining code point budget. ASCII code points are one byte, so this preserves the returned span and found count while avoiding work past the budget.

Local benchmark, 10 MB ASCII _wp_utf8_codepoint_span( ..., 0, 5 ): original 3.183709 ms, patched 0.001250 ms. Differential fuzz: 189847 span/found cases and 2750 valid mb_substr sanity cases, no mismatches.
@sirreal sirreal marked this pull request as ready for review June 11, 2026 11:26
@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell, sergeybiryukov.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

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