Skip to content

fix(hstr): avoid references to uninitialized bytes - #12087

Open
labor0-bot[bot] wants to merge 1 commit into
mainfrom
fix/hstr-uninitialized-memory
Open

fix(hstr): avoid references to uninitialized bytes#12087
labor0-bot[bot] wants to merge 1 commit into
mainfrom
fix/hstr-uninitialized-memory

Conversation

@labor0-bot

@labor0-bot labor0-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Description:

Fixes two soundness issues in hstr where mutable byte references were formed over uninitialized storage.

  • Use an initialized 64-byte stack buffer in Atom::from_mutated_str, retaining the stack fast path and heap fallback for longer strings.
  • Encode WTF-8 code points through Vec::spare_capacity_mut() and MaybeUninit::write, updating the vector length only after the exact encoded byte count is initialized.
  • Document the safety invariants for retained unsafe operations.
  • Add focused regression coverage for short, 64-byte, and over-64-byte ASCII case conversion and one- through four-byte code-point appends, including an unpaired surrogate.

Validation:

  • cargo test -p hstr
  • Focused Miri runs for both new regression tests
  • cargo fmt --all
  • cargo clippy --all --all-targets -- -D warnings

Related issue (if exists):

Closes #12083

@labor0-bot
labor0-bot Bot requested a review from a team as a code owner July 30, 2026 04:39
@changeset-bot

changeset-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 21ffde8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codspeed-hq

codspeed-hq Bot commented Jul 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 200 untouched benchmarks
⏩ 61 skipped benchmarks1


Comparing fix/hstr-uninitialized-memory (21ffde8) with main (83ab4ed)

Open in CodSpeed

Footnotes

  1. 61 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Comment thread .github/workflows/CI.yml
@labor0-bot
labor0-bot Bot force-pushed the fix/hstr-uninitialized-memory branch from 97be205 to 21ffde8 Compare July 30, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Soundness: Forming a mutable reference to uninitialized stack memory in Atom::from_mutated_str and push_code_point

2 participants