Skip to content

fix: String may be written twice in one codepath#65

Merged
Licenser merged 1 commit into
simd-lite:mainfrom
EmilyMatt:fix-duplicate-write
Jul 9, 2026
Merged

fix: String may be written twice in one codepath#65
Licenser merged 1 commit into
simd-lite:mainfrom
EmilyMatt:fix-duplicate-write

Conversation

@EmilyMatt

@EmilyMatt EmilyMatt commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

This was discovered by running miri on simd-json.
Test serde::se::pp::test::prettyfy

After lengthy debugging, following codepath is required:

  1. runtime-detection is enabled
  2. x86 architecture
  3. No avx2 available on system
  4. No sse2 available on system
  5. portable is disabled

In that code path we end up calling write_string_rust twice.
But the first one does not advance the string, so we end up writing the same string twice.
The solutions is to move the *string = &string[string.len()..]; line into write_string_rust() itself

Closes #62

@Licenser Licenser force-pushed the fix-duplicate-write branch from a3a8e92 to 3e6f735 Compare July 9, 2026 11:17

@Licenser Licenser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wonderful catch, thank you!

@Licenser Licenser merged commit 2ee87bb into simd-lite:main Jul 9, 2026
1 check was pending
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.

write_str_simd_fastest can accidentally write strings twice. under miri

2 participants