Fix undefined behavior in UTF-16 parsing from unaligned buffers - #62
Open
natecook1000 wants to merge 2 commits into
Open
Fix undefined behavior in UTF-16 parsing from unaligned buffers#62natecook1000 wants to merge 2 commits into
natecook1000 wants to merge 2 commits into
Conversation
URBP.assumingMemoryBound(to:) requires that the buffer is UInt16- aligned, which doesn't necessarily hold when reading a binary file. This change adds an `_UnalignedUnsafeBufferPointer` and uses it when the memory to be parsed as a UTF16 string is out of alignment with `UInt16`.
natecook1000
force-pushed
the
fix/utf16-unaligned-load
branch
from
August 18, 2026 18:39
4663706 to
5a00bb2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
URBP.assumingMemoryBound(to:)requires that the buffer isUInt16- aligned, which doesn't necessarily hold when reading a binary file. This change adds an_UnalignedUnsafeBufferPointerand uses it when the memory to be parsed as a UTF16 string is out of alignment withUInt16.This will go through a slow path in UTF16 -> UTF8 string initialization (since the new unaligned buffer isn't one of the always-specialized types) so we should benchmark this change.
Checklist
Scripts/format.shto correctly format my change