Skip to content

Make the scan SIMD helpers enforce their length contract - #1353

Merged
mgomes merged 1 commit into
masterfrom
able/vibe-103
Oct 31, 2026
Merged

mgomes merged 1 commit into
masterfrom
able/vibe-103

Conversation

@mgomes

@mgomes mgomes commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

The SIMD helpers in src/scan.rs were unsafe fns that read 16 or 64 bytes through raw pointers. They took slices, and the length they need was written down only in SAFETY comments, so a future caller could pass a short slice and read out of bounds.

Now vector_ascii_mismatch, vector_clean and vector_case take &[u8; 16] or &mut [u8; 16], and vector_ascii64 takes &[u8; 64]. The type enforces the length, and the helpers are safe functions with an internal unsafe block. vector_unicode already bounds its own loads, so it becomes safe too. Call sites convert their chunks_exact chunks with try_into().unwrap(), because as_chunks needs Rust 1.88 and the MSRV is 1.85.

No regression: on arm64 the release compare binaries disassemble to the same instructions as master, in both the SIMD and portable builds. The only difference is the file name. Timings against a master baseline (compare.py --baseline, 8 rounds, geomean of after/before medians):

Suite SIMD Portable
text (66 cases) 0.991 0.999
json (38 cases) 1.000 1.000

This is a type-level change with no behaviour change, so there's no new test. The existing lane and alignment tests in scan.rs cover the helpers. The x86_64 code gets compiled only in CI (ubuntu), because the build host has no x86_64 toolchain.

vector_ascii_mismatch, vector_clean, vector_ascii64 and vector_case
read a fixed number of bytes through raw pointers, but took slices and
left the length to an unstated caller contract. Taking arrays puts that
length in the type, so the helpers no longer need to be unsafe.
vector_unicode already bounds its own loads and becomes safe too.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T08:09:53.803035Z a195fcd Manual request
🔒 Security Review ✅ Completed 2026-10-31T08:07:12.383302Z a195fcd PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@mgomes

mgomes commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: a195fcd405

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@mgomes
mgomes merged commit 640c2fc into master Oct 31, 2026
12 checks passed
@mgomes
mgomes deleted the able/vibe-103 branch October 31, 2026 08:51
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